public static bool UserLogin(string username, string password) { using (var context = new MuffinContext()) { var issetUser = context.User.Any(user => user.username.ToLower() == username); if (!issetUser) { throw new UserNotFoundException(); } else { var user = context.User.Where(u => u.username.ToLower() == username.ToLower()).First(); if (user.password != password) { throw new IncorrectPasswordException(); } else { UIRepository.Instance.CurrentClientID = user.user_id; UIRepository.Instance.LoggedInUser = user; UIRepository.Instance.UserCart = new Cart(); return(true); } } } }
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 bool hasEmail(string email) { using (var context = new MuffinContext()) { var hasEmail = context.User.Any(u => u.email.ToLower() == email.ToLower()); return(hasEmail); } }
public static bool hasUsername(string username) { using (var context = new MuffinContext()) { var hasUser = context.User.Any(u => u.username.ToLower() == username.ToLower()); return(hasUser); } }
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 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 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 MuffinService(MuffinContext context) { _context = context; }
public MuffinsController(MuffinContext context) { _context = context; }