public User GetUser(int Id) { using (APShopContext context = new APShopContext()) { UnitOfWork UoW = new UnitOfWork(context); EntityModels.Users efUser = UoW.User.GetById(Id); if (efUser == null) { return(null); } DTOs.User user = _mapper.Map <DTOs.User>(efUser); return(user); } }
public int RegisterUser(DTOs.User loginUser, DateTime lastUpdated) { //if (loginUser == null) //{ // throw new ArgumentNullException(); //} //using (APShopContext context = new APShopContext()) //{ // UnitOfWork UoW = new UnitOfWork(context); // EntityModels.Users user = _mapper.Map<EntityModels.Users>(loginUser); // UoW.User.Register(user); // EntityModels.Cart cart = new EntityModels.Cart(); // user.Cart.Add(cart); // UoW.commit(); // return user.Id; if (loginUser == null) { throw new ArgumentNullException("User info was not provided!"); } using (APShopContext context = new APShopContext()) { UnitOfWork uow = new UnitOfWork(context); EntityModels.Users user = _mapper.Map <EntityModels.Users>(loginUser); uow.User.Register(user); //uow.commit(); // Creating, mapping and adding the cart to the user EntityModels.Cart cart = new EntityModels.Cart() { DateLastUpdated = lastUpdated }; user.Cart.Add(cart); //context.Cart.Add(cart); uow.commit(); return(user.Id); } }