public ActionResult EditPost(int?id, PdfViewModel model, MenugroupViewModel mgmodel) { ViewBag.PageEdit = true; ViewBag.Class = "admin"; ViewBag.PdfPanelActive = "active"; HttpPostedFileBase fileImg = Request.Files["fileImg"]; HttpPostedFileBase filePdf = Request.Files["filePdf"]; if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var PdfItem = db.Pdfs.Find(id); var MenuItem = db.Menugroups.Where(mi => mi.PdfId == id); if (PdfItem == null) { return(HttpNotFound()); } if (fileImg != null) { model.Img = ConvertToBytes(fileImg); } else { model.Img = null; } if (PdfItem.FileName != null) { var PdfFile = filePdf; var PdfFileItem = Regex.Replace(PdfFile.FileName, " ", "-"); var fileName = System.IO.Path.GetFileName(PdfFileItem); var path = System.IO.Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~/Content/PdfFiles/"), fileName); PdfFile.SaveAs(path); model.FileName = PdfFileItem; if (TryUpdateModel(PdfItem, "", new string[] { "Title", "Summary", "Created", "Publish", "Author", "Img", "Filename", "NavbarId", "ImageId", "IsExternal", "Exlink" })) { ; } } else { if (TryUpdateModel(PdfItem, "", new string[] { "Title", "Summary", "Created", "Publish", "Author", "Img", "NavbarId", "ImageId", "IsExternal", "Exlink" })) { ; } } db.Entry(PdfItem).State = EntityState.Modified; int i = db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult EditPost(int?id, PageViewModel model) { ViewBag.PageEdit = true; ViewBag.Class = "admin"; ViewBag.PagePanelActive = "active"; if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var Page = db.Pages.Find(id); if (Page == null) { return(HttpNotFound()); } Page.SubContent = Request["subcontent"]; if (Request.Files["upload"] != null) { HttpPostedFileBase file = Request.Files["upload"]; Page.Img = ConvertToBytesEdit(file); if (TryUpdateModel(Page, "", new string[] { "Title", "Summary", "ShowSum", "Maintext", "Created", "MetaDescription", "MetaKeywords", "Publish", "AuthorId", "ImageId", "NavbarId", "SidenavId", "Img", "menuitems" })) { ; } } else { if (TryUpdateModel(Page, "", new string[] { "Title", "Summary", "ShowSum", "Maintext", "Created", "MetaDescription", "MetaKeywords", "Publish", "AuthorId", "ImageId", "NavbarId", "SidenavId", "menuitems" })) { ; } } db.Entry(Page).State = EntityState.Modified; int i = db.SaveChanges(); byte[] ConvertToBytesEdit(HttpPostedFileBase image) { byte[] imageBytes = null; var reader = new System.IO.BinaryReader(image.InputStream); imageBytes = reader.ReadBytes((int)image.ContentLength); return(imageBytes); } return(RedirectToAction("Index")); }
public ActionResult EditPost(int?id, ExtlinkViewModel model) { ViewBag.PageEdit = true; ViewBag.Class = "admin"; ViewBag.PdfPanelActive = "active"; ViewBag.Footer = false; if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var UrlItem = db.Extlinks.Find(id); if (UrlItem == null) { return(HttpNotFound()); } if (Request.Files["fileImg"] != null) { HttpPostedFileBase file = Request.Files["fileImg"]; UrlItem.Img = ConvertToBytes(file); if (TryUpdateModel(UrlItem, "", new string[] { "Title", "UrlLink", "Created", "Author", "ImageId", "NavbarId", "Img", "IsExternal" })) { ; } } else { if (TryUpdateModel(UrlItem, "", new string[] { "Title", "UrlLink", "Created", "Author", "ImageId", "NavbarId", "IsExternal", })) { ; } } db.Entry(UrlItem).State = EntityState.Modified; int i = db.SaveChanges(); byte[] ConvertToBytes(HttpPostedFileBase image) { byte[] imageBytes = null; var reader = new System.IO.BinaryReader(image.InputStream); imageBytes = reader.ReadBytes((int)image.ContentLength); return(imageBytes); } return(RedirectToAction("Index")); }
public ActionResult Index(MenugroupViewModel model, int?menutype, List <string> menugroups) { ViewBag.PageEdit = true; ViewBag.Class = "admin"; ViewBag.MenugroupPanelActive = "active"; int pagelistId = 0; int pdfId = 0; int elinkId = 0; int modalId = 0; int pageId = Convert.ToInt32(System.Web.HttpContext.Current.Request.Form["PageId"]); int menuId = Convert.ToInt32(System.Web.HttpContext.Current.Request.Form["menuid"]); int parentId = Convert.ToInt32(System.Web.HttpContext.Current.Request.Form["menuparent"]); int isExternal = Convert.ToInt32(System.Web.HttpContext.Current.Request.Form["ExLink"]); HttpPostedFileBase fileImg = Request.Files["fileImg"]; HttpPostedFileBase filePdf = Request.Files["filePdf"]; model.PageModel.Maintext = null; if (Request.Form["PageListId"] != "") { pagelistId = Convert.ToInt32(System.Web.HttpContext.Current.Request.Form["PageListId"]); } if (Request.Form["PdfId"] != "") { pdfId = Convert.ToInt32(System.Web.HttpContext.Current.Request.Form["PdfId"]); } if (Request.Form["ElinkId"] != "") { elinkId = Convert.ToInt32(System.Web.HttpContext.Current.Request.Form["ElinkId"]); } if (Request.Form["ModalId"] != "") { modalId = Convert.ToInt32(System.Web.HttpContext.Current.Request.Form["ModalId"]); } if (fileImg != null) { model.PageModel.Img = ConvertToBytes(fileImg); model.PdfModel.Img = ConvertToBytes(fileImg); model.ExtLinkModel.Img = ConvertToBytes(fileImg); } else { model.PageModel.Img = null; model.PdfModel.Img = null; model.ExtLinkModel.Img = null; } if (filePdf != null) { var PdfFile = filePdf; var PdfFileItem = Regex.Replace(PdfFile.FileName, " ", "-"); var fileName = System.IO.Path.GetFileName(PdfFileItem); var path = System.IO.Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~/Content/PdfFiles/"), fileName); PdfFile.SaveAs(path); model.PdfModel.FileName = PdfFileItem; } else { model.PdfModel.FileName = null; } switch (menutype) { case 26: HttpPostedFileBase SubModalFileImgSingle = Request.Files["ModalFileImg"]; var createsubmodalsingle = new ModalModel { Title = model.ModalModel.Title, Summary = model.ModalModel.Summary, Maintext = Request["ModalPanelContentSingle"], Icon = model.ModalModel.Icon, NavbarId = menuId, Img = ConvertToBytes(SubModalFileImgSingle), }; var submenumodalitemsingle = new Menugroup { Name = model.ModalModel.Title, IsParent = 0, ParentId = parentId, Type = 4, ModalId = modalId }; db.Menugroups.Add(submenumodalitemsingle); db.Modals.Add(createsubmodalsingle); break; case 27: HttpPostedFileBase SubModalFileImg = Request.Files["ModalFileImg"]; var createsubmodal = new ModalModel { Title = model.ModalModel.Title, Summary = model.ModalModel.Summary, Maintext = Request["ModalPanelContent"], Icon = model.ModalModel.Icon, NavbarId = menuId, Img = ConvertToBytes(SubModalFileImg), }; var submenumodalitem = new Menugroup { Name = model.ModalModel.Title, IsParent = 0, ParentId = parentId, Type = 4, ModalId = modalId }; db.Menugroups.Add(submenumodalitem); db.Modals.Add(createsubmodal); break; case 25: HttpPostedFileBase ModalFileImg = Request.Files["ModalFileImg"]; var createmodal = new ModalModel { Title = model.ModalModel.Title, Summary = model.ModalModel.Summary, Maintext = model.ModalModel.Maintext, NavbarId = menuId, Img = ConvertToBytes(ModalFileImg), }; var parentmenumodalitem = new Menugroup { Name = model.ModalModel.Title, IsParent = 1, Type = 4, ModalId = modalId }; db.Menugroups.Add(parentmenumodalitem); db.Modals.Add(createmodal); break; case 24: var editMenuSss = db.Menugroups.Find(menuId); editMenuSss.Name = Request["menuname"]; if (TryUpdateModel(editMenuSss, "", new string[] { "Name" })) { ; } db.Entry(editMenuSss).State = EntityState.Modified; break; case 21: var editMenuSs = db.Menugroups.Find(menuId); editMenuSs.Name = Request["menuname"]; if (TryUpdateModel(editMenuSs, "", new string[] { "Name" })) { ; } db.Entry(editMenuSs).State = EntityState.Modified; break; case 18: var editMenuS = db.Menugroups.Find(menuId); editMenuS.Name = Request["menuname"]; if (TryUpdateModel(editMenuS, "", new string[] { "Name" })) { ; } db.Entry(editMenuS).State = EntityState.Modified; break; case 15: var editMenuParent = db.Menugroups.Find(menuId); editMenuParent.Name = Request["menuname"]; if (TryUpdateModel(editMenuParent, "", new string[] { "Name" })) { ; } db.Entry(editMenuParent).State = EntityState.Modified; break; case 8: HttpPostedFileBase SubLinkFileImg = Request.Files["LinkFileImg"]; var sublinkitem = new ExtLinkModel { Title = model.ExtLinkModel.Title, UrlLink = model.ExtLinkModel.UrlLink, Created = model.ExtLinkModel.Created, Img = ConvertToBytes(SubLinkFileImg), Icon = model.ExtLinkModel.Icon, IsExternal = model.ExtLinkModel.IsExternal, NavbarId = menuId }; var submenulinkitem = new Menugroup { Name = model.ExtLinkModel.Title, IsParent = 0, ParentId = parentId, Type = 3, ExtlinkId = elinkId }; db.Menugroups.Add(submenulinkitem); db.Extlinks.Add(sublinkitem); break; case 7: var subpdfitem = new PdfModel { Title = model.PdfModel.Title, Summary = model.PdfModel.Summary, Created = model.PdfModel.Created, Img = model.PdfModel.Img, FileName = model.PdfModel.FileName, IsExternal = model.PdfModel.IsExternal, NavbarId = menuId, ExLink = model.PdfModel.ExLink }; var submenupdfitem = new Menugroup { Name = model.PdfModel.Title, IsParent = 0, ParentId = parentId, Type = 2, PdfId = pdfId }; db.Menugroups.Add(submenupdfitem); db.Pdfs.Add(subpdfitem); break; case 6: var dataImg = Request.Form["PageImg"]; if (dataImg == "ni") { var subpageitem = new PageModel { Title = model.PageModel.Title, Summary = model.PageModel.Summary, Maintext = model.PageModel.Maintext, Created = model.PageModel.Created, MetaDescription = model.PageModel.MetaDescription, MetaKeywords = model.PageModel.MetaKeywords, Publish = model.PageModel.Publish, AuthorId = model.PageModel.AuthorId, ImageId = model.PageModel.ImageId, NavbarId = model.PageModel.NavbarId, SidenavId = menuId, Icon = model.PageModel.Icon, SubContent = Request["subcontent"], PageUrl = model.PageModel.PageUrl, menuitems = model.PageModel.menuitems }; var submenuitem = new Menugroup { Name = model.PageModel.Title, IsParent = 0, ParentId = parentId, Type = 1, PageId = pageId }; db.Menugroups.Add(submenuitem); db.Pages.Add(subpageitem); } else { var subpageitem = new PageModel { Title = model.PageModel.Title, Summary = model.PageModel.Summary, Maintext = model.PageModel.Maintext, Created = model.PageModel.Created, MetaDescription = model.PageModel.MetaDescription, MetaKeywords = model.PageModel.MetaKeywords, Publish = model.PageModel.Publish, AuthorId = model.PageModel.AuthorId, ImageId = model.PageModel.ImageId, NavbarId = model.PageModel.NavbarId, SidenavId = menuId, Img = model.PageModel.Img, Icon = model.PageModel.Icon, SubContent = Request["subcontent"], PageUrl = model.PageModel.PageUrl, menuitems = model.PageModel.menuitems }; var submenuitem = new Menugroup { Name = model.PageModel.Title, IsParent = 0, ParentId = parentId, Type = 1, PageId = pageId }; db.Menugroups.Add(submenuitem); db.Pages.Add(subpageitem); } break; case 5: HttpPostedFileBase LinkFileImg = Request.Files["LinkFileImg"]; var createlink = new ExtLinkModel { Title = model.ExtLinkModel.Title, UrlLink = model.ExtLinkModel.UrlLink, Created = model.ExtLinkModel.Created, Img = ConvertToBytes(LinkFileImg), IsExternal = model.ExtLinkModel.IsExternal }; var parentmenulinkitem = new Menugroup { Name = model.ExtLinkModel.Title, IsParent = 1, Type = 3, ExtlinkId = elinkId }; db.Menugroups.Add(parentmenulinkitem); db.Extlinks.Add(createlink); break; case 4: var createpdf = new PdfModel { Title = model.PdfModel.Title, Summary = model.PdfModel.Summary, Created = model.PdfModel.Created, Img = model.PdfModel.Img, FileName = model.PdfModel.FileName, IsExternal = model.PdfModel.IsExternal, ExLink = model.PdfModel.ExLink }; var parentmenupdfitem = new Menugroup { Name = model.PdfModel.Title, IsParent = 1, Type = 2, PdfId = pdfId }; db.Menugroups.Add(parentmenupdfitem); db.Pdfs.Add(createpdf); break; case 3: var createpage = new PageModel { Title = model.PageModel.Title, Summary = model.PageModel.Summary, Maintext = model.PageModel.Maintext, Created = model.PageModel.Created, MetaDescription = model.PageModel.MetaDescription, MetaKeywords = model.PageModel.MetaKeywords, Publish = model.PageModel.Publish, AuthorId = model.PageModel.AuthorId, ImageId = model.PageModel.ImageId, NavbarId = model.PageModel.NavbarId, SidenavId = menuId, Img = model.PageModel.Img, SubContent = Request["subcontent"], PageUrl = model.PageModel.PageUrl, menuitems = model.PageModel.menuitems }; var parentmenuitem = new Menugroup { Name = model.PageModel.Title, IsParent = 1, Type = 1, PageId = pageId }; db.Menugroups.Add(parentmenuitem); db.Pages.Add(createpage); break; case 2: var firstchild = new Menugroup { Name = model.Name, IsParent = 0, ParentId = parentId, Type = 1, PageId = pagelistId }; db.Menugroups.Add(firstchild); break; case 1: var parent = new Menugroup { Name = model.Name, IsParent = 1, Type = 1, PageId = pagelistId }; db.Menugroups.Add(parent); break; default: var parentmenu = new Menugroup { Name = model.Name, IsParent = 1, Type = 1, PageId = pageId }; db.Menugroups.Add(parentmenu); break; } int i = db.SaveChanges(); if (i == 1) { return(RedirectToAction("Index")); } return(RedirectToAction("Index")); }