public async Task <ClientCreateResult> Create(ClientCreateParameters parameters) { var validation = await _clientValidation.ValidateCreateDuplicate(parameters); if (validation != UserValidationStatus.Success) { return(null); } else { var result = await _dbContext.Clients.AddAsync(new Client() { Name = parameters.Name, MobileNumber = parameters.MobileNumber, AreaCode = parameters.AreaCode, Email = parameters.Email, Password = parameters.Password, Status = UserStatus.Inactive, }); await _dbContext.SaveChangesAsync(); var client = result.Entity; return(new ClientCreateResult() { Id = client.Id, Name = client.Name, MobileNumber = client.MobileNumber, AreaCode = client.AreaCode, Email = client.Email, }); } }
public async Task <ClientUpdateResult> Update(int id, ClientCreateParameters parameters) { var validation = await _clientValidation.ValidateUpdateDuplicate(id, parameters); if (validation != UserValidationStatus.Success) { return(null); } var client = await _dbContext.Clients .FirstOrDefaultAsync(c => c.Id == id); if (client == null) { return(null); } client.Name = parameters.Name; client.MobileNumber = parameters.MobileNumber; client.AreaCode = parameters.AreaCode; client.Email = parameters.Email; client.Password = parameters.Password; await _dbContext.SaveChangesAsync(); return(new ClientUpdateResult() { Id = client.Id, Name = client.Name, MobileNumber = client.MobileNumber, AreaCode = client.AreaCode, Email = client.Email }); }
public async Task <IActionResult> Put(string authorization, int id, ClientCreateParameters parameters) { var client = await _clientService.Update(id, parameters); if (client == null) { return(Ok(new ClientCreateResult())); } return(Ok(client)); }
public async Task <IActionResult> Post(ClientCreateParameters parameters) { var client = await _clientService.Create(parameters); if (client == null) { return(Ok(new ClientCreateResult())); } return(Ok(client)); }
public async Task <IActionResult> Profile(ClientUpdateViewParameters parameters) { var user = (TokenUser)HttpContext.Items["User"]; var clientCreateParameters = new ClientCreateParameters { Name = parameters.FirstName + " " + parameters.LastName, MobileNumber = parameters.MobileNumber, AreaCode = parameters.AreaCode, Email = parameters.Email, Password = _protectionService.ComputeHash(parameters.Password) }; await _clientProxy.Update(user.Token, user.Id, clientCreateParameters); return(RedirectToAction("Profile")); }
public async Task <UserValidationStatus> ValidateUpdateDuplicate(int id, ClientCreateParameters parameters) { var findClientEmail = await _dbContext.Clients.AnyAsync(c => (c.Id != id) && c.Email.Contains(parameters.Email)); var findClientMobile = await _dbContext.Clients.AnyAsync(c => (c.Id != id) && c.MobileNumber.Equals(parameters.MobileNumber)); if (findClientEmail) { return(UserValidationStatus.EmailAlreadyExists); } else if (findClientMobile) { return(UserValidationStatus.MobileAlreadyExists); } else { return(UserValidationStatus.Success); } }
public async Task <IActionResult> Register(ClientUpdateViewParameters parameters) { var clientCreateParameters = new ClientCreateParameters { Name = parameters.FirstName + " " + parameters.LastName, MobileNumber = parameters.MobileNumber, AreaCode = parameters.AreaCode, Email = parameters.Email, Password = _protectionService.ComputeHash(parameters.Password) }; var client = await _clientProxy.Create(clientCreateParameters); if (client != null) { return(RedirectToAction("Otp", new { userId = client.Id, mobileNumber = client.AreaCode + client.MobileNumber, email = client.Email })); } return(View()); }