public void CreateDurationTest() { CreateReservation create = new CreateReservation(); create.Guest = 12; Assert.IsTrue(create.Guest == 12); }
public void CreateNoteTest() { CreateReservation create = new CreateReservation(); create.Note = "Extra Plates needed"; Assert.IsTrue(create.Note == "Extra Plates needed"); }
[HttpGet] //id= selected sitting id public async Task <IActionResult> Create(int id) { //find sitting by id var sitting = await _db.Sittings.FirstOrDefaultAsync(s => s.Id == id); if (sitting == null) { //validation return(NotFound()); } var m = new CreateReservation { Sitting = sitting, Time = sitting.Start,//put the default time as a start time }; if (User.Identity.IsAuthenticated && User.IsInRole("Member")) {//get user if it is member var user = await _userManager.FindByNameAsync(User.Identity.Name); //get person from Created reservation m.Person = await _db.Members.FirstOrDefaultAsync(m => m.UserId == user.Id); } return(View(m)); //ViewData["PersonId"] = new SelectList(_db.People, "Id", "Discriminator"); //ViewData["SittingId"] = new SelectList(_db.Sittings, "Id", "Id"); //ViewData["SourceId"] = new SelectList(_db.ReservationSources, "Id", "Id"); //ViewData["StatusId"] = new SelectList(_db.ReservationStatuses, "Id", "Id"); //return View(); }
public IActionResult Create([FromBody] CreateReservation request) { using (logger.BeginScope("Create Reservation")) { logger.LogInformation("Initiating reservation creation for {seatId}", request?.SeatId); if (request?.SeatId == null || request?.SeatId == Guid.Empty) { logger.LogWarning(LogEvents.InvalidRequest, "Invalid {SeatId}", request?.SeatId); return(BadRequest("Invalid SeatId")); } var reservation = new Reservation { SeatId = request.SeatId }; if (!repository.Create(reservation)) { logger.LogWarning(LogEvents.ConflictState, "Seat with {SeatId} is already reserved", reservation.SeatId); return(Conflict("Seat is already reserved")); } logger.LogInformation("Successfully created reservation {ReservationId}", reservation.Id); return(Created("api/Reservations", reservation.Id)); } }
public void CreateNewReservation(CreateReservation cmd) { Decimal discountFactor, totalCost; if (cmd.DiscountCode == "FREE") { //it's free discountFactor = 0; } else if (cmd.DiscountCode == "HALF") { //half off discountFactor = 0.5m; } else { //too bad discountFactor = 1; } totalCost = cmd.NumberOfSeats * (_ticketCost * discountFactor); ApplyEvent(new ReservationCreated() { ReservationId = cmd.ReservationId, ReservationMade = DateTime.UtcNow, NumberOfSeats = cmd.NumberOfSeats, SeatsReservedFor = cmd.Name, TotalCost = totalCost }); }
public async void CreateReservation( EStatusCode expectedStatus, CreateReservation mutation ) { if (expectedStatus != EStatusCode.NotFound) { EntitiesFactory.NewAnnouncement(id: mutation.AnnouncementId).Save(); } if (expectedStatus == EStatusCode.Conflict) { EntitiesFactory.NewContact(phone: mutation.ContactPhone).Save(); } var result = await MutationsHandler.Handle(mutation); Assert.Equal(expectedStatus, result.Status); if (expectedStatus == EStatusCode.Success) { var reservationDb = await MutationsDbContext.Reservations .Where(r => r.Id == mutation.Id) .FirstOrDefaultAsync(); Assert.NotNull(reservationDb); Assert.Equal(mutation.AnnouncementId, reservationDb.AnnouncementId); Assert.Equal(mutation.ContactName, reservationDb.Contact.Name); Assert.Equal(mutation.ContactPhone, reservationDb.Contact.Phone); } }
public IActionResult Reservation(CreateReservation model) { Reservation res = new Reservation(); res.Email = model.Email; res.Name = model.Name; res.EventId = model.EventId; res.Event = db.Events.FirstOrDefault(f => f.Id == model.EventId); db.Reservations.Add(res); db.SaveChanges(); res = db.Reservations.FirstOrDefault(f => f.Email == model.Email && f.Name == model.Name); var seatsOnEvent = db.Seats.Where(s => s.EventId == model.EventId).ToList(); var dict = new Dictionary <int, List <int> >(); dict.Add(1, model.Level1 != null ? model.Level1.Split(",").Select(s => Convert.ToInt32(s)).ToList() : new List <int>()); dict.Add(2, model.Level2 != null ? model.Level2.Split(",").Select(s => Convert.ToInt32(s)).ToList() : new List <int>()); dict.Add(3, model.Level3 != null ? model.Level3.Split(",").Select(s => Convert.ToInt32(s)).ToList() : new List <int>()); seatsOnEvent.ForEach(e => { if (dict[e.Level].Contains(e.SeatNumber)) { e.Reservation = res; e.ReservationId = res.Id; e.Status = false; } }); db.Seats.UpdateRange(seatsOnEvent); db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <bool> CreateReservation(CreateReservation res) { var Reservation = new Reservation() { GuestsNumber = res.GuestsNumber, ReservationDate = res.ReservationDate, Notes = res.Notes }; await _ctx.Reservation.Add(Reservation); foreach (int m in res.MenuTypeId) { var menutype = await _ctx.MenuType.Get(m); var ResMenu = new ReservationMenuType() { MenuType = menutype, Reservation = Reservation }; await _ctx.ReservationMenuType.Add(ResMenu); } var result = await _ctx.Save(); if (result > 0) { return(false); } return(true); }
public async Task <IActionResult> Post([FromBody] CreateReservation command) { var context = new CorrelationContext(Guid.NewGuid(), command.UserId, "reservations", _tracer.ActiveSpan.Context.ToString()); await _busPublisher.SendAsync(command, context); return(Accepted($"reservations/{context.Id}")); }
public void AddNewReservationTest() { // TODO: add unit test for the method 'AddNewReservation' int?restaurantId = null; // TODO: replace null with proper value CreateReservation value = null; // TODO: replace null with proper value var response = instance.AddNewReservation(restaurantId, value); Assert.IsInstanceOf <Reservation> (response, "response is Reservation"); }
public void UpdateReservationTest() { // TODO: add unit test for the method 'UpdateReservation' int? restaurantId = null; // TODO: replace null with proper value string reservationId = null; // TODO: replace null with proper value CreateReservation value = null; // TODO: replace null with proper value instance.UpdateReservation(restaurantId, reservationId, value); }
private void btnUpdate_Click(object sender, RoutedEventArgs e) { getRow(e); EntityFactory.Term = currentRow.Item as term; EntityFactory.Reservation = EntityFactory.Term.reservation; CreateReservation createReservationControl = new CreateReservation(); createReservationControl.Update_Reservation(); Content = createReservationControl; }
private void btnUpdate_Click(object sender, RoutedEventArgs e) { var selected = schedule.SelectedAppointment; var index = schedule.Appointments.IndexOf(schedule.Appointments.First(a => a.Subject.Equals(selected.Subject) && a.Location.Equals(selected.Location) && a.StartTime.Equals(selected.StartTime) && a.EndTime.Equals(selected.EndTime))); CreateReservation createReservationControl = new CreateReservation(); EntityFactory.Term = terms[index]; EntityFactory.Reservation = EntityFactory.Term.reservation; createReservationControl.Update_Reservation(); Content = createReservationControl; }
public IActionResult Create(CreateReservation createReservation) { var newReservation = new Reservation { Name = createReservation.Name, PhoneNumber = createReservation.PhoneNumber, BarberId = createReservation.BarberId }; _reservationService.CreateReservation(newReservation); return(ReloadPage()); }
private HttpResponseMessage MakeReservation(DateTime hour, int roomNumber) { var message = new CreateReservation { UserName = new UserName { LastName = "John", FirstName = "Doe" }, Hour = hour, RoomNumber = roomNumber }; return(server.HttpClient.PostAsync("/reservations", message.CreateHttpJsonMessage()).Result); }
public IHttpActionResult CreateBooking([FromBody] CreateReservation message) { var room = roomProvider.GetRoom(message.RoomNumber); var user = userProvider.GetFromUserName(new UserName(message.UserName.LastName, message.UserName.FirstName)); var day = Day.From(message.Hour.Date); var timeSlot = day.ComputeSlots(Constraints.SlotDuration).First(s => s.Contains(message.Hour)); var bookingResult = reservationService.BookRoom(room, user, timeSlot); if (bookingResult.Status == BookingStatus.Accepted) { return(Content(HttpStatusCode.Accepted, bookingResult.ReservationId)); } var availableSlotStarts = reservationService.GetBookableTimeSlots(room, timeSlot).Select(s => s.Start).ToList(); return(Content(HttpStatusCode.Conflict, availableSlotStarts)); }
public async Task <IActionResult> Put([FromBody] CreateReservation reservation) { if (reservation == null) { throw new ArgumentNullException(nameof(reservation)); } var mappedReservations = reservation.Seats.Select(seat => new Domain.Models.SeatReservation() { EmailAddress = seat.EmailAddress, SeatId = seat.SeatId }); var response = await _mediator.Send(new CreateReservationRequest(mappedReservations)); return(new NoContentResult()); }
public async Task <IActionResult> CreateReservation([FromBody] CreateReservation dto) { try { var Result = await _ctx.CreateReservation(dto); if (!Result) { return(BadRequest()); } } catch { return(BadRequest()); } return(Created(string.Empty, string.Empty)); }
public void SittingTest() { Sitting sitting = new Sitting { RestuarantId = 1, SittingTypeId = 1, Start = new DateTime(2020, 12, 20, 8, 30, 00), End = new DateTime(2020, 12, 20, 12, 30, 00), Capacity = 100, }; CreateReservation create = new CreateReservation(); create.Sitting = sitting; Assert.IsNotNull(create.Sitting); Assert.AreEqual(1, create.Sitting.RestuarantId); Assert.AreEqual(1, create.Sitting.SittingTypeId); Assert.AreEqual(new DateTime(2020, 12, 20, 8, 30, 00), create.Sitting.Start); Assert.AreEqual(new DateTime(2020, 12, 20, 12, 30, 00), create.Sitting.End); }
public async Task AddAsync(CreateReservation command, Captain captain, Pitch pitch) { var reservation = new Reservation(command.Name, command.StartDate, command.EndDate); if (_context.Reservations.Where(x => x.Pitch.Id == pitch.Id).Any(y => reservation.IsOverlaping(y)) == true) { throw new CorruptedOperationException("Rezerwacja na tym boisku w podanym okresie już istnieje! Sprawdź wszystkie rezerwacje w widoku boiska."); } if (captain.Reservations.Where(x => x.StartDate.Date == command.StartDate.Date).Count() >= 2) { throw new CorruptedOperationException("Maksymalna ilość rezerwacji na dzień to: 2."); } reservation.Pitch = pitch; reservation.Captain = captain; await _context.Reservations.AddAsync(reservation); await _context.SaveChangesAsync(); }
public void PersonTestValid() { //set up the data Person person = new Person { FirstName = "Me", LastName = "MyLast", Email = "[email protected]", Phone = "0000000000", RestuarantId = 1 }; CreateReservation create = new CreateReservation(); create.Person = person; Assert.IsNotNull(create.Person); Assert.AreEqual(person, create.Person); Assert.AreEqual("[email protected]", create.Person.Email); Assert.AreEqual("Me", create.Person.FirstName); Assert.AreEqual("MyLast", create.Person.LastName); Assert.AreEqual("1", create.Person.RestuarantId.ToString()); }
public ActionResult Create(ReservationModel model) { Guid id = Guid.NewGuid(); var cmd = new CreateReservation() { Name = model.Name, NumberOfSeats = model.NumberOfSeats, DiscountCode = model.DiscountCode, ReservationId = id }; //submit the command AgileWays.Cqrs.Commands.Writer.ICommandWriter writer = new AzureCommandWriter(); writer.SendCommand(cmd); //CloudHelper.EnqueueCommand(cmd); CloudHelper.LogMessage(1, "Created a new reservation", "CREATE"); //redirect to confirmation return(RedirectToAction("Confirmation", new { id = id })); }
public async Task <IActionResult> CreateReservation(int id, CreateReservation command) { if (!ModelState.IsValid) { ViewBag.ShowError = true; ViewBag.ErrorMessage = "Popraw wymagane błędy"; return(View("CreateReservation", command)); } try { var captainId = int.Parse(HttpContext.Session.GetString("Id")); var pitch = await _pitchService.GetAsync(id); var captain = await _captainService.GetAsync(captainId); await _reservationService.AddAsync(command, captain, pitch); ModelState.Clear(); ViewBag.ShowSuccess = true; ViewBag.SuccessMessage = "Dodawanie rezerwacji zakończone pomyślnie"; return(View()); } catch (CorruptedOperationException ex) { ViewBag.ShowError = true; ViewBag.ErrorMessage = ex.Message; return(View()); } catch (Exception) { ViewBag.ShowError = true; ViewBag.ErrorMessage = "Coś poszło nie tak"; return(View()); } }
static void Main(string[] args) { var theCommand = new CreateReservation() { DiscountCode = "HALF", Name = "David Hoerster", NumberOfSeats = 2, ReservationId = Guid.NewGuid() }; AgileWays.Cqrs.Commands.Writer.ICommandWriter writer = new AgileWays.Cqrs.Commands.Writer.CommandWriter(); writer.SendCommand(theCommand); var cancellation = new CancelReservation() { Reason = "just not that into it anymore", ReservationId = Guid.NewGuid() }; writer.SendCommand(cancellation); }
public void Init() { instance = new CreateReservation(); }
public Task <int> Handle(CreateReservation instr) { return(Task.FromResult(id)); }
public Task <int> Handle(CreateReservation instruction) { return(Task.FromResult(Create(instruction.Reservation))); }
public void HandleThread() { bool end = false; binaryFormatter = new BinaryFormatter(); while (!end) { try { DataTransferObject transferClass = (DataTransferObject)binaryFormatter.Deserialize(clientStream); switch (transferClass.Operation) { case Operation.SignIn: SignInUser signInUser = new SignInUser(); transferClass.Result = signInUser.ExecuteSystemOperation(transferClass.Object); break; case Operation.SignUp: RegisterUser registerUser = new RegisterUser(); transferClass.Result = registerUser.ExecuteSystemOperation(transferClass.Object); break; case Operation.LogOut: end = true; break; case Operation.CreateCar: CreateCar createCar = new CreateCar(); transferClass.Result = createCar.ExecuteSystemOperation(transferClass.Object); break; case Operation.GetAllCars: GetAllCars get = new GetAllCars(); transferClass.Result = get.ExecuteSystemOperation(transferClass.Object); break; case Operation.GetAllReservations: GetReservations reservations = new GetReservations(); transferClass.Result = reservations.ExecuteSystemOperation(transferClass.Object); break; case Operation.CreateReservation: CreateReservation createReservation = new CreateReservation(); transferClass.Result = createReservation.ExecuteSystemOperation(transferClass.Object); break; case Operation.DeleteCar: DeleteUser deleteUser = new DeleteUser(); transferClass.Result = deleteUser.ExecuteSystemOperation(transferClass.Object); break; case Operation.DeleteReservation: DeleteReservation deleteReservation = new DeleteReservation(); transferClass.Result = deleteReservation.ExecuteSystemOperation(transferClass.Object); break; case Operation.FindCar: FindCars findCar = new FindCars(); transferClass.Result = findCar.ExecuteSystemOperation(transferClass.Object); break; case Operation.FindReservation: GetReservations findReservation = new GetReservations(); transferClass.Result = findReservation.ExecuteSystemOperation(transferClass.Object); break; case Operation.FindByIDCar: FindByIdCar find = new FindByIdCar(); transferClass.Result = find.ExecuteSystemOperation(transferClass.Object); break; case Operation.FindByIDReservation: FindByIdReservation findByIdReservation = new FindByIdReservation(); transferClass.Result = findByIdReservation.ExecuteSystemOperation(transferClass.Object); break; } binaryFormatter.Serialize(clientStream, transferClass); } catch (Exception) { end = true; } } }
public async Task <IActionResult> Create(CreateReservation m) { var sitting = await _db.Sittings.FirstOrDefaultAsync(s => s.Id == m.Sitting.Id); if (sitting == null) { return(NotFound()); } if (m.Time < sitting.Start || m.Time > sitting.End) { ModelState.AddModelError("Time", "Invalid Time, must fall within sitting start/end times"); } if (ModelState.IsValid) { bool isMember = false; Person p; if (User.Identity.IsAuthenticated && User.IsInRole("Member")) { //get user by name var user = await _userManager.FindByNameAsync(User.Identity.Name); p = await _db.Members.FirstOrDefaultAsync(m => m.UserId == user.Id); isMember = true; } else//user not login and not member { p = new Person { FirstName = m.Person.FirstName, LastName = m.Person.LastName, Email = m.Person.Email, Phone = m.Person.Phone, RestuarantId = 1 }; _db.People.Add(p); } //make new reservation var r = new Reservation { Guest = m.Guest, StartTime = m.Time, SittingId = sitting.Id, Duration = m.Duration, Note = m.Note, StatusId = 1, //pending SourceId = 1, ///Online }; //connect reservation and person p.Reservations.Add(r); //save cahnge _db.SaveChanges(); if (isMember) { return(RedirectToAction("Index", "Reservation", new { Area = "Member" })); } return(RedirectToAction(nameof(Details), new { id = r.Id })); } //ViewData["PersonId"] = new SelectList(_db.People, "Id", "Discriminator", reservation.PersonId); //ViewData["SittingId"] = new SelectList(_db.Sittings, "Id", "Id", reservation.SittingId); //ViewData["SourceId"] = new SelectList(_db.ReservationSources, "Id", "Id", reservation.SourceId); //ViewData["StatusId"] = new SelectList(_db.ReservationStatuses, "Id", "Id", reservation.StatusId); //return View(reservation); //if we got so far, then the model is not valid sp send back create form var errors = ModelState.Values.SelectMany(v => v.Errors); m.Sitting = sitting; return(View(m)); }
public async Task <ActionResult <MutationResult> > CreateAsync([FromBody] CreateReservation mutation) { return(GetResult(await _mutationsHanlder.Handle(mutation))); }