Exemple #1
0
        public APIReturn _Add([FromForm] uint?Parent_id, [FromForm] string Name, [FromForm] uint[] mn_Category)
        {
            AreaInfo item = new AreaInfo();

            item.Parent_id = Parent_id;
            item.Name      = Name;
            item           = Area.Insert(item);
            //关联 Category
            foreach (uint mn_Category_in in mn_Category)
            {
                item.FlagCategory(mn_Category_in);
            }
            return(APIReturn.成功.SetData("item", item.ToBson()));
        }
Exemple #2
0
        public APIReturn _Edit([FromQuery] uint Id, [FromForm] uint?Parent_id, [FromForm] string Name, [FromForm] uint[] mn_Category)
        {
            AreaInfo item = Area.GetItem(Id);

            if (item == null)
            {
                return(APIReturn.记录不存在_或者没有权限);
            }
            item.Parent_id = Parent_id;
            item.Name      = Name;
            int affrows = Area.Update(item);

            //关联 Category
            if (mn_Category.Length == 0)
            {
                item.UnflagCategoryALL();
            }
            else
            {
                List <uint> mn_Category_list = mn_Category.ToList();
                foreach (var Obj_category in item.Obj_categorys)
                {
                    int idx = mn_Category_list.FindIndex(a => a == Obj_category.Id);
                    if (idx == -1)
                    {
                        item.UnflagCategory(Obj_category.Id);
                    }
                    else
                    {
                        mn_Category_list.RemoveAt(idx);
                    }
                }
                mn_Category_list.ForEach(a => item.FlagCategory(a));
            }
            if (affrows > 0)
            {
                return(APIReturn.成功.SetMessage($"更新成功,影响行数:{affrows}"));
            }
            return(APIReturn.失败);
        }