public ActionResult Edit([Bind(Include = "Id,Name,Email,Message,IsReady,CreationDate,CreatedId,ModifiedDate,ModifiedId,DeletedDate,DeletedId")] Contact contact) { if (ModelState.IsValid) { db.Entry(contact).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(contact)); }
public ActionResult Edit(Category category) { if (ModelState.IsValid) { db.Entry(category).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
// GET: Admin/Contacts/Details/5 public ActionResult Details(int?id) { if (id == null) { if (Request.IsAjaxRequest()) { return(Content("")); } return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Contact contact = db.Contact.Find(id); if (contact == null) { if (Request.IsAjaxRequest()) { return(Content("")); } return(HttpNotFound()); } if (Request.IsAjaxRequest()) { return(PartialView("~/Areas/Admin/Views/Contacts/Partial/_ContactPartial.cshtml", contact)); } if (!contact.IsReady) { contact.IsReady = true; contact.ModifiedDate = DateTime.Now; db.Entry(contact).State = EntityState.Modified; db.SaveChanges(); } return(View(contact)); }
public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Info info = db.Info.Find(id); info.IsRead = true; db.Entry(info).State = EntityState.Modified; db.SaveChanges(); if (info == null) { return(HttpNotFound()); } return(View(info)); }
public ActionResult Edit(News news, HttpPostedFileBase mediaUrl, string fileName) { News entity = db.News.Find(news.Id); if (entity == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ModelState.Remove("mediaUrl"); if (mediaUrl != null) { bool valid = true; if (!mediaUrl.CheckImageType()) { ModelState.AddModelError("mediaUrl", "Şəkil uyğun deyil!"); valid = false; } if (!mediaUrl.CheckImageSize(5)) { ModelState.AddModelError("mediaUrl", "Şəklin ölçüsü uyğun deyil!"); valid = false; } if (valid) { string newPath = mediaUrl.SaveImage(Server.MapPath("~/Template/media")); //System.IO.File.Move(Server.MapPath(System.IO.Path.Combine("~/Template/media", entity.MediaUrl)), // Server.MapPath(System.IO.Path.Combine("~/Template/media", entity.MediaUrl))); if (!string.IsNullOrWhiteSpace(entity.MediaUrl)) { Server.MoveFile("~/Template/media" , entity.MediaUrl , string.Format("archive/{0}-{1}", entity.Id, entity.MediaUrl)); } entity.MediaUrl = newPath; } } else if (!string.IsNullOrWhiteSpace(entity.MediaUrl) && string.IsNullOrWhiteSpace(fileName)) { entity.MediaUrl = null; } if (ModelState.IsValid) { entity.Title = news.Title; entity.Body = news.Body; entity.Author = news.Author; entity.IsPopular = news.IsPopular; entity.ModifiedDate = DateTime.UtcNow.AddHours(4); entity.CategoryId = news.CategoryId; db.Entry(entity).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryId = new SelectList(db.Category, "Id", "Name", news.CategoryId); return(View(news)); }