public APIReturn _Add([FromForm] string Name, [FromForm] uint?Total_news, [FromForm] uint[] mn_News) { NewstagInfo item = new NewstagInfo(); item.Create_time = DateTime.Now; item.Name = Name; item.Total_news = Total_news; item = Newstag.Insert(item); //关联 News foreach (uint mn_News_in in mn_News) { item.FlagNews(mn_News_in); } return(APIReturn.成功.SetData("item", item.ToBson())); }
public APIReturn _Edit([FromQuery] uint Id, [FromForm] string Name, [FromForm] uint?Total_news, [FromForm] uint[] mn_News) { NewstagInfo item = Newstag.GetItem(Id); if (item == null) { return(APIReturn.记录不存在_或者没有权限); } item.Create_time = DateTime.Now; item.Name = Name; item.Total_news = Total_news; int affrows = Newstag.Update(item); //关联 News if (mn_News.Length == 0) { item.UnflagNewsALL(); } else { List <uint> mn_News_list = mn_News.ToList(); foreach (var Obj_news in item.Obj_newss) { int idx = mn_News_list.FindIndex(a => a == Obj_news.Id); if (idx == -1) { item.UnflagNews(Obj_news.Id); } else { mn_News_list.RemoveAt(idx); } } mn_News_list.ForEach(a => item.FlagNews(a)); } if (affrows > 0) { return(APIReturn.成功.SetMessage($"更新成功,影响行数:{affrows}")); } return(APIReturn.失败); }