示例#1
0
        public ActionResult AddBookedCustomer(FormCollection fm, [Bind(Include = "ApartmentID,UploadedFile")] IdPicture image)
        {
            var UserID   = User.Identity.GetUserId();
            var cartItem = db.Carts.Where(u => u.UserID == UserID);

            foreach (var c in cartItem.ToList())
            {
                var AlreadyBook = db.BookingDetails.Where(i => c.CheckIn <= i.CheckOut && c.CheckOut >= i.CheckIn && i.Booking.StatusID != 3 && i.ApartmentID == c.ApartmentID);

                if (AlreadyBook.Count() == 0)
                {
                    var item1 = new Booking {
                        UserID = UserID, BookDate = DateTime.Now, StatusID = 1
                    };
                    db.Bookings.Add(item1);

                    db.SaveChanges();
                    Session["bookingid"] = item1.BookingID;
                    foreach (var item in cartItem)
                    {
                        var item2 = new BookingDetail {
                            BookingID = item1.BookingID, ApartmentID = item.ApartmentID, CheckIn = item.CheckIn, CheckOut = item.CheckOut, NoOfGuests = item.NoOfGuests, Price = item.OrigPrice, BlockedReason = null
                        };
                        db.BookingDetails.Add(item2);
                    }
                    db.SaveChanges();
                    var crt = db.Carts.Where(a => a.UserID == UserID).Max(i => i.NoOfGuests);
                    for (int i = 0; i < crt; i++)
                    {
                        var fname = fm["fname" + i];
                        var sname = fm["sname" + i];
                        var email = fm["email" + i];
                        var phone = fm["phone" + i];

                        var item3 = new Customer {
                            FName = fname, SName = sname, Email = email, Phone = phone, IDpicture = null
                        };
                        db.Customers.Add(item3);
                        db.SaveChanges();
                        var item4 = new BookedCustomer {
                            CartID = cartItem.FirstOrDefault().CartID, BookingID = (int)Session["bookingid"], CustomerID = item3.CustomerID
                        };
                        db.BookedCustomers.Add(item4);
                        db.SaveChanges();
                    }

                    db.Carts.Remove(c);
                    db.SaveChanges();
                }
                else
                {
                    throw new System.InvalidOperationException("Oops! someone else has just booked this apartment. Dont worry we have plenty of others nearby. Please search again.");
                }
            }



            return(RedirectToAction("BookedCustomer", "Home"));
        }
示例#2
0
 public override string ToString()
 {
     //Renvoie en String tous les champs
     return
         (" IdPicture: " + IdPicture.ToString() +
          " Url: " + Url +
          " IdRoom: " + IdRoom.ToString());
 }