Esempio n. 1
0
 public IHttpActionResult GetWorker(int workerId)
 {
     try
     {
         WorkerToReturn worker = WorkerService.GetWorker(workerId);
         return(Ok(worker));
     }
     catch (UserNotFoundException ex)
     {
         return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)));
     }
 }
Esempio n. 2
0
        public IEnumerable <WorkerToReturn> GetWorkers()
        {
            IEnumerable <Worker> query = unitOfWork.WorkerRepository.Get();

            List <WorkerToReturn> queryWorkers = new List <WorkerToReturn>();

            foreach (Worker worker in query)
            {
                List <string>  disponibilities = convertDisponibilityEnum(worker.Disponibility);
                WorkerToReturn workerRet       = convertWorkerToReturn(worker, disponibilities);
                queryWorkers.Add(workerRet);
            }
            return(queryWorkers);
        }
Esempio n. 3
0
        public WorkerToReturn GetWorker(int workerId)
        {
            if (ExistsWorker(workerId))
            {
                Worker        worker        = unitOfWork.WorkerRepository.GetByID(workerId);
                List <string> disponibility = convertDisponibilityEnum(worker.Disponibility);

                WorkerToReturn retWorker = convertWorkerToReturn(worker, disponibility);
                return(retWorker);
            }
            else
            {
                throw new UserNotFoundException("No existe el usuario");
            }
        }
Esempio n. 4
0
        public IEnumerable <WorkerToReturn> GetWorkersByFilter(bool both, string name, string address)
        {
            int zipCode = 0;

            if (address != null)
            {
                zipCode = localizationMgr.GetZipCodeFromAddress(address);
            }
            IEnumerable <Worker> query = unitOfWork.WorkerRepository.Get(w => (w.IsWalker == both) &&
                                                                         (name == null || w.Name == name) &&
                                                                         (address == null || w.ZIPCode == zipCode));

            List <WorkerToReturn> queryWorkers = new List <WorkerToReturn>();

            foreach (Worker worker in query)
            {
                List <string>  disponibilities = convertDisponibilityEnum(worker.Disponibility);
                WorkerToReturn workerRet       = convertWorkerToReturn(worker, disponibilities);
                queryWorkers.Add(workerRet);
            }
            return(queryWorkers);
        }
Esempio n. 5
0
        private WorkerToReturn convertWorkerToReturn(Worker worker, List <string> disponibility)
        {
            byte[] workerImg = ImageSaver.GetIntance().getImage(worker.ProfileImage);

            IEnumerable <WorkerImage> workerImages = unitOfWork.WorkerImagesRepository.Get(i => i.WorkerId == worker.WorkerId);

            byte[] bannerImage = null;
            if (workerImages.Count() > 0)
            {
                bannerImage = ImageSaver.GetIntance().getImage(workerImages.ElementAt(0).ImageUrl);
            }

            LocationBundle workerLocation = convertLocationToReturn(worker.Location);
            double         workerScore    = getWorkerAverageScore(worker.WorkerId);


            WorkerToReturn retWorker = new WorkerToReturn(worker.WorkerId, worker.Name, worker.Surname,
                                                          worker.Email, worker.Password, worker.PhoneNumber, worker.IsWalker, disponibility, workerImg,
                                                          worker.ShortDescription, worker.Information, worker.BoardingPrice, worker.WalkingPrice,
                                                          bannerImage, workerLocation, workerScore);

            return(retWorker);
        }