// GET: Posts/Create public ActionResult Create() { LoginDatabaseEntites db = new LoginDatabaseEntites(); if (Request.HttpMethod == "POST") { var naslov = Request.Form["title"].ToString(); var vsebina = Request.Form["content"].ToString(); var category = Convert.ToInt32(Request.Form["kategorija"]); var path = Path.Combine("/assets/images", "wha.jpg"); if (Request.Files.Count > 0) { HttpPostedFileBase file = Request.Files[0]; var fileName = Guid.NewGuid().ToString() + Path.GetFileName(file.FileName); path = Path.Combine("/assets/images", fileName); path.ToList(); file.SaveAs(Server.MapPath(path)); } DateTime date2 = (DateTime) new SqlDateTime(DateTime.Now); var temp = new DateTime().Date.ToString("yyyy-MM-dd HH:mm:ss"); blogs novi = new blogs() { title = naslov, content = vsebina, kategorija = category, Imagepath = path }; db.blogs.Add(novi); db.SaveChanges(); return(RedirectToAction("Index", "cms")); } ViewBag.AppDataApplicationType = new SelectList(db.categories, "CatId", "naslov_kategorije"); return(View()); }
// DELETE: api/BlogDetails/5 public void Delete(int id) { LoginDatabaseEntites db = new LoginDatabaseEntites(); var posodobi = db.blogs.Find(id); db.blogs.Remove(posodobi); db.SaveChanges(); }
// POST: api/BlogDetails public void Post([FromBody] blogs value) { var naslov = value.title; var vsebina = value.content; var category = value.kategorija; var imagepath = (value.Imagepath != null) ? value.Imagepath : "https://workhardanywhere.com/wp-content/uploads/2014/11/WHA_marvin_king_ashore.jpg"; blogs novi = new blogs() { title = naslov, content = vsebina, kategorija = category, Imagepath = imagepath }; db.blogs.Add(novi); db.SaveChanges(); }
public ActionResult Delete(int id) { LoginDatabaseEntites db = new LoginDatabaseEntites(); var posodobi = db.blogs.Find(id); db.blogs.Remove(posodobi); db.SaveChanges(); return(RedirectToAction("Index", "Cms")); }
public ActionResult Edit(int id) { LoginDatabaseEntites db = new LoginDatabaseEntites(); if (Request.HttpMethod == "POST") { var naslov = Request.Form["title"].ToString(); var vsebina = Request.Form["content"].ToString(); var idbloga = Convert.ToInt32(Request.Form["blogid"].ToString()); var category = Convert.ToInt32(Request.Form["kategorija"]); var path = ""; if (Request.Files.Count > 0) { HttpPostedFileBase file = Request.Files[0]; var fileName = Guid.NewGuid().ToString() + Path.GetFileName(file.FileName); path = Path.Combine("/assets/images", fileName); path.ToList(); file.SaveAs(Server.MapPath(path)); } var posodobi = db.blogs.FirstOrDefault(x => x.blogid == id); posodobi.content = vsebina; posodobi.title = naslov; posodobi.kategorija = category; if (path.Length > 1) { posodobi.Imagepath = path; } db.SaveChanges(); return(RedirectToAction("Index", "Cms")); } else { var post = db.blogs.SingleOrDefault(x => x.blogid == id); if (post != null) { ViewBag.Found = true; List <blogs> blg = new List <blogs>(); blg.Add(post); ViewBag.AppDataApplicationType = new SelectList(db.categories, "CatId", "naslov_kategorije"); return(View(blg)); } else { ViewBag.Found = false; } } return(View()); }