public int RegisterNewBooking(BookingPaymentDTO bookingData) { PaymentDTO paymentDto = convertToPaymentDto(bookingData); BookingDTO bookingDto = convertToBookingDto(bookingData); validatePaymentData(paymentDto); Client c = unitOfWork.ClientRepository.GetByID(bookingData.ClientId); Worker w = unitOfWork.WorkerRepository.GetByID(bookingData.WorkerId); Pet p = unitOfWork.PetRepository.GetByID(bookingData.PetId); validateDataExists(c, w, p); validateBookingNotRepeated(bookingDto); validateWorkerBookingsNotOverlap(w, bookingData.StartDate, bookingData.FinishDate); validateWorkerBookingOnDisponibilities(w, bookingData.StartDate, bookingData.IsWalker); Booking newBooking = new Booking(bookingDto.ClientId, bookingDto.WorkerId, bookingDto.PetId, bookingDto.StartDate, bookingDto.FinishDate, bookingDto.IsWalker); newBooking.MadeDate = DateTime.Now; newBooking.InitialLocation = new Location(); unitOfWork.BookingsRepository.Insert(newBooking); unitOfWork.Save(); Payment newPayment = new Payment(newBooking.BookingId, paymentDto.CreditCardNumber, paymentDto.CCV, paymentDto.CreditCardExpirationMonth, paymentDto.CreditCardExpirationYear, paymentDto.Amount); unitOfWork.PaymentRepository.Insert(newPayment); unitOfWork.Save(); return(newBooking.BookingId); }
public IHttpActionResult PostBooking(BookingPaymentDTO bookingPaymentDto) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } int bookingId = BookingService.RegisterNewBooking(bookingPaymentDto); JsonMessager message = new JsonMessager(bookingId.ToString()); return(Ok(message)); } catch (UserNotFoundException ex) { return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message))); } catch (BookingAlreadyRegisteredException ex) { return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message))); } catch (DatesOverlapException ex) { return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message))); } catch (DisponibilitiesNotMatchException ex) { return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message))); } catch (InsufficientDataException ex) { return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message))); } }
private PaymentDTO convertToPaymentDto(BookingPaymentDTO bookingData) { PaymentDTO paymentDto = new PaymentDTO(); paymentDto.CreditCardNumber = bookingData.CreditCardNumber; paymentDto.CreditCardExpirationYear = bookingData.CreditCardExpirationYear; paymentDto.CreditCardExpirationMonth = bookingData.CreditCardExpirationMonth; paymentDto.CCV = bookingData.CCV; paymentDto.Amount = bookingData.Amount; return(paymentDto); }
private BookingDTO convertToBookingDto(BookingPaymentDTO bookingData) { BookingDTO bookingDto = new BookingDTO(); bookingDto.ClientId = bookingData.ClientId; bookingDto.FinishDate = bookingData.FinishDate; bookingDto.IsWalker = bookingData.IsWalker; bookingDto.PetId = bookingData.PetId; bookingDto.StartDate = bookingData.StartDate; bookingDto.WorkerId = bookingData.WorkerId; return(bookingDto); }
public void ValidateRegisterBooking_2() { IBookingService bookingService = new BookingService(new UnitOfWork()); BookingPaymentDTO bookingToAdd = new BookingPaymentDTO(); bookingToAdd.ClientId = 10; bookingToAdd.WorkerId = 10; bookingToAdd.StartDate = DateTime.Now; bookingToAdd.FinishDate = DateTime.Now; bookingToAdd.IsWalker = true; bookingToAdd.CreditCardNumber = "11122224445557"; bookingToAdd.CCV = 222; bookingToAdd.CreditCardExpirationMonth = 5; bookingToAdd.CreditCardExpirationYear = 2022; bookingToAdd.Amount = 200; int newBookingId = bookingService.RegisterNewBooking(bookingToAdd); bookingService.DeleteBooking(newBookingId); Assert.IsInstanceOfType(newBookingId, typeof(int)); }
public void ValidateRegisterBooking_1() { IClientService clientService = new ClientService(new UnitOfWork()); IWorkerService workerService = new WorkerService(new UnitOfWork()); IBookingService bookingService = new BookingService(new UnitOfWork()); ClientDTO clientToAdd = new ClientDTO(); clientToAdd.Email = "*****@*****.**"; clientToAdd.Password = "******"; clientToAdd.RepeatedPassword = "******"; int newClientId = clientService.RegisterNewClient(clientToAdd); PetBundle petData = new PetBundle(); petData.Name = "Rulito"; petData.Age = 10; petData.Gender = "Masculino"; petData.HasVaccination = true; petData.Weight = 50; petData.PetType = "Perro"; petData.Information = "Perro bueno"; petData.FriendlyPet = true; clientService.AddClientPet(newClientId, petData); WorkerDTO workerToAdd = new WorkerDTO(); workerToAdd.Email = "*****@*****.**"; workerToAdd.Password = "******"; workerToAdd.RepeatedPassword = "******"; workerToAdd.IsWalker = true; workerToAdd.Disponibility = new List <DayOfWeek>() { 0 }; workerToAdd.Latitude = "validLength"; workerToAdd.Longitude = "validLength"; int newWorkerId = workerService.RegisterNewWorker(workerToAdd); BookingPaymentDTO bookingToAdd = new BookingPaymentDTO(); bookingToAdd.ClientId = newClientId; bookingToAdd.WorkerId = newWorkerId; bookingToAdd.StartDate = DateTime.Now; bookingToAdd.FinishDate = DateTime.Now; bookingToAdd.IsWalker = true; bookingToAdd.CreditCardNumber = "1112222444555557"; bookingToAdd.CCV = 222; bookingToAdd.CreditCardExpirationMonth = 5; bookingToAdd.CreditCardExpirationYear = 2022; bookingToAdd.Amount = 200; int newBookingId = bookingService.RegisterNewBooking(bookingToAdd); bookingService.DeleteBooking(newBookingId); clientService.DeleteClient(newClientId); workerService.DeleteWorker(newWorkerId); Assert.IsInstanceOfType(newBookingId, typeof(int)); }