public void CreateEdition(EditionEdit edition) { Edition new_edition = new Edition() { Name = edition.Name, Price = edition.Price }; Db.Editions.Create(new_edition); using (var db = new PeriodicalContext()) { var existedEdition = db.Editions.Where(e => e.Name == new_edition.Name).FirstOrDefault(); var category = db.Categories.Where(c => c.Name == edition.CategoryName).FirstOrDefault(); existedEdition.Category = category; category.Editions.Add(existedEdition); db.SaveChanges(); } }
public void EditEdition(EditionEdit edition) { DeleteEdition(edition.EditionId); CreateEdition(edition); }