Exemple #1
0
        public async Task UpdateClientAccountTest()
        {
            UpdateClientRequestModel  updateClientRequestModel = CreateUpdateClientRequestModel();
            UpdateClientResponseModel expected = CreateUpdateClientResponseModel();

            SetupAccountUpdateClientAccountMock(Token, updateClientRequestModel, expected);

            var actual = (JsonResult)await accountApiController.UpdateClientAccount(Token, updateClientRequestModel);

            Assert.AreEqual(expected, actual.Value);
        }
Exemple #2
0
        public async Task <IdentityResult> ChangePasswordAsync(UpdateClientRequestModel dto)
        {
            IdentityResult result = IdentityResult.Failed();
            var            user   = await userManager.FindByEmailAsync(dto.Email.Normalize());

            if (await userManager.CheckPasswordAsync(user, dto.OldPassword))
            {
                result = await userManager.ChangePasswordAsync(user, dto.OldPassword, dto.NewPassword);
            }

            return(result);
        }
Exemple #3
0
        public static UpdateClientCommand ToUpdateClientCommand(this UpdateClientRequestModel request, int id)
        {
            if (request is null)
            {
                return(null);
            }

            return(new UpdateClientCommand()
            {
                ClientId = id,
                Age = request.Age,
                Gender = request.Gender
            });
        }
Exemple #4
0
        public async Task <ActionResult> UpdateClientAsync(int id, UpdateClientRequestModel request, CancellationToken cancellationToken)
        {
            _logger.LogInformation("Call made to UpdateClientAsync.");

            if (!request.Age.HasValue && !request.Gender.HasValue)
            {
                return(BadRequest("Please enter at least one valid parameter."));
            }

            var command = request.ToUpdateClientCommand(id);
            await _mediator.Send(command, cancellationToken);

            return(Ok());
        }
Exemple #5
0
        public IActionResult UpdateClient(int id, [FromBody] UpdateClientRequestModel model)
        {
            var responseBusiness = _clientManager.UpdateClient(new ClientUpdateRequestModelDTO()
            {
                ClientId   = id,
                ClientName = model.ClientName
            });

            //TODO: hata dönüşümleri
            //if (id > dataArray.Count || id <= 0)
            //{
            //  return BadRequest("Böyle bir ID bulunamadı");
            //}

            //if (!ModelState.IsValid)
            //{
            //  return BadRequest(ModelState.Values);
            //}


            return(CreatedAtRoute("GetClient", new { id = responseBusiness.ClientId }, responseBusiness));
        }
Exemple #6
0
        public async Task <UpdateClientResponseModel> UpdateClientAccountAsync(string token, UpdateClientRequestModel dto)
        {
            var response = new UpdateClientResponseModel {
                IsSuccessful = false, Message = string.Empty
            };
            SessionData sessionData = await sessionRepository.GetByTokenAsync(token);

            if (sessionData == null)
            {
                response.Message = "Unauthorized";
                return(response);
            }
            UserData user = await applicationUserRepository.FindByIdAsync(sessionData.UserId);

            ClientData client = clientRepository.FindByUser(user);

            if (!await applicationUserRepository.CheckPasswordAsync(dto.Email, dto.OldPassword))
            {
                response.Message = "You should write your current password before update";
                return(response);
            }

            user.Email       = dto.Email;
            client.Name      = dto.Name;
            client.Surname   = dto.Surname;
            client.Telephone = dto.Telephone;
            client.Passport  = dto.Passport;

            if (dto.NewPassword != null && dto.NewPassword != string.Empty && dto.NewPassword != dto.OldPassword)
            {
                var passwordChangeResult = await applicationUserRepository.ChangePasswordAsync(dto);

                if (!passwordChangeResult.Succeeded)
                {
                    response.Message = "Error while changing passsword";
                    return(response);
                }
                response.Message = "Password changed successfully";
            }
            bool clientRes = await clientRepository.UpdateAsync(client);

            if (!clientRes)
            {
                response.Message = "Error while updating client information";
            }
            else
            {
                response.IsSuccessful = true;
            }
            return(response);
        }
Exemple #7
0
 public async Task <IActionResult> UpdateClientAccount(string token, [FromBody] UpdateClientRequestModel dto)
 => Json(await accountService.UpdateClientAccountAsync(token, dto));
Exemple #8
0
 private void SetupAccountUpdateClientAccountMock(string token, UpdateClientRequestModel updateClientRequestModel, UpdateClientResponseModel updateClientResponseModel)
 => accountServiceMock
 .Setup(service => service.UpdateClientAccountAsync(token, updateClientRequestModel))
 .ReturnsAsync(updateClientResponseModel);