public async Task <ActionResult <UserInfoResponse> > UpdateAccountInfo(
            Guid userId,
            [FromBody] UpdateAccountInfoRequest model)
        {
            var targetUser = await UserManager.FindByIdAsync(userId.ToString());

            if (targetUser == null)
            {
                return(NotFound("User not found"));
            }

            mapper.Map(model, targetUser);
            try
            {
                var updateResul = await UserManager.UpdateAsync(targetUser);

                if (!updateResul.Succeeded)
                {
                    logger.LogError($"Can't update user info {updateResul}");
                    return(StatusCode(500, "Unhandled error"));
                }
                return(mapper.Map <UserInfoResponse>(targetUser));
            }
            catch (DbUpdateException ex) when(
                ex.InnerException is PostgresException psex &&
                psex.SqlState == PostgresErrorCodes.UniqueViolation &&
                psex.ConstraintName.Contains(nameof(targetUser.StudentID)))
            {
                ModelState.AddModelError(nameof(targetUser.StudentID), $"StudentID {targetUser.StudentID} already exists");
                return(BadRequest(ModelState));
            }
        }
Beispiel #2
0
 public IResult UpdateAccount(Guid accountId, UpdateAccountInfoRequest request, Guid principal)
 {
     return(_accountRepository.UpdateInfo(accountId, request, principal).Success(() =>
     {
         _session.SaveChanges();
         return Result.Success();
     }));
 }
Beispiel #3
0
 public Result <Account> UpdateInfo(Guid id, UpdateAccountInfoRequest request, Guid principal)
 {
     return(ById(id).Success(v =>
     {
         _mapper.Map(_mapper.Map <UpdateAccountInfoRequest>(request), v);
         v.ModifiedOn = DateTime.UtcNow;
         v.ModifiedBy = principal;
         return Result.Success(v);
     }));
 }