public static void RegisterUser(string username, string password, string repassword, string email) { using (var context = new MuffinContext()) { if (hasUsername(username)) { throw new UsernameExistsException(); } if (hasEmail(email)) { throw new EmailExistsException(); } if (password == repassword) { User newUser = new User(); newUser.username = username; newUser.password = password; newUser.email = email; context.User.Add(newUser); context.SaveChanges(); } else { throw new PasswordsNotMatchException(); } } }
public static void DeleteMuffin(int id) { using (var context = new MuffinContext()) { Muffin deleteMuffin = context.Muffin.Find(id); context.Muffin.Remove(deleteMuffin); context.SaveChanges(); } }
public static void AddMuffin(string muffin_name, decimal muffin_price) { using (var context = new MuffinContext()) { Muffin newMuffin = new Muffin(); newMuffin.muffin_name = muffin_name; newMuffin.muffin_price = muffin_price; context.Muffin.Add(newMuffin); context.SaveChanges(); } }
public static void ModifyMuffin(int muffin_id, string muffin_name, decimal muffin_price) { using (var context = new MuffinContext()) { Muffin modifyMuffin = context.Muffin.Find(muffin_id); modifyMuffin.muffin_name = muffin_name; modifyMuffin.muffin_price = muffin_price; context.Entry(modifyMuffin).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } }
public void CreateMuffin(Muffin muffin) { //do some work business stuff _context.Muffins.Add(muffin); _context.SaveChanges(); }