public async Task HandleWithValidCreateRequestCallSaveAsExpectedResultAsync() { // Arrange var bookingModel = new Booking { Id = 299536, DropLocation = "Chennai, Chrompet" }; var config = new MapperConfiguration(m => { m.CreateMap <Entities.Booking, Booking>(); m.CreateMap <Booking, Entities.Booking>(); }); var mapper = new Mapper(config); var bookingList = MockBookingListResponse().ToList().AsQueryable(); repository = new Mock <IRepository>(); repository.Setup(m => m.Query <Entities.Booking>()) .Returns(bookingList); underTest = new CreateBooking(repository.Object, mapper); request = new CreateBookingRequest(bookingModel); // Act CancellationToken cancellationToken; var result = await underTest.Handle(request, cancellationToken); // Assert Assert.NotNull(result); Assert.Equal(bookingModel.Id, result.Id); Assert.Equal(bookingModel.DropLocation, result.DropLocation); }
public ActionResult BookGroup(CreateBooking booking) { if (!CapacityCheck(booking)) { var warningMessage = "Unable to create the group booking. " + Resource(booking).Name + " has a capacity of " + Resource(booking).Capacity + ", this booking requires a capacity of " + BookingCapacity(booking); return(RedirectToAction("Index", new { warningMessage = warningMessage })); } try { var userId = Session["UserId"].ToString(); var user = userService.GetUser(new Guid(userId)); service.AddGroupBooking( booking.GroupBooking.Date, booking.GroupBooking.SelectedAttendees.ToList(), booking.GroupBooking.SelectedTeams.ToList(), booking.GroupBooking.StartTime, booking.GroupBooking.EndTime, booking.Resource, user.UserId); return(RedirectToAction("Index", new { successMessage = "Group booking successfully added!" })); } catch (Exception e) { ModelState.AddModelError("", e); return(View(booking)); } }
public async Task HandleWithValidCreateRequestCallSaveAsExpectedResult() { // Arrange var watchListModel = new WatchListModel { MovieId = 299536, Comments = "Avengers: Infinity is good" }; var config = new MapperConfiguration(m => { m.CreateMap <WatchList, WatchListModel>(); }); var mapper = new Mapper(config); repository = new Mock <IRepository>(); repository.Setup(m => m.Get <WatchList>(It.IsAny <int>())) .Returns((WatchList)null); createWatchList = new CreateBooking(repository.Object, mapper); createWatchListRequest = new CreateBookingRequest(watchListModel); // Act CancellationToken cancellationToken; var result = await createWatchList.Handle(createWatchListRequest, cancellationToken); // Assert Assert.NotNull(result); Assert.Equal(watchListModel.Comments, result.Comments); Assert.Equal(watchListModel.MovieId, result.MovieId); }
public async Task HandleWithNullCreateRequestCallRetrunNullWithThrowsException() { // Arrange var watchListEntity = new WatchList { MovieId = 299536, Comments = "Avengers: Infinity War is good" }; var watchListModel = new WatchListModel { MovieId = 299536, Comments = "Avengers: Infinity War" }; var config = new MapperConfiguration(m => { m.CreateMap <WatchList, WatchListModel>(); }); var mapper = new Mapper(config); repository = new Mock <IRepository>(); repository.Setup(m => m.Get <WatchList>(It.IsAny <int>())) .Returns(watchListEntity); createWatchList = new CreateBooking(repository.Object, mapper); createWatchListRequest = new CreateBookingRequest(watchListModel); // Act CancellationToken cancellationToken; var result = await createWatchList.Handle(createWatchListRequest, cancellationToken); // Assert Assert.Null(result); }
public object Post(CreateBooking request) { // Your business logic var id = Db.Insert(request.ConvertTo <Booking>(), selectIdentity: true); return(new IdResponse { Id = id.ToString() }); }
public ActionResult Create(CreateBooking cmd) { if (ModelState.IsValid) { cmd.Id = Guid.NewGuid(); Domain.Dispatcher.SendCommand(cmd); return(RedirectToAction("Index")); } return(View()); }
private void btnCreateBooking_Click(object sender, RoutedEventArgs e) { CreateBooking dialog = new CreateBooking(); dialog.ShowDialog(); if (dialog.DialogResult.HasValue && dialog.DialogResult.Value) { MessageBox.Show("Booking has been created!"); } FillBookingsListViews(); }
/// <summary> /// Gets the capcity a booking requires /// Teams memebers + attendees /// </summary> /// <param name="booking">The booking</param> /// <returns>The number of attendess in the booking</returns> private int BookingCapacity(CreateBooking booking) { var attendeeCount = booking.GroupBooking.SelectedAttendees.Count(); var teamMemberCount = 0; foreach (string teamId in booking.GroupBooking.SelectedTeams) { var team = teamService.GetTeam(new Guid(teamId)); teamMemberCount += team.Members.Count(); } return(attendeeCount + teamMemberCount); }
public async Task <IActionResult> CreateBooking(CreateBooking createBooking) { Booking booking = new Booking(); if (createBooking.Booking.CheckIn == createBooking.Booking.CheckOut) { TimeSpan time = new TimeSpan(20, 30, 0); createBooking.Booking.CheckOut = createBooking.Booking.CheckOut.AddDays(0.8); booking.CheckOut = createBooking.Booking.CheckOut; booking.CheckIn = createBooking.Booking.CheckIn; booking.Customer = createBooking.Customer; booking.Total = 0; booking.CreateTime = DateTime.Now; } else { booking.CheckOut = createBooking.Booking.CheckOut; booking.CheckIn = createBooking.Booking.CheckIn; booking.Customer = createBooking.Customer; booking.Total = 0; booking.CreateTime = DateTime.Now; } List <BookingDetail> bookingDetails = new List <BookingDetail>(); for (int i = 0; i < createBooking.NumberRoom.Length; i++) { for (int j = 0; j < createBooking.NumberRoom[i]; j++) { List <Room> rooms = CheckTypeRoom(createBooking.TypeRoomID[i], createBooking.Booking.CheckIn, createBooking.Booking.CheckOut); BookingDetail bookingDetail = new BookingDetail(); bookingDetail.RoomId = rooms[j].ID; bookingDetail.CheckInExpected = createBooking.Booking.CheckIn; bookingDetail.CheckOutExpected = createBooking.Booking.CheckOut; bookingDetail.Booking = booking; bookingDetail.NumberDate = 0; bookingDetail.Price = createBooking.PriceRoom[i]; bookingDetail.Total = 0; bookingDetail.NumberDateDiscount = 0; bookingDetail.PriceDiscount = 0; bookingDetails.Add(bookingDetail); } } booking.BookingDetails = bookingDetails; _context.Add(booking); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
/// <summary> /// Getsthe create booking page /// </summary> /// <returns>Booking/Create</returns> public ActionResult Create() { var model = new CreateBooking { Slots = GetSlots(), GroupBooking = new GroupBooking { Attendees = GetAttendees(), Teams = GetTeams(), } }; return(View(model)); }
public wrapper.Booking ConvertSingleBookingToWrapper(CreateBooking entry) { var slot = slotService.GetSlot(entry.SingleBooking.Slot); var resource = resourceService.GetResource(entry.Resource); var booking = new wrapper.Booking { Date = entry.SingleBooking.Date, Slot = slot, Resource = resource, User = ConvertUserToWrapper(entry.User), }; return(booking); }
/// <summary> /// Retrieves available resources for a single booking /// </summary> /// <param name="booking">The booking Id</param> /// <returns>Booking/Create/SingleBooking</returns> public PartialViewResult RetrieveAvailableResources(CreateBooking booking) { var availableResources = service.GetAvailableResources(booking.SingleBooking.Date, booking.SingleBooking.Slot); var rs = new ResourceService(); var resources = converter.ConvertResourceListFromWrapper(availableResources); booking.Resources = resources; var time = slotService.GetSlot(booking.SingleBooking.Slot).StartTime; ViewBag.Message = booking.Resources.Count() + " resources are available on " + booking.SingleBooking.Date.ToShortDateString() + " at " + string.Format("{0:hh\\:mm}", time); return(PartialView("_resources", booking)); }
/// <summary> /// Checks if a resource is big enough for a group booking /// </summary> /// <param name="booking">The booking</param> /// <returns>True or false</returns> private bool CapacityCheck(CreateBooking booking) { var resource = resourceService.GetResource(booking.Resource); var attendeeCount = booking.GroupBooking.SelectedAttendees.Count(); var teamMemberCount = 0; foreach (string teamId in booking.GroupBooking.SelectedTeams) { var team = teamService.GetTeam(new Guid(teamId)); teamMemberCount += team.Members.Count(); } if (resource.Capacity >= (attendeeCount + teamMemberCount)) { return(true); } return(false); }
public async Task <IActionResult> CreateBooking([FromBody] CreateBooking cmd) { try { var result = await messaging.Send(cmd); return(StatusCode(result.Code, result.Value)); } catch (Domain.BookingException e) { return(StatusCode(e.Status, new { e.Message })); } catch (Exception e) { logger.LogError(e, $"{nameof(CreateBooking)} error"); return(StatusCode(500)); } }
public void PostBookingAsAdminExample() { // Create and configure client // BokaMera API supports MsgPack, prefer that for efficient communication with the API. // See https://github.com/ServiceStack/ServiceStack/wiki/MessagePack-Format // See https://github.com/ServiceStack/ServiceStack/wiki/C%23-client var client = new JsonServiceClient(ApiUrlTest); client.Headers.Add("x-api-key", "YOUR_API_KEY_HERE"); //Language settings sv = swedish, en = english (default) client.Headers.Add("x-language", "sv"); //Authenticate the user var response = client.Post <AuthenticateResponse>("authenticate", new { UserName = "******", //The user is administrator for Company Demo Hårsalong with CompanyId: 00000000-0000-0000-0000-000000000001 (see https://www.bokamera.se/Demo1) Password = "******", }); client.AddHeader("x-ss-id", response.SessionId); client.BearerToken = response.BearerToken; //Create request object for create a new booking var request = new CreateBooking { CompanyId = new Guid("00000000-0000-0000-0000-000000000001"), CustomerId = new Guid("00000000-0000-0000-0000-000000000010"), From = DateTime.Now, To = DateTime.Now.AddMinutes(60), AllowBookingOutsideSchedules = true, ServiceId = 1, //Klippning , kort hår - Kortbetalning (see https://www.bokamera.se/Demo1/BookTime?event=1) Resources = new System.Collections.Generic.List <ResourceToBook>() { new ResourceToBook() { ResourceId = 1, ResourceTypeId = 1 }, new ResourceToBook() { ResourceId = 5, ResourceTypeId = 2 }, } }; }
public ActionResult Book(CreateBooking booking) { try { var userId = Session["UserId"].ToString(); var user = userService.GetUser(new Guid(userId)); booking.User = converter.ConvertUserFromWrapper(user); var convertedBooking = converter.ConvertSingleBookingToWrapper(booking); service.AddBooking(convertedBooking); return(RedirectToAction("Index", new { successMessage = "Booking successfully added!" })); } catch { return(View("Create")); } }
/// <summary> /// Gets the available resources for a group booking /// </summary> /// <param name="booking"></param> /// <returns></returns> public PartialViewResult RetrieveAvailableResourcesForGroupBooking(CreateBooking booking) { var availableResources = service.GetAvailableResourcesForGroupBooking( booking.GroupBooking.Date, booking.GroupBooking.StartTime, booking.GroupBooking.EndTime, booking.GroupBooking.Capacity); var rs = new ResourceService(); var resources = converter.ConvertResourceListFromWrapper(availableResources); booking.Resources = resources; var startTime = slotService.GetSlot(booking.GroupBooking.StartTime).StartTime; var endTime = slotService.GetSlot(booking.GroupBooking.EndTime).EndTime; ViewBag.Message = booking.Resources.Count() + " resources are available on " + booking.GroupBooking.Date.ToShortDateString() + " between " + string.Format("{0:hh\\:mm}", startTime) + " - " + string.Format("{0:hh\\:mm}", endTime); return(PartialView("_groupResources", booking)); }
public ActionResult BookBlock(CreateBooking booking) { try { var userId = Session["UserId"].ToString(); var user = userService.GetUser(new Guid(userId)); service.AddBlockBooking( booking.BlockBooking.StartDate, booking.BlockBooking.EndDate, booking.BlockBooking.StartSlot, booking.BlockBooking.EndSlot, booking.Resource, user.UserId); return(RedirectToAction("Index", new { successMessage = "Block bookings successfully added!" })); } catch { return(View("Create")); } }
public void TestSilverBooking() { var silverBooking = new CreateBooking(BookingTypeId.Silver()); silverBooking.TypeId.ShouldBe(2); }
private void mnuCreateBooking_Click(object sender, RoutedEventArgs e) { CreateBooking window = new CreateBooking(); window.Show(); }
public void TestBronzeBooking() { var silverBooking = new CreateBooking(BookingTypeId.Bronze()); silverBooking.TypeId.ShouldBe(1); }
static void Main(string[] args) { if (SQL.CheckConnection()) { SQL.CreateDatabase(); } int homeChoice, typeChoice, usrActionChoice, admActionChoice, newOldChoice; Customer customer; do { homeChoice = PickStart.View(); if (homeChoice == 0) { typeChoice = PickUserType.View(); if (typeChoice == 0) { newOldChoice = PickNewOrOldCustomer.View(); if (newOldChoice == 0) { customer = CustomerLogin.View(); } else { customer = CreateCustomer.View(); } ShowCustomer.View(customer); do { usrActionChoice = PickCustomerActions.View(); switch (usrActionChoice) { case 0: CreateBooking.View(customer); break; case 1: ShowCustomerBookings.View(customer); break; case 2: customer = UpdateCustomer.View(customer); break; case 3: Delete.Customer(customer.CustomerId); usrActionChoice = 4; break; default: break; } } while (usrActionChoice != 4); } else if (typeChoice == 1) { do { admActionChoice = PickAdminActions.View(); switch (admActionChoice) { case 0: CreateMovie.View(); break; case 1: ShowCustomers.View(); break; default: break; } } while (admActionChoice != 2); } } } while (homeChoice == 0); }
public void TestCustomBooking() { const int custom = 546; var silverBooking = new CreateBooking(BookingTypeId.Custom(custom)); silverBooking.TypeId.ShouldBe(custom); }
private Resource Resource(CreateBooking booking) { var resource = converter.ConvertResourceFromWrapper(resourceService.GetResource(booking.Resource)); return(resource); }
public void TestGoldBooking() { var silverBooking = new CreateBooking(BookingTypeId.Gold()); silverBooking.TypeId.ShouldBe(3); }