public bool Add(ClientServiceDTO clientDto) { if(clientDto == null) throw new ArgumentNullException("clientDto"); User dbUser = _db.Query<User>().GetByName(clientDto.Name); if (dbUser != null) return false; _db.Insert(clientDto.CopyToDomainObject()); return true; }
/// <summary> /// Actualiza o domain object com os valores do DTO client /// </summary> /// <param name="domainClient"></param> /// <param name="dto"></param> public static void UpdateDomainObjectFromDTO(this Client domainClient, ClientServiceDTO dto) { domainClient.Email = dto.Email; domainClient.Enabled = dto.Enabled; domainClient.Name = dto.Name; domainClient.Phone = dto.Phone; if (dto.Password != PasswordUtils.Confuse()) { domainClient.Password = PasswordUtils.Encript(dto.Password); } }
public bool Update(ClientServiceDTO clientDto) { if (clientDto == null) throw new ArgumentNullException("clientDto"); Client dbClient = _db.Query<Client>().GetById(clientDto.UserID); User dbUser; if (dbClient.Name != clientDto.Name && ((dbUser = _db.Query<User>().GetByName(clientDto.Name)) != null) && dbUser.UserID != dbClient.UserID) return false; dbClient.UpdateDomainObjectFromDTO(clientDto); return true; }
public ActionResult Create(ClientServiceDTO clientDto) { // Verificar erros do modelo if (!ModelState.IsValid) return View("CreateUpdate", clientDto); // Verificar erros de negocio if (!_clientsService.Add(clientDto)){ ModelState.AddModelError("Name", "This name belongs to another user"); return View("CreateUpdate", clientDto); } // Sucesso ViewBag.Who = clientDto.Name; return View("CUD", ActionEnum.Created); }