1 changed files with 84 additions and 0 deletions
@ -0,0 +1,84 @@ |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Shentun.Peis.Models; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories; |
|||
using Volo.Abp; |
|||
|
|||
namespace Shentun.Peis.UserItemTypes |
|||
{ |
|||
/// <summary>
|
|||
/// 用户对应项目类别
|
|||
/// </summary>
|
|||
[ApiExplorerSettings(GroupName = "Work")] |
|||
[Authorize] |
|||
public class UserItemTypeAppService |
|||
{ |
|||
private readonly IRepository<UserItemType> _userItemTypeRepository; |
|||
|
|||
public UserItemTypeAppService( |
|||
IRepository<UserItemType> userItemTypeRepository |
|||
) |
|||
{ |
|||
_userItemTypeRepository = userItemTypeRepository; |
|||
} |
|||
/// <summary>
|
|||
/// 设置用户对应的项目类别 先删除,后创建
|
|||
/// </summary>
|
|||
/// <param name="UserId">用户ID</param>
|
|||
/// <param name="ItemTypeIds">对应的项目类别ID集合</param>
|
|||
/// <returns></returns>
|
|||
/// <exception cref="UserFriendlyException"></exception>
|
|||
[HttpPost("api/app/UserItemType/CreateMany")] |
|||
public async Task CreateManyAsync(Guid UserId, List<Guid> ItemTypeIds) |
|||
{ |
|||
|
|||
if (UserId == Guid.Empty) |
|||
{ |
|||
throw new UserFriendlyException($"用户ID不能为空"); |
|||
} |
|||
|
|||
await _userItemTypeRepository.DeleteAsync(d => d.UserId == UserId, true); |
|||
|
|||
|
|||
if (ItemTypeIds.Any()) |
|||
{ |
|||
|
|||
List<UserItemType> entlist = new List<UserItemType>(); |
|||
foreach (var itemTypeId in ItemTypeIds) |
|||
{ |
|||
var ent = new UserItemType |
|||
{ |
|||
UserId = UserId, |
|||
ItemTypeId = itemTypeId |
|||
}; |
|||
entlist.Add(ent); |
|||
} |
|||
|
|||
await _userItemTypeRepository.InsertManyAsync(entlist); |
|||
} |
|||
} |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 获取当前用户对应的项目类别
|
|||
/// </summary>
|
|||
/// <param name="UserId">用户ID</param>
|
|||
/// <returns></returns>
|
|||
[HttpPost("api/app/UserItemType/GetUserItemType")] |
|||
public async Task<List<Guid>> GetUserItemTypeAsync(Guid UserId) |
|||
{ |
|||
List<Guid> guids = new List<Guid>(); |
|||
var entlist = await _userItemTypeRepository.GetListAsync(m => m.UserId == UserId); |
|||
if (entlist.Any()) |
|||
{ |
|||
guids = entlist.Select(s => s.ItemTypeId).ToList(); |
|||
} |
|||
return guids; |
|||
} |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue