public void CreateNewUser(DTOs.User user) { usersWebService.User us = new usersWebService.User(); us.ID = (int)user.ID; us.Name = user.Name; us.Email = user.Email; context.User.Add(us); }
public DTOs.User GetByEmail(string email) { var data = context.User.ToList(); DTOs.User user = data.Where(u => u.Email == email).Select(u => new DTOs.User ( ID: u.ID, Name: u.Name, Email: u.Email )).FirstOrDefault(); return(user); }
public DTOs.User GetById(int id) { var data = context.Admin.ToList(); DTOs.User user = data.Where(u => u.ID == id).Select(u => new DTOs.User { ID = u.ID, Name = u.Name, Email = u.Email }).FirstOrDefault(); return(user); }
public void UpdateUser(DTOs.User user, int ID) { DTOs.User use = GetById(ID); usersWebService.User us = new usersWebService.User(); us.ID = (int)use.ID; context.User.Remove(us); us.ID = user.ID; us.Name = user.Name; us.Email = user.Email; context.User.Add(us); // context.Entry(user).State = EntityState.Modified; Save(); }
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); } }
public IActionResult Register([FromBody] DTOs.User user) { if (user == null) { return(BadRequest("User info was not provided!")); } int result = 0; try { var currentDate = DateTime.Now; result = _usermenager.RegisterUser(user, currentDate); } catch (ArgumentNullException) { BadRequest("NoUser"); } return(Ok("Succesfull registration " + result)); }
public IActionResult GetById(int userId) { DTOs.User user = _usermenager.GetUser(userId); return(Ok(user)); }