public User GetUser(int id) { using (EF.APShopContext context = new EF.APShopContext()) { UnitOfWork uow = new UnitOfWork(context); //EF.User efUser = uow.Users.GetAll().FirstOrDefault(); EF.User efUser = uow.Users.GetById(id); if (efUser is null) { return(null); } User user = new User() { Id = efUser.Id, Username = efUser.Username, Password = efUser.Password, Role = efUser.Role }; return(user); } }
public User UserLogin(string username, string passwordHash) { using (EF.APShopContext context = new EF.APShopContext()) { UnitOfWork uow = new UnitOfWork(context); EF.User efUser = uow.Users.GetByUsernameAndPassword(username, passwordHash); if (efUser is null) { return(null); } User user = _mapper.Map <User>(efUser); return(user); } }
public static void PostUser(User userDBO) { using (EF.APShopContext context = new EF.APShopContext()) { UnitOfWork uow = new UnitOfWork(context); EF.User efUser = new EF.User() { Username = userDBO.Username, Password = userDBO.Password, Role = userDBO.Role }; uow.Users.Add(efUser); context.SaveChanges(); } }
public int Register(User user, DateTime cartDate) { if (user == null) { throw new ArgumentNullException("User info not supplied"); } using (EF.APShopContext context = new EF.APShopContext()) { UnitOfWork uow = new UnitOfWork(context); EF.User dboUser = _mapper.Map <EF.User>(user); uow.Users.CreateUser(dboUser); EF.Cart dbCart = new EF.Cart() { DateLastUpdated = cartDate }; dboUser.Cart.Add(dbCart); //virtuelni clan uow.Commit(); return(dboUser.Id); } }