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))); } }
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); }
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"); } }
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); }
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); }