public int EditCake(Model.Cake model) { int result; Cake cake; using (ApplicationDbContext db = new ApplicationDbContext()) { cake = db.Cakes.FirstOrDefault(x => x.CakeId == model.CakeId); cake.Title = model.Title; cake.Remarks = model.Remarks; result = db.SaveChanges(); } return(result); }
public int AddCake(Model.Cake model) { int result; using (ApplicationDbContext db = new ApplicationDbContext()) { //check if a record already exists Cake cake = db.Cakes.Where(x => x.Title.ToLower() == model.Title.ToLower()).First(); if (cake != null) { result = 0; } else { db.Cakes.Add(model); result = db.SaveChanges(); } } return(result); }