Esempio n. 1
0
        public void ValidateRegisterWorker_9()
        {
            IWorkerService service = new WorkerService(new UnitOfWork());

            WorkerDTO workerToAdd = new WorkerDTO();

            workerToAdd.Email            = "*****@*****.**";
            workerToAdd.Password         = "******";
            workerToAdd.RepeatedPassword = "******";
            workerToAdd.IsWalker         = false;
            workerToAdd.Disponibility    = new List <DayOfWeek>()
            {
                0
            };
            workerToAdd.Latitude  = "validLength";
            workerToAdd.Longitude = "validLength";

            int newId = service.RegisterNewWorker(workerToAdd);

            WorkerBundle workerToUpdate = new WorkerBundle();

            workerToUpdate.Password    = "******";
            workerToUpdate.PhoneNumber = "222333444";

            try
            {
                service.UpdateWorkerInfo(newId, workerToUpdate);
            }
            catch (Exception ex)
            {
                Assert.Fail();
            }
            service.DeleteWorker(newId);
        }
Esempio n. 2
0
        private void updateNewInfo(Worker workerToUpdate, WorkerBundle newWorkerInfo)
        {
            if (newWorkerInfo.Name != null)
            {
                workerToUpdate.Name        = newWorkerInfo.Name;
                workerToUpdate.Surname     = newWorkerInfo.Surname;
                workerToUpdate.Password    = newWorkerInfo.Password;
                workerToUpdate.PhoneNumber = newWorkerInfo.PhoneNumber;
            }

            if (newWorkerInfo.ShortDescription != null)
            {
                workerToUpdate.ShortDescription = newWorkerInfo.ShortDescription;
                workerToUpdate.Information      = newWorkerInfo.Information;
                workerToUpdate.BoardingPrice    = newWorkerInfo.BoardingPrice;
                workerToUpdate.ZIPCode          = localizationMgr.GetZipCodeFromAddress(newWorkerInfo.Address);
            }
            if (newWorkerInfo.Disponibility != null)
            {
                workerToUpdate.Disponibility = convertDisponibilityIntToString(newWorkerInfo.Disponibility, workerToUpdate.WorkerId);
            }
            if (newWorkerInfo.WalkingPrice != null && newWorkerInfo.WalkingPrice != 0)
            {
                workerToUpdate.WalkingPrice = newWorkerInfo.WalkingPrice;
            }

            if (newWorkerInfo.ProfileImage != null)
            {
                workerToUpdate.ProfileImage = ImageSaver.GetIntance().getUrlOfImage(newWorkerInfo.ProfileImage, workerToUpdate.WorkerId.ToString(), "w");
            }
        }
Esempio n. 3
0
 private void validateWorkerDataToUpdate(WorkerBundle newWorkerInfo)
 {
     if (newWorkerInfo.Name != null)
     {
         validator.validateStringData(null, newWorkerInfo);
         validator.validatePhoneNumber(null, newWorkerInfo);
     }
 }
Esempio n. 4
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.");
            }
        }
Esempio n. 5
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.");
            }
        }
Esempio n. 6
0
        public void UpdateWorkerInfo(int workerId, WorkerBundle workerInfo)
        {
            Worker workerToUpdate = unitOfWork.WorkerRepository.GetByID(workerId);

            validator.validateUserExists(null, workerToUpdate);
            validateWorkerDataToUpdate(workerInfo);

            updateNewInfo(workerToUpdate, workerInfo);

            unitOfWork.WorkerRepository.Update(workerToUpdate);
            unitOfWork.Save();
        }
Esempio n. 7
0
        public void ValidateUpdateClient_1()
        {
            IWorkerService service = new WorkerService(new UnitOfWork());

            WorkerDTO workerToAdd = new WorkerDTO();

            workerToAdd.Email            = "*****@*****.**";
            workerToAdd.Password         = "******";
            workerToAdd.RepeatedPassword = "******";
            workerToAdd.IsWalker         = false;
            workerToAdd.Disponibility    = new List <DayOfWeek>()
            {
                0
            };
            workerToAdd.Latitude  = "validLength";
            workerToAdd.Longitude = "validLength";


            int newId = service.RegisterNewWorker(workerToAdd);


            WorkerBundle dataToUpdate = new WorkerBundle();

            dataToUpdate.Name             = "valid";
            dataToUpdate.Surname          = "valid";
            dataToUpdate.PhoneNumber      = "095456908";
            dataToUpdate.Password         = "******";
            dataToUpdate.Address          = "address";
            dataToUpdate.BoardingPrice    = 100;
            dataToUpdate.Information      = "information";
            dataToUpdate.ShortDescription = "description";

            try
            {
                service.UpdateWorkerInfo(newId, dataToUpdate);
            }
            catch (Exception)
            {
                Assert.Fail();
            }
            service.DeleteWorker(newId);
        }
Esempio n. 8
0
 public IHttpActionResult PutWorker(int workerId, WorkerBundle newWorkerInfo)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(BadRequest(ModelState));
         }
         WorkerService.UpdateWorkerInfo(workerId, newWorkerInfo);
         JsonMessager message = new JsonMessager("Trabajador 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)));
     }
 }