public ActionResult Create([Bind] BookingModels bookingModels, int offerId) { var offer = db.OfferModels.Where(off => off.OfferID == offerId).FirstOrDefault(); var user_id = User.Identity.GetUserId(); var request = db.RequestModels.Where(req => req.RequestID == offer.RequestID).FirstOrDefault(); var requestIsOpen = request.IsOpen; var request_id = offer.RequestID; var supp_id = offer.UserID; if (ModelState.IsValid && requestIsOpen == true) { bookingModels.BookingDate = DateTime.Now; bookingModels.OfferID = offerId; bookingModels.RequestID = offer.RequestID; bookingModels.SuppFirstName = offer.SupplierFirstName; bookingModels.SuppLastName = offer.SupplierLastName; bookingModels.CustFirstName = request.CustomerFirstName; bookingModels.CustLastName = request.CustomerLastName; bookingModels.CustId = user_id; bookingModels.SuppId = supp_id; request.IsOpen = false; db.BookingModels.Add(bookingModels); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(bookingModels)); }
// bookings is model en database public ActionResult Submitted(BookingModels booking) { //Create a list of lodgetypes from the database table LodgeTypes List <LodgeTypes> lodgeTypes = db.LodgeTypes.Where(t => t.Disabled == false).ToList(); //create a viewbag for the list lodgetypes ViewBag.lodgetypes = lodgeTypes; //kijk of de booking checkindate nier eerder is dan de datum van vandaag if (booking.CheckInDate > DateTime.Now) { //kijk of de checkindate eerder is dan de checkout date if (booking.CheckInDate < booking.CheckOutDate) { //kijk lodge de lodgetype bestaat if (db.LodgeTypes.Where(table => table.Name == booking.LodgeTypes).Count() != 0) { //selecteer de lodgetype ID uit de databse LodgeTypes lodgeType = db.LodgeTypes.Where(table => table.Name == booking.LodgeTypes).First(); //slecteer alle lodges van de geselecteerde lodtype uit de database List <Lodges> lodge = db.Lodges.Where(table => table.LodgeTypeId == lodgeType.LodgeTypeId && table.Disabled == false).ToList(); foreach (Lodges item in lodge) { //kijk voor elke lodge van het geselecteerde lodge type of hij beschikbaar is if (db.Bookings.Where(table => table.LodgeId == item.LodgeId && (table.CheckInDate < booking.CheckOutDate) && (booking.CheckInDate < table.CheckOutDate) && table.Canceled == false).Count() == 0) { //zet de geselecteerde data in een session var Session["booking"] = booking; //als de gebruiker al is ingelogd if (User.Identity.IsAuthenticated) { //TRUE: stuur de gebruiker naar de booking controller return(RedirectToAction("Index", "Booking")); } else { //FALSE: stuur de gebruiker naar de register view return(RedirectToAction("Register", "Account")); } } } //stuur een error message als er geen lodge beschikbaar is van het geselecteerde lodge type ViewBag.Message = string.Format("There is no lodge available of the type {0}", booking.LodgeTypes); return(View("index")); } //stuur een error als er geen lodgetype van het geselecteerde lodge niet bestaat ViewBag.Message = string.Format("The lodge type: {0} does not exisit", booking.LodgeTypes); return(View("index")); } //sruut een error als de chekindate later is dan de checkout date ViewBag.Message = string.Format("The checkin date cant be later than the checkout date"); return(View("index")); } //stuur een error wanneer de checkindate eerder is dan de datum van vandaag ViewBag.Message = string.Format("The checkin date cant be earlier than the current date"); return(View("index")); }
public async Task <bool> AddBookings(List <BookingModel> bookingModels, int tenantId) { foreach (BookingModel bookingModel in bookingModels) { BookingModels.Add(bookingModel); } return(true); }
public ActionResult DeleteConfirmed(int id) { BookingModels bookingModels = db.BookingModels.Find(id); db.BookingModels.Remove(bookingModels); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "BookingID,BookingDate,Description")] BookingModels bookingModels) { if (ModelState.IsValid) { db.Entry(bookingModels).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(bookingModels)); }
public ActionResult Index() { //de if statement zorg er voor dat deze functie niet te gebruiken is als er niks in de sessions staat) if (Session["booking"] != null) { //haal de informatie van de booking uit de session BookingModels booking = (BookingModels)Session["booking"]; //haal de lodge ID van de geselecteerde lodge uit de database LodgeTypes lodgeType = db.LodgeTypes.Where(table => table.Name == booking.LodgeTypes && table.Disabled == false).First(); //kijk of de Lodgetype bestaat if (db.Lodges.Where(table => table.LodgeTypeId == lodgeType.LodgeTypeId).Count() != 0) { //slecteer alle lodges van de geselecteerde lodtype uit de database List <Lodges> lodge = db.Lodges.Where(table => table.LodgeTypeId == lodgeType.LodgeTypeId && table.Disabled == false).ToList(); foreach (Lodges item in lodge) { //kijk voor elke lodge van het geselecteerde lodge type of hij beschikbaar is if (db.Bookings.Where(table => table.LodgeId == item.LodgeId && (table.CheckInDate < booking.CheckOutDate) && (booking.CheckInDate < table.CheckOutDate) && table.Canceled == false).Count() == 0) { //maak de booking DateTime?date = booking.CheckInDate; Bookings newBookings = new Bookings { //zet de opjecten over CheckInDate = booking.CheckInDate, CheckOutDate = booking.CheckOutDate, Discount = (int)db.spGetDiscount(date).First(), UserId = User.Identity.GetUserId(), LodgeId = item.LodgeId, Price = (decimal)db.spGetLodgePrice(date, item.Code).First() }; //clear de session Session.Clear(); db.Bookings.Add(newBookings); db.SaveChanges(); //set een complete message in de session Session["Message"] = "Your booking has been completed!"; //redirect to the booking view return(RedirectToAction("index", "bookingview")); //testing should redirect to "Booking sucseeded" page } } } } Session.Clear(); return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));; }
// GET: BookingModels/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BookingModels bookingModels = db.BookingModels.Find(id); if (bookingModels == null) { return(HttpNotFound()); } return(View(bookingModels)); }
public virtual BookingRequestDTO ConvertBookingModelstoBookingRequestDTO(BookingModels input) { BookingRequestDTO bookingRequest = new BookingRequestDTO() { Id = input.Id, ApplicationUserId = input.ApplicationUserId, CustomerEmail = input.CustomerEmail, CustomerName = input.CustomerName, Description = input.description, StartTime = input.BookingTimeSlotModels.startTime, EndTime = input.BookingTimeSlotModels.endTime }; return(bookingRequest); }
public async Task <BookingModels> PutBookingModels(int id, BookingModels bookingModels) { context.Entry(bookingModels).State = EntityState.Modified; try { await context.SaveChangesAsync(); return(bookingModels); } catch (DbUpdateConcurrencyException) { throw; } }
public async Task <BookingModels> PostBookingModels(BookingModels bookingRequest) { try { context.Bookings.Add(bookingRequest); await context.SaveChangesAsync(); return(bookingRequest); } catch (DbUpdateException) { return(null); throw; } }
public virtual SingleBookingDTO ConvertBookingModelToSingleBookingDTO(BookingModels input) { SingleBookingDTO BookingDTO = new SingleBookingDTO() { Id = input.Id, CustomerEmail = input.CustomerEmail, CustomerName = input.CustomerName, Description = input.description, Approved = input.Approved, StartTime = input.BookingTimeSlotModels.startTime, EndTime = input.BookingTimeSlotModels.endTime, ApplicationUserFirstName = input.ApplicationUser.FirstName, ApplicationUserLastName = input.ApplicationUser.LastName }; return(BookingDTO); }
public virtual BookingModels ConvertBookingRequestDTOtoBookingModels(BookingRequestDTO input) { BookingModels bookingModel = new BookingModels() { CustomerName = input.CustomerName, CustomerEmail = input.CustomerEmail, description = input.Description, ApplicationUserId = input.ApplicationUserId, BookingTimeSlotModels = new BookingTimeSlotModels() { startTime = input.StartTime, endTime = input.EndTime } }; return(bookingModel); }
public async Task <BookingModels> DeleteBookingModels(int bookingId, string userId) { BookingModels bookingModels = await context.Bookings.FindAsync(bookingId); BookingTimeSlotModels bookingtimeslot = bookingModels.BookingTimeSlotModels; if (bookingModels == null) { return(null); } if (!bookingModels.ApplicationUserId.Equals(userId)) { return(null); } context.Bookings.Remove(bookingModels); context.BookingTimeSlots.Remove(bookingtimeslot); await context.SaveChangesAsync(); return(bookingModels); }
public void ExportToExcel() { try { //Excel.Application appli = new Excel.Application(); //Excel.Workbook workb = appli.Workbooks.Add(System.Reflection.Missing.Value); //Excel.Worksheet works = workb.ActiveSheet; //BookingModel bk = new BookingModel(); //works.Cells[1, 1] = "ID"; //works.Cells[1, 2] = "Time"; //works.Cells[1, 3] = "Status"; //works.Cells[1, 4] = "TableId"; //works.Cells[1, 5] = "UserId"; //works.Cells[1, 6] = "Table_ID"; //int row = 2; //foreach(Booking p in bk.findAll()) //{ // works.Cells[row, 1] = p.Id; // works.Cells[row, 2] = p.Time.ToString("dd/mm/yyyy"); // works.Cells[row, 3] = p.Status; // works.Cells[row, 4] = p.TableId; // works.Cells[row, 5] = p.User; // works.Cells[row, 6] = p.Table; // row++; //} //workb.Close(); //Marshal.ReleaseComObject(workb); //ViewBag.Result = "In thanh cong"; var grid = new GridView(); BookingModels bk = new BookingModels(); grid.DataSource = from p in bk.findAll() select new { ID = p.Id, Time = p.Time.ToString("dd/MM/yyyy"), Status = p.Status.ToString(), User = p.User.UserName, Price = p.BookingDetails.Sum(e => e.Meal.Price * e.Number).ToString("0,000"), Table = p.TableId }; grid.DataBind(); Response.ClearContent(); Response.AddHeader("content-disposition" , "attachment;filename=BookingList.xls"); Response.ContentType = "application/excel"; StringWriter sw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); grid.RenderControl(htw); Response.Write(sw.ToString()); Response.End(); } catch (Exception ex) { ViewBag.Result = ex.Message; } }