Example #1
0
        public void ValidateUpdateClient_1()
        {
            IClientService service = new ClientService(new UnitOfWork());

            ClientDTO clientToAdd = new ClientDTO();

            clientToAdd.Email            = "*****@*****.**";
            clientToAdd.Password         = "******";
            clientToAdd.RepeatedPassword = "******";

            int newId = service.RegisterNewClient(clientToAdd);

            ClientBundle dataToUpdate = new ClientBundle();

            dataToUpdate.Name        = "valid";
            dataToUpdate.Surname     = "valid";
            dataToUpdate.PhoneNumber = "095456908";
            dataToUpdate.Password    = "******";

            try
            {
                service.UpdateClientInfo(newId, dataToUpdate);
            }
            catch (Exception)
            {
                Assert.Fail();
            }
            service.DeleteClient(newId);
        }
Example #2
0
 private void updateNewInfo(Client clientToUpdate, ClientBundle newClientInfo)
 {
     clientToUpdate.Name        = newClientInfo.Name;
     clientToUpdate.Surname     = newClientInfo.Surname;
     clientToUpdate.Password    = newClientInfo.Password;
     clientToUpdate.PhoneNumber = newClientInfo.PhoneNumber;
 }
Example #3
0
        public void validatePhoneNumber(ClientBundle client = null, WorkerBundle worker = null)
        {
            bool wrongLength = worker.PhoneNumber.Length < 9;
            bool wrongFormat = !(worker.PhoneNumber.All(Char.IsDigit));

            if (wrongLength || wrongFormat)
            {
                throw new WrongDataTypeException("El numero de telefono debe contener como minimo 9 digitos.");
            }
        }
Example #4
0
        public void validateStringData(ClientBundle client = null, WorkerBundle worker = null)
        {
            bool wrongNameLength     = worker.Name.Length < 4;
            bool wrongSurnameLength  = worker.Surname.Length < 4;
            bool wrongPasswordLength = worker.Password.Length < 8;

            if (wrongNameLength || wrongSurnameLength || wrongPasswordLength)
            {
                throw new WrongDataTypeException("Los campos de texto no cumplen con el largo minimo.");
            }
        }
Example #5
0
        public void UpdateClientInfo(int clientId, ClientBundle newClientInfo)
        {
            Client clientToUpdate = unitOfWork.ClientRepository.GetByID(clientId);

            validator.validateUserExists(clientToUpdate);
            validateClientDataToUpdate(newClientInfo);

            updateNewInfo(clientToUpdate, newClientInfo);

            unitOfWork.ClientRepository.Update(clientToUpdate);
            unitOfWork.Save();
        }
Example #6
0
 public IHttpActionResult PutClient(int clientId, ClientBundle newClientInfo)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(BadRequest(ModelState));
         }
         ClientService.UpdateClientInfo(clientId, newClientInfo);
         JsonMessager message = new JsonMessager("Cliente actualizado correctamente.");
         return(ResponseMessage(Request.CreateResponse(HttpStatusCode.OK, message)));
     }
     catch (UserNotFoundException ex)
     {
         return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)));
     }
     catch (WrongDataTypeException ex)
     {
         return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)));
     }
 }
Example #7
0
 private void validateClientDataToUpdate(ClientBundle newClientInfo)
 {
     validator.validateStringData(newClientInfo);
     validator.validatePhoneNumber(newClientInfo);
 }