abp小试牛刀之应用服务开发
应用服务使用简单的CRUD,实现方式基于CrudAppService方式
1.DTO编写
NewsItemDto.cs
using System;
using Volo.Abp.Application.Dtos;
namespace MyAbp.Application.Contracts.News.Dto
{
public class NewsItemDto:EntityDto<Guid>
{
public string Title { get; set; }
public string Short { get; set; }
public string Full { get; set; }
public bool Published { get; set; } = false;
public DateTime? StartDateUtc { get; set; }
public DateTime? EndDateUtc { get; set; }
public bool AllowComments { get; set; } = false;
public int OrderBy { get; set; }
}
}
CreateNewsItemDto.cs
using System;
using System.ComponentModel.DataAnnotations;
namespace MyAbp.Application.Contracts.News.Dto
{
public class CreateNewsItemDto
{
[Required]
[StringLength(128)]
public string Title { get; set; }
[Required]
public string Short { get; set; }
[Required]
public string Full { get; set; }
public bool Published { get; set; } = false;
[Required]
public DateTime? StartDateUtc { get; set; }
[Required]
public DateTime? EndDateUtc { get; set; }
public bool AllowComments { get; set; } = false;
public int OrderBy { get; set; }
}
}
UpdateNewsItemDto.cs
using System;
using System.ComponentModel.DataAnnotations;
namespace MyAbp.Application.Contracts.News.Dto
{
public class UpdateNewsItemDto
{
[Required]
[StringLength(128)]
public string Title { get; set; }
[Required]
public string Short { get; set; }
[Required]
public string Full { get; set; }
public bool Published { get; set; } = false;
[Required]
public DateTime? StartDateUtc { get; set; }
[Required]
public DateTime? EndDateUtc { get; set; }
public bool AllowComments { get; set; } = false;
public int OrderBy { get; set; }
}
}
2.接口编写
using System;
using MyAbp.Application.Contracts.News.Dto;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
namespace MyAbp.Application.Contracts.News
{
public interface INewsItemAppService : ICrudAppService<NewsItemDto,
Guid,
PagedAndSortedResultRequestDto,
CreateNewsItemDto,
UpdateNewsItemDto>
{
}
}
3.服务代码编写
using System;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
using MyAbp.Domain.News;
using MyAbp.Application.Contracts.News.Dto;
using MyAbp.Application.Contracts.News;
namespace MyAbp.Application.News
{
public class NewsItemAppService : CrudAppService<NewsItem, NewsItemDto, Guid, PagedAndSortedResultRequestDto,
CreateNewsItemDto, UpdateNewsItemDto>,
INewsItemAppService
{
public NewsItemAppService(IRepository<NewsItem, Guid> repository)
: base(repository)
{
}
}
}

浙公网安备 33010602011771号