Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
        /// <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);
            }
        }
Exemplo n.º 3
0
        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;
        }
Exemplo n.º 4
0
        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);
        }