public ActionResult Edit(int? id)
 {
     var offer = new SpecialOffer();
     if (id != null)
     {
         offer = _db.SpecialOffers.Find(id);
     }
     FillAuthKeys();
     ViewBag.Status = offer.Status.ToSelectList();
     return View(offer);
 }
        public ActionResult Edit(SpecialOffer model)
        {
            if (Request.Files.Count > 0)
            {
                HttpPostedFileBase file = Request.Files[0];
                if (file.ContentLength > 700 * 1024)
                {
                    ModelState.AddModelError("", "The maximum allowed picture size is 600KB");
                }
            }

            if (ModelState.IsValid)
            {
                if (IsAuth)
                {
                    var currUser = CurrentUser;
                    model.UserId = currUser.UserId;
                    model.UserName = currUser.FullName;
                    model.Status = currUser.IsAdmin() ? model.Status : PostStatusType.Pending;
                }
                else
                {
                    model.Status = PostStatusType.Pending;
                }

                if (Request.Files.Count > 0)
                {
                    HttpPostedFileBase file = Request.Files[0];
                    byte[] imageBytes = new byte[file.ContentLength];
                    file.InputStream.Read(imageBytes, 0, (int)file.ContentLength);
                    model.ImageType = file.FileName.Split('\\').Last();
                    model.ImageData = imageBytes;
                }

                if (model.EntityKey == 0)
                {
                    TempData[Constants.ViewBagMessageKey] = Strings.OfferPostSuccess;
                    _db.Entry(model).State = System.Data.EntityState.Added;
                }
                else
                {
                    _db.Entry(model).State = System.Data.EntityState.Modified;
                }

                _db.SaveChanges();
                return RedirectToAction("Index");
            }
            FillAuthKeys();
            ViewBag.Status = model.Status.ToSelectList();
            return View(model);
        }