public ActionResult Create([Bind(Include = "IsExternal,Email,Name,Image,ExternalLink,DisplayInHomePage")] FeaturedPartner featuredPartner) { if (ModelState.IsValid) { featuredPartner.Created = DateTime.Now; featuredPartner.Modified = DateTime.Now; if (featuredPartner.IsExternal.HasValue && featuredPartner.IsExternal.Value) { string imagePath = Server.MapPath(Global.FeaturedPartnerImages + string.Format("FeaturedPartners_{0}_{1}.jpg", featuredPartner.FeaturedPartnerId, DateTime.Now.ToString("ddMMyyss"))); featuredPartner.Image = ImageHelper.UploadImage(Request.Files["Image"], Global.FeaturedPartnerImages, imagePath, false); } else { var user = db.AspNetUsers.FirstOrDefault(x => x.Email.Equals(featuredPartner.Email, StringComparison.InvariantCultureIgnoreCase)); if (user == null) { ModelState.AddModelError("", "User not found."); return(View(featuredPartner)); } featuredPartner.PartnerId = user.Id; } db.FeaturedPartners.Add(featuredPartner); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(featuredPartner)); }
public ActionResult Edit([Bind(Include = "FeaturedPartnerId,Created,Modified,Name,Image,PartnerId,IsExternal,ExternalLink,DisplayInHomePage")] FeaturedPartner featuredPartner) { if (ModelState.IsValid) { FeaturedPartner dbFeaturedPartner = db.FeaturedPartners.Find(featuredPartner.FeaturedPartnerId); TryUpdateModel(dbFeaturedPartner); //db.Entry(featuredPartner).State = EntityState.Modified; if (featuredPartner.IsExternal.HasValue && featuredPartner.IsExternal.Value) { string oldpicpath = Request.Form["OldImagePath"]; if (Request.Files["Image"].ContentLength != 0) { string imagePath = Server.MapPath(Global.FeaturedPartnerImages + string.Format("FeaturedPartner_{0}_{1}.jpg", featuredPartner.FeaturedPartnerId, DateTime.Now.ToString("ddMMyyss"))); dbFeaturedPartner.Image = ImageHelper.UploadImage(Request.Files["Image"], Global.FeaturedPartnerImages, imagePath, false); } else { dbFeaturedPartner.Image = oldpicpath; } } dbFeaturedPartner.Modified = DateTime.Now; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(featuredPartner)); }
// GET: FeaturedPartners/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } FeaturedPartner featuredPartner = db.FeaturedPartners.Find(id); if (featuredPartner == null) { return(HttpNotFound()); } return(View(featuredPartner)); }
// GET: FeaturedPartners/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } FeaturedPartner featuredPartner = db.FeaturedPartners.Find(id); if (featuredPartner == null) { return(HttpNotFound()); } db.FeaturedPartners.Remove(featuredPartner); db.SaveChanges(); return(RedirectToAction("Index")); }