/// <summary>
        /// 保持菜单
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <ActionResult> Save(MenuCommand model)
        {
            if (string.IsNullOrEmpty(model.Icon) || !model.Icon.Contains("/"))
            {
                model.Icon = null;
            }
            var m = await MenuService.GetByIdAsync(model.Id);

            if (m == null)
            {
                return(await MenuService.AddEntitySavedAsync(model.Mapper <Menu>()) > 0 ? ResultData(model, true, "添加成功") : ResultData(null, false, "添加失败"));
            }

            Mapper.Map(model, m);
            bool b = await MenuService.SaveChangesAsync() > 0;

            return(ResultData(null, b, b ? "修改成功" : "修改失败"));
        }
        /// <summary>
        /// 保持菜单
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ActionResult Save(MenuCommand model)
        {
            if (string.IsNullOrEmpty(model.Icon) || !model.Icon.Contains("/"))
            {
                model.Icon = null;
            }
            var m = MenuService.GetById(model.Id);

            if (m == null)
            {
                var menu = MenuService.AddEntitySaved(model.Mapper <Menu>());
                return(menu != null?ResultData(menu, true, "添加成功") : ResultData(null, false, "添加失败"));
            }

            Mapper.Map(model, m);
            bool b = MenuService.SaveChanges() > 0;

            return(ResultData(null, b, b ? "修改成功" : "修改失败"));
        }
Exemple #3
0
        /// <summary>
        /// 保持菜单
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <ActionResult> Save([FromBodyOrDefault] MenuCommand model)
        {
            if (string.IsNullOrEmpty(model.Icon) || !model.Icon.Contains("/"))
            {
                model.Icon = null;
            }
            var m = await MenuService.GetByIdAsync(model.Id);

            if (m == null)
            {
                var menu = model.Mapper <Menu>();
                menu.Path = model.ParentId > 0 ? (MenuService[model.ParentId.Value].Path + "," + model.ParentId).Trim(',') : SnowFlake.NewId;
                return(await MenuService.AddEntitySavedAsync(menu) > 0 ? ResultData(model, true, "添加成功") : ResultData(null, false, "添加失败"));
            }

            Mapper.Map(model, m);
            m.Path = model.ParentId > 0 ? (MenuService[model.ParentId.Value].Path + "," + model.ParentId).Trim(',') : SnowFlake.NewId;
            bool b = await MenuService.SaveChangesAsync() > 0;

            return(ResultData(null, b, b ? "修改成功" : "修改失败"));
        }