public static void UpdatePostIt(Model.PostIt postIt) { using (PostItContext context = CreateContext()) { context.PostIts.Update(postIt); context.SaveChanges(); } }
public static void AddCategories(Category category) { using (PostItContext context = CreateContext()) { context.Categories.Add(category); context.SaveChanges(); } }
public static void DeletePostIt(Model.PostIt postIt) { using (PostItContext context = CreateContext()) { postIt.Category.PostIts.Remove(postIt); context.PostIts.Remove(postIt); context.SaveChanges(); } }
public static void ChangePostItCategory(Model.PostIt model, Category category) { using (PostItContext context = CreateContext()) { var postIt = context.PostIts.FirstOrDefault(p => p.Id == model.Id); int indexPostit = model.Category.PostIts.IndexOf(model); model.Category.PostIts.RemoveAt(indexPostit); var newCategory = context.Categories.FirstOrDefault(c => c.Id == category.Id); model.Category = category; model.CategoryId = category.Id; postIt.Category = category; postIt.CategoryId = category.Id; context.PostIts.Update(postIt); category.PostIts.Add(model); context.SaveChanges(); } }
public static void CreatePostIt(string text, Category category, Color color) { if (category == null) { throw new Exception("Please add a category"); } using (PostItContext context = CreateContext()) { Model.PostIt postIt = new Model.PostIt() { Text = text, Category = category, CategoryId = category.Id, ColorArgb = color.ToArgb() }; var dbCategory = context.Categories.Include(c => c.PostIts).First(c => c.Id == category.Id); dbCategory.PostIts.Add(postIt); context.SaveChanges(); postIt.Category = category; category.PostIts.Add(postIt); } }