public NewstagInfo Save() { if (this.Id != null) { Newstag.Update(this); return(this); } this.Create_time = DateTime.Now; return(Newstag.Insert(this)); }
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.失败); }