public ActionResult Edit(ArticlesGroup articlesGroup) { if (ModelState.IsValid) { db.Entry(articlesGroup).State = EntityState.Modified; var Inputfile = Request.Files[0]; if (Inputfile != null && Inputfile.ContentLength > 0) { string filename = Path.GetFileName(Inputfile.FileName); string path = Path.Combine(Server.MapPath(ConfigurationManager.AppSettings["MovieImage"].ToString()), filename); articlesGroup.FileName = filename; Inputfile.SaveAs(path); //Save Image in Binary Format. NB: need to figure out later how to display it in Datatable using this format articlesGroup.Image = new byte[Inputfile.ContentLength]; Inputfile.InputStream.Read(articlesGroup.Image, 0, Inputfile.ContentLength); } else { db.Entry(articlesGroup).Property("FileName").IsModified = false; db.Entry(articlesGroup).Property("Image").IsModified = false; } db.SaveChanges(); return(RedirectToAction("Index")); } return(View(articlesGroup)); }
public ActionResult Create(ArticlesGroup articlesGroup) { if (ModelState.IsValid) { HttpPostedFileBase Inputfile = Request.Files[0]; if (Inputfile != null && Inputfile.ContentLength > 0) { string filename = Path.GetFileName(Inputfile.FileName); string path = Path.Combine(Server.MapPath(ConfigurationManager.AppSettings["MovieImage"].ToString()), filename); articlesGroup.FileName = filename; Inputfile.SaveAs(path); articlesGroup.Image = new byte[Inputfile.ContentLength]; Inputfile.InputStream.Read(articlesGroup.Image, 0, Inputfile.ContentLength); } db.ArticlesGroups.Add(articlesGroup); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(articlesGroup)); }
public IHttpActionResult PutArticlesGroup(int id, ArticlesGroup articlesGroup) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != articlesGroup.Id) { return(BadRequest()); } db.Entry(articlesGroup).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ArticlesGroupExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult DeleteConfirmed(int id) { ArticlesGroup articlesGroup = db.ArticlesGroups.Find(id); db.ArticlesGroups.Remove(articlesGroup); db.SaveChanges(); return(RedirectToAction("Index")); }
public IHttpActionResult GetArticlesGroup(int id) { ArticlesGroup articlesGroup = db.ArticlesGroups.Find(id); if (articlesGroup == null) { return(NotFound()); } return(Ok(articlesGroup)); }
public IHttpActionResult PostArticlesGroup(ArticlesGroup articlesGroup) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.ArticlesGroups.Add(articlesGroup); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = articlesGroup.Id }, articlesGroup)); }
// GET: ArticlesGroups/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ArticlesGroup articlesGroup = db.ArticlesGroups.Find(id); if (articlesGroup == null) { return(HttpNotFound()); } return(View(articlesGroup)); }
public IHttpActionResult DeleteArticlesGroup(int id) { ArticlesGroup articlesGroup = db.ArticlesGroups.Find(id); if (articlesGroup == null) { return(NotFound()); } db.ArticlesGroups.Remove(articlesGroup); db.SaveChanges(); return(Ok(articlesGroup)); }
// GET: ArticlesGroups/Create public ActionResult Create(int?id) // Create Sub Category for selected Category if parameter is passed { var articlesGroup = new ArticlesGroup(); articlesGroup.ParentId = 0; if (id != null) { ArticlesGroup parentGroup = db.ArticlesGroups.Find(id); ViewBag.Parent = parentGroup.Name; articlesGroup.ParentId = (int)id; } return(View(articlesGroup)); }