Exemplo n.º 1
0
        public JsonResult AddAndEdit(SubMenuActionModel model)
        {
            JsonResult json = new JsonResult();

            var result = false;

            List <int> pictureIDs = !string.IsNullOrEmpty(model.PictureIDs) ? model.PictureIDs.Split(',').Select(x => int.Parse(x)).ToList() : new List <int>();

            var pictures = sharedServices.GetPictureByIDs(pictureIDs);

            if (ModelState.IsValid)
            {
                if (model.SubMenuID > 0)
                {
                    var subMenu = subServices.GetSubMenuByID(model.SubMenuID);

                    subMenu.MainMenuID  = model.MainMenuID;
                    subMenu.SubMenuName = model.SubMenuName;
                    subMenu.Description = model.Description;
                    subMenu.UpdatedAt   = DateTime.Now;

                    subMenu.SubMenuPictures.Clear();
                    subMenu.SubMenuPictures.AddRange(pictures.Select(x => new SubMenuPicture()
                    {
                        SubMenuID = subMenu.SubMenuID, PictureID = x.PictureID
                    }));

                    result = subServices.UpdateSubMenu(subMenu);
                }
                else
                {
                    SubMenu subMenu = new SubMenu();

                    subMenu.MainMenuID  = model.MainMenuID;
                    subMenu.SubMenuName = model.SubMenuName;
                    subMenu.Description = model.Description;
                    subMenu.UpdatedAt   = DateTime.Now;

                    subMenu.SubMenuPictures = new List <SubMenuPicture>();
                    subMenu.SubMenuPictures.AddRange(pictures.Select(x => new SubMenuPicture()
                    {
                        PictureID = x.PictureID
                    }));

                    result = subServices.SaveSubMenu(subMenu);
                }
            }
            if (result)
            {
                json.Data = new { Success = true };
            }
            else
            {
                json.Data = new { Success = false, Message = "Unable to perform any action" };
            }

            return(json);
        }
Exemplo n.º 2
0
        public ActionResult Delete(int ID)
        {
            SubMenuActionModel model = new SubMenuActionModel();

            var subMenu = subServices.GetSubMenuByID(ID);

            model.SubMenuID = subMenu.SubMenuID;

            return(PartialView("_Delete", model));
        }
Exemplo n.º 3
0
        public ActionResult AddAndEdit(int?ID)
        {
            SubMenuActionModel model = new SubMenuActionModel();

            if (ID.HasValue)
            {
                var subMenu = subServices.GetSubMenuByID(ID.Value);

                model.SubMenuID   = subMenu.SubMenuID;
                model.MainMenuID  = subMenu.MainMenuID;
                model.SubMenuName = subMenu.SubMenuName;
                model.Description = subMenu.Description;

                model.SubMenuPictures = subServices.GetPictureBySubMneID(subMenu.SubMenuID);
            }
            model.MainMenus = mainServices.GetAllMainMenus();

            return(PartialView("_AddAndEdit", model));
        }
Exemplo n.º 4
0
        public JsonResult Delete(SubMenuActionModel model)
        {
            JsonResult json = new JsonResult();

            var result = false;

            var subMenu = subServices.GetSubMenuByID(model.SubMenuID);

            result = subServices.DeleteSubMenu(subMenu);

            if (result)
            {
                json.Data = new { Success = true };
            }
            else
            {
                json.Data = new { Success = false, Message = "Unable to perform any action" };
            }

            return(json);
        }