예제 #1
0
        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"));
        }
예제 #2
0
        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 30:
                if (menugroups[0] != null)
                {
                    string   v      = menugroups[0].ToString();
                    string[] values = v.Split(',');
                    for (int mi = 0; mi < values.Length; mi++)
                    {
                        string   vi         = values[mi];
                        string[] valueItems = vi.Split('-');
                        //var test = new Menugroup
                        //{
                        //    Name = valueItems[0],
                        //    IsParent = 0,
                        //    ParentId = null,
                        //    Type = 4,
                        //    ModalId = null
                        //};
                        //db.Menugroups.Add(test);

                        //var MenuItemUpdate = db.Menugroups.Find(Convert.ToInt32(valueItems[0]));
                        //if (TryUpdateModel(MenuItemUpdate, "", new string[] { "ParentId", "Order"})) ;
                        //db.Entry(MenuItemUpdate).State = EntityState.Modified;
                    }
                }

                break;

            case 27:
                HttpPostedFileBase SSubModalFileImg = Request.Files["ModalFileImg"];
                var createssubmodal = new ModalModel
                {
                    Title    = model.ModalModel.Title,
                    Summary  = model.ModalModel.Summary,
                    Maintext = model.ModalModel.Maintext,
                    NavbarId = menuId,
                    Img      = ConvertToBytes(SSubModalFileImg),
                };
                var ssubmenumodalitem = new Menugroup
                {
                    Name     = model.ModalModel.Title,
                    IsParent = 0,
                    ParentId = parentId,
                    Type     = 4,
                    ModalId  = modalId
                };
                db.Menugroups.Add(ssubmenumodalitem);
                db.Modals.Add(createssubmodal);
                break;

            case 26:
                HttpPostedFileBase SubModalFileImg = Request.Files["ModalFileImg"];
                var createsubmodal = new ModalModel
                {
                    Title    = model.ModalModel.Title,
                    Summary  = model.ModalModel.Summary,
                    Maintext = model.ModalModel.Maintext,
                    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),
                    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 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,
                    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"));
        }