public ActionResult EditLodgeTypeSubmit([Bind(Include = "LodgeTypeId,Name,Surface,Description,MaxPersons,Picture, price, Disabled")] LodgeTypes model, HttpPostedFileBase upload, decimal?price)
        {
            if (ModelState.IsValid)
            {
                if (upload != null && upload.ContentLength > 0)
                {
                    using var reader = new System.IO.BinaryReader(upload.InputStream);
                    model.Picture    = reader.ReadBytes(upload.ContentLength);
                }

                if (price != null)
                {
                    LodgePrice oldlodgeprice = db.LodgePrice.Where(t => t.LodgeTypeId == model.LodgeTypeId && t.EndDate == null).First();

                    oldlodgeprice.EndDate         = DateTime.Now;
                    db.Entry(oldlodgeprice).State = EntityState.Modified;

                    LodgePrice lodgePrice = new LodgePrice
                    {
                        StartingDate = DateTime.Now,
                        price        = (decimal)price,
                        LodgeTypeId  = model.LodgeTypeId
                    };

                    db.LodgePrice.Add(lodgePrice);
                }

                db.Entry(model).State = EntityState.Modified;

                db.SaveChanges();

                return(RedirectToAction("LodgeType"));
            }
            return(RedirectToAction("EditLodgeType", model.LodgeTypeId));
        }
        public ActionResult AddLodgeTypeSubmit(LodgeTypes model, HttpPostedFileBase upload, decimal price)
        {
            if (ModelState.IsValid)
            {
                LodgeTypes lodgeTypes = new LodgeTypes
                {
                    Name        = model.Name,
                    Surface     = model.Surface,
                    Description = model.Description,
                    MaxPersons  = model.MaxPersons
                };
                if (upload != null && upload.ContentLength > 0)
                {
                    using (var reader = new System.IO.BinaryReader(upload.InputStream))
                    {
                        lodgeTypes.Picture = reader.ReadBytes(upload.ContentLength);
                    }
                }

                db.LodgeTypes.Add(lodgeTypes);
                db.SaveChanges();

                LodgePrice lodgePrice = new LodgePrice
                {
                    StartingDate = DateTime.Now,
                    price        = Convert.ToDecimal(price),
                    LodgeTypeId  = (from n in db.LodgeTypes orderby n.LodgeTypeId descending select n.LodgeTypeId).First()
                };
                db.LodgePrice.Add(lodgePrice);
                db.SaveChanges();

                return(RedirectToAction("LodgeType"));
            }
            return(RedirectToAction("AddLodgeType"));
        }
Esempio n. 3
0
        // 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 ActionResult DeleteConfirmed(int id)
        {
            LodgeTypes lodgeTypes = db.LodgeTypes.Find(id);

            db.LodgeTypes.Remove(lodgeTypes);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "LodgeTypeNaam,LodgeOmschrijving,aantalpersonen,prijs")] LodgeTypes lodgeTypes)
 {
     if (ModelState.IsValid)
     {
         db.Entry(lodgeTypes).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(lodgeTypes));
 }
        public ActionResult Create([Bind(Include = "LodgeTypeNaam,LodgeOmschrijving,aantalpersonen,prijs")] LodgeTypes lodgeTypes)
        {
            if (ModelState.IsValid)
            {
                db.LodgeTypes.Add(lodgeTypes);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(lodgeTypes));
        }
        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: Lodgetypescontroller/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            LodgeTypes lodgeTypes = db.LodgeTypes.Find(id);

            if (lodgeTypes == null)
            {
                return(HttpNotFound());
            }
            return(View(lodgeTypes));
        }
        public ActionResult EditLodgeType(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            //get the loge type details from the database
            LodgeTypes lodgeTypes = db.LodgeTypes.Find(id);

            //look if the lodgetype can be found in the database
            if (lodgeTypes == null)
            {
                return(HttpNotFound());
            }

            //return the logetype details to the view
            return(View(lodgeTypes));
        }