Ejemplo n.º 1
0
        public JsonResult EditMenu(Menu menu)
        {
            if (menu == null)
            {
                return(Json(ErrorModel.InputError));
            }

            var bll     = new MenuBll();
            var success = menu.Id > 0 ? bll.Update(menu) : bll.Insert(menu).Id > 0;

            return(Json(success ? ErrorModel.GetDataSuccess(menu) : ErrorModel.OperateFailed));
        }
Ejemplo n.º 2
0
        public JsonResult Edit(Menu model)
        {
            if (model.Id == 0)
            {
                model.CDate    = TypeConvert.DateTimeToInt(DateTime.Now);
                model.HasChild = false;
            }
            var apiResult = new APIResult();

            try
            {
                if (model.Id == 0)
                {
                    model.Id = IdBuilder.NextLongID();
                    MenuBll.Insert(model);
                    //保存菜单按钮
                    if (!string.IsNullOrWhiteSpace(model.BtnNames))
                    {
                        string[] btnIdArr = model.BtnNames.Split(',');
                        if (btnIdArr.Length > 0)
                        {
                            foreach (var btnIdStr in btnIdArr)
                            {
                                long btnId = 0;
                                if (long.TryParse(btnIdStr, out btnId))
                                {
                                    var menuFuncBtn = new MenuFuncBtn()
                                    {
                                        Id        = IdBuilder.NextLongID(),
                                        MenuId    = model.Id,
                                        FuncBtnId = btnId,
                                        CDate     = TypeConvert.DateTimeToInt(DateTime.Now)
                                    };
                                    MenuFuncBtnBll.AddOrUpdate(menuFuncBtn);
                                }
                            }
                        }
                    }
                }

                else
                {
                    MenuBll.Update(model);
                    //删除菜单按钮
                    MenuFuncBtnBll.Delete(model.Id);
                    //保存菜单按钮
                    if (!string.IsNullOrWhiteSpace(model.BtnNames))
                    {
                        string[] btnIdArr = model.BtnNames.Split(',');
                        if (btnIdArr.Length > 0)
                        {
                            foreach (var btnIdStr in btnIdArr)
                            {
                                long btnId = 0;
                                if (long.TryParse(btnIdStr, out btnId))
                                {
                                    var menuFuncBtn = new MenuFuncBtn()
                                    {
                                        Id        = IdBuilder.NextLongID(),
                                        MenuId    = model.Id,
                                        FuncBtnId = btnId,
                                        CDate     = TypeConvert.DateTimeToInt(DateTime.Now)
                                    };
                                    MenuFuncBtnBll.AddOrUpdate(menuFuncBtn);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                apiResult.Ret = -1;
                apiResult.Msg = ex.Message;
                if (!(ex is OperationExceptionFacade))
                {
                    LogFactory.GetLogger().Log(LogLevel.Error, ex);
                }
            }

            return(Json(apiResult));
        }