Exemple #1
0
        public ActionResult AddGuests(int?id, int?EID)
        {
            ViewBag.GuestID = new SelectList(db.Fetch <Guest>("Select * From Guests g inner join Reservation_Guest rg on g.GuestID= rg.GuestID inner join Reservation r on r.ReservationID =rg.ReservationID Where rg.ReservationID = @0", id), "GuestID", "GuestName");
            ViewBag.IsLead  = db.FirstOrDefault <string>("Select GuestName From Guests g inner join Reservation_Guest rg on g.GuestID= rg.GuestID inner join Reservation r on r.ReservationID =rg.ReservationID Where rg.ReservationID = @0 and  rg.Islead =@1", id, true);

            ViewBag.ResDet = db.FirstOrDefault <Reservation>("Select * From Reservation Where ReservationID = @0", id);
            ViewBag.Dets   = db.Fetch <Guest>("Select * From Guests g inner join Reservation_Guest rg on g.GuestID= rg.GuestID inner join Reservation r on r.ReservationID =rg.ReservationID Where rg.ReservationID = @0", id);
            var rec = base.BaseCreateEdit <Guest>(EID, "GuestID");

            if (EID != null)
            {
                GuestsDets ci = new GuestsDets()
                {
                    GuestAddress = rec.GuestAddress,
                    GuestCountry = rec.GuestCountry,
                    GuestID      = rec.GuestID,
                    GuestName    = rec.GuestName,
                    Dislikes     = rec.Dislikes,
                    Email        = rec.Email,
                    Likes        = rec.Likes,
                    Phone        = rec.Phone,
                    PhotoID      = rec.PhotoID
                };
                return(View(ci));
            }
            else
            {
                GuestsDets ci = new GuestsDets()
                {
                };
                return(View(ci));
            }
        }
Exemple #2
0
        public ActionResult AddGuests([Bind(Include = "GuestID,GuestName,GuestAddress,GuestCountry,Email,Phone,UploadedFile,Likes,Dislikes")] GuestsDets guest, int?RID, int?GuestIDD)
        {
            using (var transaction = db.GetTransaction())
            {
                try
                {
                    if (GuestIDD != null && RID != null)
                    {
                        var resguest = db.FirstOrDefault <Reservation_Guest>("Select * from Reservation_Guest Where ReservationID=@0 and GuestID =@1", RID, GuestIDD);


                        var UpdateRec = db.Execute("update Reservation_Guest set IsLead=1 Where GuestID=@0 and ReservationID =@1", GuestIDD, RID);

                        //var item = new Reservation_Guest { ReservationID=(int)RID,GuestID=(int)GuestID,IsLead=true };
                        //db.Save(item);
                        transaction.Complete();
                        return(RedirectToAction("AddGuests"));
                    }
                    Guest res = new Guest
                    {
                        GuestAddress = guest.GuestAddress,
                        GuestCountry = guest.GuestCountry,
                        GuestID      = guest.GuestID,
                        GuestName    = guest.GuestName,
                        Dislikes     = guest.Dislikes,
                        Email        = guest.Email,
                        Likes        = guest.Likes,
                        Phone        = guest.Phone,
                        PhotoID      = guest.PhotoID
                    };

                    if (guest.UploadedFile != null)
                    {
                        string fn = guest.UploadedFile.FileName.Substring(guest.UploadedFile.FileName.LastIndexOf('\\') + 1);
                        fn = guest.GuestName + "_" + fn;
                        string SavePath = System.IO.Path.Combine(Server.MapPath("~/Images"), fn);
                        guest.UploadedFile.SaveAs(SavePath);

                        //System.Drawing.Bitmap upimg = new System.Drawing.Bitmap(siteTransaction.UploadedFile.InputStream);
                        //System.Drawing.Bitmap svimg = MyExtensions.CropUnwantedBackground(upimg);
                        //svimg.Save(System.IO.Path.Combine(Server.MapPath("~/Images"), fn));

                        res.PhotoID = fn;
                    }
                    else
                    {
                        res.PhotoID = guest.PhotoID;
                    }
                    base.BaseSave <Guest>(res, guest.GuestID > 0);
                    if (guest.GuestID == 0)
                    {
                        var res_guest = new Reservation_Guest {
                            GuestID = res.GuestID, ReservationID = (int)RID, IsLead = false
                        };
                        db.Insert(res_guest);
                    }
                    transaction.Complete();
                    return(RedirectToAction("AddGuests"));
                }
                catch (Exception ex)
                {
                    db.AbortTransaction();
                    throw ex;
                }
            }
        }