示例#1
0
        public void CreateMenuTest()
        {
            var client = ApiClient.GetInstance("tag");
            var method = new MenuCreate()
            {
                Menu = new Menu()
                {
                    Buttons = new List <BaseMenu>()
                    {
                        new ClickButton()
                        {
                            Name = "查询说明", Key = "Help"
                        },
                        //new ViewButton(){Name="百度", Url="http://www.baidu.com"},
                        //new SubMenus(){ Name = "abc", SubButtons = new List<ButtonMenu>(){
                        //    new ClickButton(){Name="A", Key = "A"},
                        //    new ClickButton(){Name="B", Key="B"},
                        //    new ClickButton(){Name="C", Key="C"}
                        //}}
                    }
                }
            };

            var data = client.Execute(method);
        }
示例#2
0
        public IHttpActionResult CreateMenu(MenuCreate menu)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            MenuService service = CreatedMenuService();

            service.CreateMenu(menu);

            return(Ok());
        }
示例#3
0
 public ActionResult CreateMenuCategory(MenuCreate model)
 {
     if (!ModelState.IsValid)
     {
         return(View());
     }
     else
     {
         tbl_menu_category tbl = new tbl_menu_category();
         tbl.MenuOrder    = model.MenuOrder;
         tbl.CategoryName = model.CategoryName;
         db.tbl_menu_category.Add(tbl);
         db.SaveChanges();
     }
     return(RedirectToAction("ListMenuItem", "Menu"));
 }
示例#4
0
        // POST
        public bool CreateMenu(MenuCreate model)
        {
            var entity =
                new Menu()
            {
                ShopId  = model.ShopId,
                Name    = model.Name,
                OwnerId = _userId
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Menus.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
示例#5
0
        public bool CreateMenu(MenuCreate model)
        {
            var entity =
                new Menu()
            {
                Name         = model.Name,
                Price        = model.Price,
                Description  = model.Description,
                RestaurantId = model.RestaurantId
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Menu.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
示例#6
0
文件: UnitTest1.cs 项目: andyshao/WX
        public void CreateMenuTest()
        {
            var client = ApiClient.GetInstance("tag");
            var method = new MenuCreate() {
                Menu = new Menu() {
                    Buttons = new List<BaseMenu>() {
                        new ClickButton(){ Name = "查询说明",Key = "Help"},
                        //new ViewButton(){Name="百度", Url="http://www.baidu.com"},
                        //new SubMenus(){ Name = "abc", SubButtons = new List<ButtonMenu>(){
                        //    new ClickButton(){Name="A", Key = "A"},
                        //    new ClickButton(){Name="B", Key="B"},
                        //    new ClickButton(){Name="C", Key="C"}
                        //}}
                    }
                }
            };

            var data = client.Execute(method);
        }
示例#7
0
        public async Task <bool> CreateMenuAsync(MenuCreate model)
        {
            var entity =
                new Menu()
            {
                // OwnerID = _userId,

                Name         = model.Name,
                Price        = model.Price,
                Description  = model.Description,
                RestaurantId = model.RestaurantId
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Menu.Add(entity);
                return(await ctx.SaveChangesAsync() == 1);
            }
        }
示例#8
0
        public async Task <ActionResult> Create(MenuCreate note)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.RestaurantId = await GetRestaurantAsync();

                return(View(note));
            }

            var service = CreateMenuService();

            if (await service.CreateMenuAsync(note))
            {
                TempData["SaveResult"] = "Your Menu was created.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Menu could not be created.");
            ViewBag.RestaurantId = await GetRestaurantAsync();


            return(View(note));
        }
        public JsonResult CreateMenu(MenuCreate model)
        {
            using (var db = new ProjectWebEntities())
            {
                try
                {
                    var code = 0;
                    //Check Null cho list Children
                    if (model.MenuChildren == null)
                    {
                        model.MenuChildren = new List <MenuChild>();
                    }
                    if (model.Id == 0)
                    {
                        var parent = new Tbl_MenuMultiLevel();
                        parent.Menu = model.MenuName;
                        parent.Url  = model.MenuUrl;
                        db.Tbl_MenuMultiLevel.Add(parent);
                        foreach (var item in model.MenuChildren)
                        {
                            code++;
                            if (item.Id == 0)
                            {
                                var child = new Tbl_MenuMultiLevel();
                                child.Menu        = item.ChildName;
                                child.PageId      = item.PageId;
                                child.Url         = item.Url;
                                child.ParentId    = parent.MenuId;
                                child.PageChildId = item.PageChildId;
                                child.MenuCode    = code;
                                db.Tbl_MenuMultiLevel.Add(child);
                            }
                            else
                            {
                                var child = db.Tbl_MenuMultiLevel.Find(item.Id);
                                child.Menu            = item.ChildName;
                                child.PageId          = item.PageId;
                                child.MenuCode        = code;
                                child.PageChildId     = item.PageChildId;
                                child.Url             = item.Url;
                                db.Entry(child).State = EntityState.Modified;
                            }
                        }
                        db.SaveChanges();
                    }
                    else
                    {
                        var parent = db.Tbl_MenuMultiLevel.Find(model.Id);
                        parent.Menu            = model.MenuName;
                        parent.Url             = model.MenuUrl;
                        db.Entry(parent).State = EntityState.Modified;
                        var lstRemove = parent.Tbl_MenuMultiLevel1.ToList();

                        foreach (var item in model.MenuChildren)
                        {
                            code++;
                            if (item.Id == 0)
                            {
                                var child = new Tbl_MenuMultiLevel();
                                child.Menu        = item.ChildName;
                                child.MenuCode    = code;
                                child.PageId      = item.PageId;
                                child.Url         = item.Url;
                                child.ParentId    = parent.MenuId;
                                child.PageChildId = item.PageChildId;
                                db.Tbl_MenuMultiLevel.Add(child);
                            }
                            else
                            {
                                var child = db.Tbl_MenuMultiLevel.Find(item.Id);
                                child.MenuCode        = code;
                                child.Menu            = item.ChildName;
                                child.PageId          = item.PageId;
                                child.PageChildId     = item.PageChildId;
                                child.Url             = item.Url;
                                db.Entry(child).State = EntityState.Modified;
                                //remove
                                lstRemove.Remove(child);
                            }
                        }
                        if (lstRemove.Any())
                        {
                            foreach (var item in lstRemove)
                            {
                                db.Entry(item).State = EntityState.Deleted;
                            }
                        }

                        db.SaveChanges();
                    }
                    //Xóa cache
                    CacheHelper.ClearAllOutputCache();
                    return(Json(JsonRequestBehavior.AllowGet));
                }
                catch (Exception ex)
                {
                    TempData["ThanhCong"] = "Có lỗi xảy ra ! <br/> Xin vui lòng thử lại hoặc liên hệ Admin";
                    logger.Error("An Error Happened! ", ex);
                    return(Json(ex, JsonRequestBehavior.DenyGet));
                }
            }
        }