public Task <Result <LinkedUserModel> > Edit(UpdateLinkedUserModel model)
        => Result <LinkedUserModel> .TryAsync(async() =>
        {
            var result =
                await _repository.FirstOrDefaultAsync <LinkedUser>(u => u.Id == model.Id);
            if (!result.Success || result.Data == null)
            {
                return(Result <LinkedUserModel> .Failed(Error.WithCode(ErrorCodes.UserNotFound)));
            }

            var LinkedUser = result.Data;

            LinkedUser.LinkStatus   = (byte)model.Status;
            LinkedUser.RelationType = model.RelationType;

            var userIds = new List <Guid> {
                LinkedUser.FirstUserId, LinkedUser.SecondUserId
            };

            var users = (await _userBiz.ListByIds(userIds)).Data;
            await _repository.CommitAsync();
            var firstUser = users.FirstOrDefault(u => u.Id == LinkedUser.FirstUserId);

            var secondUser = users.FirstOrDefault(u => u.Id == LinkedUser.SecondUserId);

            return(Result <LinkedUserModel> .Successful(new LinkedUserModel
            {
                Id = LinkedUser.Id,
                FirstUser = new LightUserModel
                {
                    Firstname = firstUser.Firstname, Lastname = firstUser.Lastname, Gender = firstUser.Gender,
                    Role = firstUser.Role, Username = firstUser.Username
                },
                SecondUser = new LightUserModel
                {
                    Username = secondUser.Username, Firstname = secondUser.Firstname,
                    Lastname = secondUser.Lastname, Role = secondUser.Role
                },
                Status = (LinkStatus)LinkedUser.LinkStatus,
                RelationType = LinkedUser.RelationType
            }));
        });
Exemplo n.º 2
0
 public async Task <Result <IList <LightUserModel> > > ListByIds(object Ids)
 => await _userBiz.ListByIds(JsonConvert.DeserializeObject <List <Guid> >(Ids.ToString()));