public void Delete(ReactCategoryModel item) { Server s = Server.Instance(); Database react = new Database("react", s); Collection <ReactCategoryModel> category = new Collection <ReactCategoryModel>("category", react); var data = item; if (data.Roles != null) { foreach (int i in data.Roles) { new ReactRole().Delete(new ReactRole().Find(x => x.Id == i)); } } var channel = new ReactChannel().Find(x => x.DiscordID == data.ChannelId); channel.Categories.Remove(data.Id); new ReactChannel().Update(x => x.Id == channel.Id, channel); category.DeleteDocument(x => x.Id == data.Id); }
public void Insert(ReactCategoryModel item) { Server s = Server.Instance(); Database react = new Database("react", s); Collection <ReactCategoryModel> category = new Collection <ReactCategoryModel>("category", react); int id = GetLastId(); id++; if (item.ChannelId != 0) { var channel = new ReactChannel().Find(x => x.DiscordID == item.ChannelId); if (channel.Categories == null) { channel.Categories = new List <int>(); } channel.Categories.Add(id); new ReactChannel().Update(x => x.Id == channel.Id, channel); item.Id = id; category.InsertDocument(item); } }