Esempio n. 1
0
        public ActionResult Create(Offer offer)
        {
            if (ModelState.IsValid)
            {
                offer.AddedDate = DateTime.Now.Date;
                db.Offers.Add(offer);
                db.SaveChanges();

                SaveOfferImagesToDisk(offer);

                return RedirectToAction("Index");
            }

            return View();
        }
Esempio n. 2
0
        private void SaveOfferImagesToDisk(Offer offer)
        {
            if (offer.HotelImage != null)
            {
                SaveFileFromSessionToDisk(offer.HotelImage.FullImageName, offer.OfferId);
                SaveFileFromSessionToDisk(offer.HotelImage.CroppedImageName, offer.OfferId);
            }

            if (offer.LocationImage != null)
            {
                SaveFileFromSessionToDisk(offer.LocationImage.FullImageName, offer.OfferId);
                SaveFileFromSessionToDisk(offer.LocationImage.CroppedImageName, offer.OfferId);
            }
        }
Esempio n. 3
0
        public ActionResult Edit(Offer offer)
        {
            if (ModelState.IsValid)
            {
                //var existing = db.Images.Find(offer.HotelImage.Id);
                //((IObjectContextAdapter)db).ObjectContext.Detach(existing);
                //existing = db.Images.Find(offer.LocationImage.Id);
                //((IObjectContextAdapter)db).ObjectContext.Detach(existing);
                db.Entry(offer).State = EntityState.Modified;
                offer.AddedDate = DateTime.Now.Date;
                db.SaveChanges();

                SaveOfferImagesToDisk(offer);

                return RedirectToAction("Index");
            }

            return View(offer);
        }