public void AddCommand_SplitBookingNonMatchingValues_CannotExecute() { var windowManager = Substitute.For <IWindowManager>(); var dialogs = Substitute.For <IDialogs>(); var fileSystem = Substitute.For <IFileSystem>(); var processApi = Substitute.For <IProcess>(); var projectData = new ProjectData(new Settings(), windowManager, dialogs, fileSystem, processApi); var sut = new EditBookingViewModel(projectData, YearBegin) { BookingText = "abc", DebitIndex = 1, DebitAccount = 100, BookingValue = 4, CreditSplitEntries = { new SplitBookingViewModel { BookingText = "X", BookingValue = 1, AccountIndex = 1, AccountNumber = 200 }, new SplitBookingViewModel { BookingText = "Y", BookingValue = 2, AccountIndex = 2, AccountNumber = 300 } } }; sut.AddCommand.CanExecute(null).Should().BeFalse(); }
public async Task <IActionResult> Edit(EditBookingViewModel editModel) { try { if (ModelState.IsValid) { BookingVehicule booking = _bookingRepository.GetBooking(editModel.BookingId); var currentuser = await _userManager.GetUserAsync(HttpContext.User); booking.Car = editModel.Car; booking.StartDate = editModel.StartDate; booking.EndDate = editModel.EndDate; booking.BookingVanStatus = editModel.BookingVanStatus; _bookingRepository.Update(booking); return(RedirectToAction("BookingsList", "Booking")); } return(View()); } catch (Exception ex) { _logger.LogError(ex, $"When retrieving to edit booking."); throw; } }
public async Task <IActionResult> Edit(int bookingid) { try { var booking = _bookingRepository.GetBooking(bookingid); var currentuser = await _userManager.GetUserAsync(HttpContext.User); var editBookingViewModel = new EditBookingViewModel { Car = booking.Car, BookingId = booking.BookingId, StartDate = booking.StartDate, EndDate = booking.EndDate, BookingVanStatus = booking.BookingVanStatus }; return(View(editBookingViewModel)); } catch (Exception ex) { _logger.LogError(ex, $"When retrieving to edit booking."); throw; } }
public void SelectedTemplate_SetTemplateWithDebit_DebitAccountSet() { var windowManager = Substitute.For <IWindowManager>(); var dialogs = Substitute.For <IDialogs>(); var fileSystem = Substitute.For <IFileSystem>(); var processApi = Substitute.For <IProcess>(); var projectData = new ProjectData(new Settings(), windowManager, dialogs, fileSystem, processApi); var sut = new EditBookingViewModel(projectData, YearBegin) { CreditAccount = 1, DebitAccount = 2, BookingText = "default", BookingValue = 42 }; sut.Accounts.Add(new AccountDefinition { ID = 1 }); sut.Accounts.Add(new AccountDefinition { ID = 2 }); sut.Accounts.Add(new AccountDefinition { ID = 3 }); sut.BindingTemplates.Add(new BookingTemplate { Debit = 3 }); sut.SelectedTemplate = sut.BindingTemplates.Last(); using var _ = new AssertionScope(); sut.DebitAccount.Should().Be(3); sut.CreditAccount.Should().Be(1); sut.BookingValue.Should().Be(42); sut.BookingText.Should().Be("default"); }
public IActionResult Edit(string id) { User user = _userManager.FindByIdAsync(_userManager.GetUserId(User)).Result; if (User.IsInRole(Convert.ToString(Roles.SuperAdmin))) { user = _userManager.FindByIdAsync(user.IdOfTheSelectedRestaurateur).Result; } Booking booking = _db.Bookings.FirstOrDefault(b => b.Id == id); if (booking != null) { EditBookingViewModel model = new EditBookingViewModel { Id = booking.Id, Date = booking.Date, Comment = booking.Comment, ClientName = booking.ClientName, PhoneNumber = booking.PhoneNumber, Email = booking.Email, Pax = booking.Pax, State = booking.State, Tables = _db.Tables.Where(t => t.RestaurantId == user.RestaurantId).ToList(), BookingTables = _db.BookingTables.Where(bt => bt.BookingId == booking.Id).ToList() }; return(View(model)); } return(NotFound()); }
public async Task <IActionResult> EditBooking(long?id) { IActionResult authenticationResult = await AuthenticateUserLogin(false); if (authenticationResult != null) { return(authenticationResult); } EquipmentCheckboxSelect = new List <EquipmentCheckboxSelectViewModel>(); long bookingId = (long)id; List <Equipment> equipmentList = (List <Equipment>) await CommandFactory.CreateCommand(CommandFactory.GET_ALL_EQUIPMENT, DbContext).Execute(); Booking bookingToEdit = (Booking)await CommandFactory.CreateCommand(CommandFactory.GET_BOOKING, bookingId, DbContext).Execute(); EditBookingViewModel editBookingViewModel = CreateEditBookingViewModel(bookingToEdit); editBookingViewModel.ChosenEquipmentList = CreateEquipmentCheckboxSelectList(equipmentList); foreach (EquipmentCheckboxSelectViewModel item in editBookingViewModel.ChosenEquipmentList) { foreach (EquipmentBooking equipmentBooking in bookingToEdit.EquipmentBookings) { if (item.Id == equipmentBooking.Equipment.Id) { item.CheckboxAnswer = true; } } } return(View(editBookingViewModel)); }
public async Task <ActionResult> Edit(Guid id, EditBookingViewModel input) { try { if (ModelState.IsValid) { //if phone number is provided, make sure it is valid. //if no phone number is provided, that's ok as well string phoneNumber = null; if (!string.IsNullOrEmpty(input.PassengerPhone)) { phoneNumber = await _nexmo.FormatPhoneNumber(input.PassengerPhone); if (phoneNumber == null) { ModelState.AddModelError("PassengerPhone", "Please enter a valid phone number"); return(View(input)); } } var booking = _context.Bookings .Include(b => b.AssignedPilot) .FirstOrDefault(b => b.Id == id); if (booking == null) { return(NotFound()); } var userId = _userManager.GetUserId(User); if (!User.IsAdmin() && booking.AssignedPilot.Id != userId) { return(RedirectToAction("Details", new { id = id, errorMessage = "Only admin or currently assigned pilot can edit booking" })); } //create booking booking.BookingDate = input.BookingDate; booking.PassengerName = input.PassengerName; booking.PassengerWeight = input.PassengerWeight; booking.PassengerPhone = phoneNumber; booking.PassengerEmail = input.PassengerEmail; booking.PassengerFee = input.PassengerFee; _context.SaveChanges(); //redirect to edit action return(RedirectToAction("Details", new { id = booking.Id })); } } catch (Exception ex) { _logger.LogError(0, $"Error editing booking {id}, {ex.Message}, {ex}"); ModelState.AddModelError("", $"An unexpected error occured during editing"); } return(View(input)); }
public void Ctor_DateAfterEnd_DateLimited() { var windowManager = Substitute.For <IWindowManager>(); var dialogs = Substitute.For <IDialogs>(); var fileSystem = Substitute.For <IFileSystem>(); var processApi = Substitute.For <IProcess>(); var projectData = new ProjectData(new Settings(), windowManager, dialogs, fileSystem, processApi); var sut = new EditBookingViewModel(projectData, YearEnd + TimeSpan.FromDays(1)); sut.Date.Should().Be(YearEnd); }
public bool ValidateBooking(Object bookingViewModel) { bool valid = true; if (bookingViewModel is BookVehicleViewModel) { BookVehicleViewModel bookVehicleViewModel = (BookVehicleViewModel)bookingViewModel; double dateRangeInDays = (bookVehicleViewModel.StartDate.Date - bookVehicleViewModel.EndDate.Date).TotalDays; if (bookVehicleViewModel.StartDate.Date < DateTime.Today.Date) { ModelState.AddModelError("", "Booking cannot begin in the past."); valid = false; } if (dateRangeInDays > 14) { ModelState.AddModelError("", "Booking cannot be for longer than 2 weeks."); valid = false; } if (dateRangeInDays == 0 && bookVehicleViewModel.EndHalfDay != true) { ModelState.AddModelError("", "Minimum booking length is half a day."); valid = false; } } else if (bookingViewModel is EditBookingViewModel) { EditBookingViewModel editBookingViewModel = (EditBookingViewModel)bookingViewModel; double dateRangeInDays = (editBookingViewModel.StartDate.Date - editBookingViewModel.EndDate.Date).TotalDays; if (dateRangeInDays > 14) { ModelState.AddModelError("", "Booking cannot be for longer than 2 weeks."); valid = false; } if (dateRangeInDays == 0 && editBookingViewModel.EndHalfDay != true) { ModelState.AddModelError("", "Minimum booking length is half a day."); valid = false; } return(valid); } return(valid); }
public void OnInitialize_Initialized() { var windowManager = Substitute.For <IWindowManager>(); var dialogs = Substitute.For <IDialogs>(); var fileSystem = Substitute.For <IFileSystem>(); var processApi = Substitute.For <IProcess>(); var projectData = new ProjectData(new Settings(), windowManager, dialogs, fileSystem, processApi); var sut = new EditBookingViewModel(projectData, YearBegin); ((IActivate)sut).Activate(); sut.DisplayName.Should().NotBeNullOrWhiteSpace(); sut.SelectedTemplate.Should().BeNull("not template should be selected by default"); }
public void AddCommand_ValidValues_CanExecute() { var windowManager = Substitute.For <IWindowManager>(); var dialogs = Substitute.For <IDialogs>(); var fileSystem = Substitute.For <IFileSystem>(); var processApi = Substitute.For <IProcess>(); var projectData = new ProjectData(new Settings(), windowManager, dialogs, fileSystem, processApi); var sut = new EditBookingViewModel(projectData, YearBegin) { BookingText = "abc", CreditIndex = 1, DebitIndex = 2, BookingValue = 42 }; sut.AddCommand.CanExecute(null).Should().BeTrue(); }
public IActionResult EditBooking(long bookingIDPMS) { Cart cartForEdit = new Cart(); cartForEdit = bookingRepository.MapBookingToCart(bookingIDPMS); EditBookingViewModel eBVM = new EditBookingViewModel() { Cart = cartForEdit, ResourceTypes = bookingRepository.GetResourceTypes(cartForEdit.CompanyID), RateCompositions = bookingRepository.GetRateCompositions(cartForEdit.CompanyID) }; return(View(eBVM)); }
public void CreateJournalEntry_SplitCreditEntries_JournalEntryCorrect() { var windowManager = Substitute.For <IWindowManager>(); var dialogs = Substitute.For <IDialogs>(); var fileSystem = Substitute.For <IFileSystem>(); var processApi = Substitute.For <IProcess>(); var projectData = new ProjectData(new Settings(), windowManager, dialogs, fileSystem, processApi); var sut = new EditBookingViewModel(projectData, YearBegin) { BookingIdentifier = 42, Date = new DateTime(2020, 6, 20) }; sut.CreditSplitEntries.Add( new SplitBookingViewModel { BookingText = "Credit1", BookingValue = 10, AccountNumber = 100 }); sut.CreditSplitEntries.Add( new SplitBookingViewModel { BookingText = "Credit2", BookingValue = 20, AccountNumber = 200 }); sut.BookingText = "Debit"; sut.BookingValue = 30; sut.DebitAccount = 300; var journalEntry = sut.CreateJournalEntry(); journalEntry.Should().BeEquivalentTo( new AccountingDataJournalBooking { Date = 2020_0620, ID = 42, Credit = new List <BookingValue> { new BookingValue { Account = 100, Text = "Credit1", Value = 1000 }, new BookingValue { Account = 200, Text = "Credit2", Value = 2000 } }, Debit = new List <BookingValue> { new BookingValue { Account = 300, Text = "Debit", Value = 3000 } } });
public EditBookingViewModel CreateEditBookingViewModel(Booking bookingToEdit) { EditBookingViewModel editBookingViewModel = new EditBookingViewModel(); editBookingViewModel.BookingId = bookingToEdit.Id; editBookingViewModel.StartDate = bookingToEdit.StartDate; editBookingViewModel.EndDate = bookingToEdit.EndDate; editBookingViewModel.LateReturn = bookingToEdit.LateReturn; editBookingViewModel.StartHalfDay = bookingToEdit.EndHalfDay; editBookingViewModel.Collected = bookingToEdit.Collected; editBookingViewModel.Price = bookingToEdit.Price; editBookingViewModel.VehicleId = bookingToEdit.Vehicle.Id; editBookingViewModel.VehicleName = bookingToEdit.Vehicle.Manufacturer + " " + bookingToEdit.Vehicle.Model; editBookingViewModel.VehicleCostPerDay = bookingToEdit.Vehicle.CostPerDay; editBookingViewModel.UserForename = bookingToEdit.User.Forename; editBookingViewModel.UserSurname = bookingToEdit.User.Surname; return(editBookingViewModel); }
public async Task <IActionResult> Edit(EditBookingViewModel model, int tableId) { if (ModelState.IsValid) { User user = await _userManager.FindByIdAsync(_userManager.GetUserId(User)); if (User.IsInRole(Convert.ToString(Roles.SuperAdmin))) { user = await _userManager.FindByIdAsync(user.IdOfTheSelectedRestaurateur); } var booking = _db.Bookings.FirstOrDefault(b => b.Id == model.Id); if (booking != null) { if (booking.BookingTables.All(b => b.TableId != tableId)) { BookingTable bookingTable = new BookingTable() { BookingId = booking.Id, TableId = tableId }; _db.Entry(bookingTable).State = EntityState.Added; } booking.Date = model.Date; booking.Comment = model.Comment; booking.ClientName = model.ClientName; booking.PhoneNumber = model.PhoneNumber; booking.Email = model.Email; booking.Pax = model.Pax; booking.State = model.State; booking.EditorId = user.Id; booking.EditedDate = DateTime.Now; _db.Entry(booking).State = EntityState.Modified; } await _db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View()); }
public void AddCommand_FirstBooking_BookingNumberIncremented() { var windowManager = Substitute.For <IWindowManager>(); var dialogs = Substitute.For <IDialogs>(); var fileSystem = Substitute.For <IFileSystem>(); var processApi = Substitute.For <IProcess>(); var projectData = new ProjectData(new Settings(), windowManager, dialogs, fileSystem, processApi); var sut = new EditBookingViewModel(projectData, YearBegin); var oldNumber = sut.BookingIdentifier; sut.CreditAccount = 100; sut.DebitAccount = 990; using var monitor = sut.Monitor(); sut.AddCommand.Execute(null); sut.BookingIdentifier.Should().Be(oldNumber + 1); monitor.Should().RaisePropertyChangeFor(m => m.BookingIdentifier); }
public Booking ConvertViewModelToBooking(Object bookingViewModel) { if (bookingViewModel is BookVehicleViewModel) { BookVehicleViewModel bookVehicleViewModel = (BookVehicleViewModel)bookingViewModel; Booking booking = new Booking(); ApplicationUser userBooking = new ApplicationUser(); Vehicle chosenVehicle = new Vehicle(); userBooking.Id = bookVehicleViewModel.UserId; chosenVehicle.Id = bookVehicleViewModel.ChosenVehicleId; booking.StartDate = bookVehicleViewModel.StartDate; booking.EndDate = bookVehicleViewModel.EndDate; booking.StartHalfDay = bookVehicleViewModel.StartHalfDay; booking.EndHalfDay = bookVehicleViewModel.EndHalfDay; booking.Price = bookVehicleViewModel.TotalCost; booking.Vehicle = chosenVehicle; booking.User = userBooking; return(booking); } else if (bookingViewModel is EditBookingViewModel) { EditBookingViewModel editBookingViewModel = (EditBookingViewModel)bookingViewModel; Booking booking = new Booking(); booking.Id = editBookingViewModel.BookingId; booking.StartDate = editBookingViewModel.StartDate; booking.EndDate = editBookingViewModel.EndDate; booking.StartHalfDay = editBookingViewModel.StartHalfDay; booking.EndHalfDay = editBookingViewModel.EndHalfDay; booking.Price = editBookingViewModel.Price; booking.Collected = editBookingViewModel.Collected; return(booking); } return(null); }
// GET: Bookings/Edit/5 public IActionResult Edit(Guid id) { if (id == null) { return(NotFound()); } var booking = DbContext.Bookings.FirstOrDefault(b => b.Id == id); if (booking == null) { return(NotFound()); } var editBookingViewModel = new EditBookingViewModel() { Booking = booking, Tracks = DbContext.Tracks }; return(View(editBookingViewModel)); }
public ActionResult Edit(Guid id) { var booking = _context.Bookings .FirstOrDefault(b => b.Id == id); if (booking == null) { return(NotFound()); } var vm = new EditBookingViewModel { Id = booking.Id, BookingDate = booking.BookingDate, PassengerName = booking.PassengerName, PassengerWeight = booking.PassengerWeight, PassengerEmail = booking.PassengerEmail, PassengerPhone = booking.PassengerPhone.AsPhoneNumber(), PassengerFee = (int)booking.PassengerFee, }; return(View(vm)); }
public void OnInitialize_AllAccountTypesAdded_AccountRelatedPropertiesNotEmpty() { var windowManager = Substitute.For <IWindowManager>(); var dialogs = Substitute.For <IDialogs>(); var fileSystem = Substitute.For <IFileSystem>(); var processApi = Substitute.For <IProcess>(); var projectData = new ProjectData(new Settings(), windowManager, dialogs, fileSystem, processApi); var sut = new EditBookingViewModel(projectData, YearBegin); foreach (AccountDefinitionType type in Enum.GetValues(typeof(AccountDefinitionType))) { sut.Accounts.Add(new AccountDefinition { Name = type.ToString(), Type = type }); } ((IActivate)sut).Activate(); sut.Accounts.Should().NotBeEmpty(); sut.IncomeAccounts.Should().NotBeEmpty(); sut.IncomeRemoteAccounts.Should().NotBeEmpty(); sut.ExpenseAccounts.Should().NotBeEmpty(); sut.ExpenseRemoteAccounts.Should().NotBeEmpty(); }
public ActionResult Edit(EditBookingViewModel model) { try { if (!ModelState.IsValid) { return(View(model)); } var record = _bookrepo.FindById(model.BookingId); record.NumberOfDays = model.NumberOfDays; var isSuccess = _bookrepo.Update(record); if (!isSuccess) { ModelState.AddModelError("", "Error while saving"); return(View(model)); } return(RedirectToAction(nameof(Details), new { id = model.EmployeeId })); } catch { return(View(model)); } }
public async Task <IActionResult> Edit(EditBookingViewModel model) { var customer = GetCurrentClient(); if (customer == null) { return(RedirectToAction("Login", "Auth", new { Area = "Client" })); } if (ModelState.IsValid) { var booking = await _dbContext.Bookings .Include(b => b.Invoice) .Include(b => b.Package) .Include(b => b.Package.PackageType) .SingleAsync(m => m.Id == model.Id); if (booking == null) { return(NotFound()); } if (booking.CustomerId != customer.Id) { return(Unauthorized()); } if (booking.Invoice.Status != InvoiceStatus.NotIssued) { return(Unauthorized()); } booking.ServiceId = model.ServiceId; booking.RequestDate = model.RequestDate; booking.OriginLocationId = model.OriginLocationId; booking.DestinationLocationId = model.DestinationLocationId; booking.PickupRequired = model.PickupRequired; booking.PickupAddress = model.PickupAddress; booking.PickupContactNumber = model.PickupContactNumber; booking.ConsigneeName = model.ConsigneeName; booking.ConsigneeAddress = model.ConsigneeAddress; booking.ConsigneeContactNumber = model.ConsigneeContactNumber; booking.Package.Description = model.PackageDescription; booking.Package.Pieces = model.Pieces; booking.Package.Weight = model.Weight; booking.Package.SpecialInstructions = model.SpecialInstructions; booking.Package.ReferenceNumber = model.ReferenceNumber; booking.Package.PackageTypeId = model.PackageTypeId; _dbContext.Update(booking); await _dbContext.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewData["LocationId"] = new SelectList(_dbContext.Locations, "Id", "Name"); ViewData["ServiceId"] = new SelectList(_dbContext.Services, "Id", "Name", model.ServiceId); ViewData["PackageTypeId"] = new SelectList(_dbContext.PackageTypes, "Id", "Name"); return(View(model)); }
public async Task <IActionResult> Edit(int?id) { var customer = GetCurrentClient(); if (customer == null) { return(RedirectToAction("Login", "Auth", new { Area = "Client" })); } if (id == null) { return(NotFound()); } Booking booking = await _dbContext.Bookings .Include(b => b.Invoice) .Include(b => b.Package) .Include(b => b.Package.PackageType) .SingleAsync(m => m.Id == id); if (booking == null) { return(NotFound()); } if (booking.CustomerId != customer.Id) { return(Unauthorized()); } if (booking.Invoice.Status != InvoiceStatus.NotIssued) { return(Unauthorized()); } var model = new EditBookingViewModel() { Id = booking.Id, ServiceId = booking.ServiceId, RequestDate = booking.RequestDate, OriginLocationId = booking.OriginLocationId, DestinationLocationId = booking.DestinationLocationId, PickupRequired = booking.PickupRequired, PickupAddress = booking.PickupAddress, PickupContactNumber = booking.PickupContactNumber, ConsigneeName = booking.ConsigneeName, ConsigneeAddress = booking.ConsigneeAddress, ConsigneeContactNumber = booking.ConsigneeContactNumber, PackageDescription = booking.Package.Description, Pieces = booking.Package.Pieces, Weight = booking.Package.Weight, SpecialInstructions = booking.Package.SpecialInstructions, ReferenceNumber = booking.Package.ReferenceNumber, PackageTypeId = booking.Package.PackageTypeId }; ViewData["LocationId"] = new SelectList(_dbContext.Locations, "Id", "Name"); ViewData["ServiceId"] = new SelectList(_dbContext.Services, "Id", "Name", model.ServiceId); ViewData["PackageTypeId"] = new SelectList(_dbContext.PackageTypes, "Id", "Name"); return(View(model)); }
public async Task <IActionResult> EditBooking(EditBookingViewModel editBookingViewModel) { IActionResult authenticationResult = await AuthenticateUserLogin(false); if (authenticationResult != null) { return(authenticationResult); } bool bookingValid = ValidateBooking(editBookingViewModel); if (bookingValid) { List <Equipment> chosenEquipmentList = new List <Equipment>(); List <Booking> coincidingBookings = (List <Booking>) await CommandFactory.CreateCommand(CommandFactory.CHECK_FOR_COINCIDING_BOOKINGS, editBookingViewModel.StartDate, editBookingViewModel.EndDate, DbContext).Execute(); for (int i = 0; i < coincidingBookings.Count; i++) { if (coincidingBookings[i].Id == editBookingViewModel.BookingId) { coincidingBookings.RemoveAt(i); break; } } if (coincidingBookings.Count > 0) { foreach (Booking coincidingBooking in coincidingBookings) { if (editBookingViewModel.VehicleId == coincidingBooking.Vehicle.Id) { ViewData["ChosenVehicle"] = await GetChosenVehicle(editBookingViewModel.VehicleId); ModelState.AddModelError("", "The vehicle is not available for the period of your booking. The latest you can book this vehicle until is " + coincidingBooking.StartDate.AddDays(-1).ToString("dd/MM/yyyy")); return(View(editBookingViewModel)); } } foreach (EquipmentCheckboxSelectViewModel equipmentCheckbox in editBookingViewModel.ChosenEquipmentList) { if (equipmentCheckbox.CheckboxAnswer == true) { Equipment tempEquipment = new Equipment(); tempEquipment.Id = equipmentCheckbox.Id; tempEquipment.Name = equipmentCheckbox.Name; bool equipmentAvailable = (bool)await CommandFactory.CreateCommand(CommandFactory.CHECK_EQUIPMENT_AVAILABILITY, coincidingBookings, tempEquipment, DbContext).Execute(); if (equipmentAvailable == true) { chosenEquipmentList.Add(tempEquipment); } else { errorString = "A " + equipmentCheckbox.Name + " is not available for the period of your booking. Please select a different booking period, or continue without this equipment item."; ModelState.AddModelError("", errorString); return(View(editBookingViewModel)); } } } } Booking booking = ConvertViewModelToBooking(editBookingViewModel); if (booking == null) { errorString = "Something went wrong, please try again."; ModelState.AddModelError("", errorString); return(View(editBookingViewModel)); } int bookingUpdated = (int)await CommandFactory.CreateCommand(CommandFactory.UPDATE_BOOKING, booking, chosenEquipmentList, DbContext).Execute(); if (bookingUpdated >= 1) { TempData["successmessage"] = "Booking Updated Successfully."; return(RedirectToAction("Index", "Home")); } else { errorString = "Something went wrong, please try again."; ModelState.AddModelError("", errorString); return(View(editBookingViewModel)); } } return(View(editBookingViewModel)); }