1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using Datory;
- using GxPress.Auth;
- using GxPress.Repository.Interface;
- using GxPress.Repository.Interface.Friends;
- using GxPress.Request.AddressBookGroupUser;
- using GxPress.Result.AddressBookGroupUser;
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Logging;
- namespace GxPress.Api.AppControllers
- {
- /// <summary>
- /// 通讯录用户信息
- /// </summary>
- [Route("api/app/address-book-group-user")]
- [ApiController]
- [Authorize]
- public class AddressBookGroupUserController : ControllerBase
- {
- private readonly ILogger<AppVersionController> _logger;
- private readonly IAddressBookGroupUserRepository _addressBookGroupUserRepository;
- private readonly ILoginContext _loginContext;
- private readonly IFriendsRepository friendsRepository;
- public AddressBookGroupUserController(ILogger<AppVersionController> logger, IAddressBookGroupUserRepository addressBookGroupUserRepository, ILoginContext loginContext, IFriendsRepository friendsRepository)
- {
- _logger = logger;
- _addressBookGroupUserRepository = addressBookGroupUserRepository;
- _loginContext = loginContext;
- this.friendsRepository = friendsRepository;
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpDelete("{id}")]
- public async Task<bool> Delete(int id)
- {
- return await _addressBookGroupUserRepository.DeleteAsync(id);
- }
- /// <summary>
- /// 删除自建分组用户
- /// </summary>
- /// <returns></returns>
- [HttpPost("delete")]
- public async Task<bool> Deletes(AddressBookGroupUserDeleteRequest request)
- {
- var model = await _addressBookGroupUserRepository.GetAllAsync(Q.WhereIn(nameof(Entity.AddressBookGroupUser.Id), request.Ids));
- if (await _addressBookGroupUserRepository.DeletesAsync(request.Ids))
- {
- return await friendsRepository.DeleteAsync(model.Select(n => n.UserId), _loginContext.AccountId);
- }
- return false;
- }
- /// <summary>
- /// 获取
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [HttpPost("list")]
- public async Task<AddressBookGroupUserListResult> GetAddressBookGroupUserList(
- AddressBookGroupUserSearchRequest request)
- {
- var userId = _loginContext.AccountId;
- return await _addressBookGroupUserRepository.GetAddressBookGroupUserListAsync(request, userId);
- }
- /// <summary>
- /// 添加
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [HttpPost("add")]
- public async Task<bool> Insert(AddressBookGroupUserInRequest request)
- {
- if (await _addressBookGroupUserRepository.InsertAsync(request))
- {
- return await friendsRepository.UpdateAddressBookGroupId(request.UserId, _loginContext.AccountId, request.AddressBookGroupId);
- }
- return false;
- }
- /// <summary>
- /// 移动分组成员
- /// </summary>
- /// /// <param name="request"></param>
- /// <returns></returns>
- [HttpPost("move")]
- public async Task<bool> AddressBookGroupUserMove(AddressBookGroupUserMoveRequest request)
- {
- return await _addressBookGroupUserRepository.AddressBookGroupUserMoveAsync(request);
- }
- }
- }
|