public ValidationFailure ReferencesValidate(Reservation reservation, ValidationContext <Reservation> context) { var worker = _workerRepository.FindBy(reservation.WorkerId); if (worker.IsNull() || worker.Status.Equals(GlobalConstants.StatusDeactivated)) { return(new ValidationFailure("Reservation", "El trabajador esta desactivado o no existe")); } var saucer = _saucerRepository.FindBy(reservation.SaucerId); if (saucer.IsNull() || saucer.Status.Equals(GlobalConstants.StatusDeactivated)) { return(new ValidationFailure("Reservation", "El platillo esta desactivado o no existe")); } var dealer = _dealerRepository.FindBy(reservation.DealerId); if (dealer.IsNull() || dealer.Status.Equals(GlobalConstants.StatusDeactivated)) { return(new ValidationFailure("Reservation", "El distribuidor esta desactivado o no existe")); } var mealType = new MealType().ConvertToCollection().FirstOrDefault(mealTp => mealTp.Value == reservation.MealType); if (mealType.IsNull()) { return(new ValidationFailure("Reservation", "El tipo de comida no existe")); } return(null); }
public DTO.Reservation Execute(Reservation reservation) { var reservationDto = TypeAdapter.Adapt <DTO.Reservation>(reservation); var worker = _workerRepository.FindBy(reservation.WorkerId); reservationDto.Worker = TypeAdapter.Adapt <DTO.Worker>(worker); var saucer = _saucerRepository.FindBy(reservation.SaucerId); reservationDto.Saucer = TypeAdapter.Adapt <DTO.Saucer>(saucer); var dealer = _dealerRepository.FindBy(reservation.DealerId); reservationDto.Dealer = TypeAdapter.Adapt <DTO.Dealer>(dealer); return(reservationDto); }
public SuccessResponse Update(WorkerRequest request) { try { var currentWorker = _workerRepository.FindBy(request.Id); currentWorker.ThrowExceptionIfRecordIsNull(); var workerToCopy = TypeAdapter.Adapt <Worker>(request); TypeAdapter.Adapt(workerToCopy, currentWorker); _workerValidator.ValidateAndThrowException(currentWorker, "Base"); _workerRepository.Update(currentWorker); return(new SuccessResponse { IsSuccess = true }); } catch (DataAccessException) { throw new ApplicationException(); } }