public async Task <IdentityResult> AssignCustomer(FrontCustomer frontCustomer, string userId) { var user = _userManager.Users.SingleOrDefault(u => u.Id == userId); if (user != null && user.Customer_Id == null) { Customer customer = new Customer() { Address = frontCustomer.Address, Name = frontCustomer.Name, Code = "0" }; if (customer.Address != null && customer.Name != null) { await _context.Customers.AddAsync(customer); await _context.SaveChangesAsync(); customer = _context.Customers.Last(); customer.Code = string.Format("{0:0000}", customer.Id) + "-" + DateTime.Now.Year.ToString(); _context.Customers.Update(customer); await _context.SaveChangesAsync(); user.Customer_Id = customer.Id; return(await _userManager.UpdateAsync(user)); } } return(new IdentityResult()); }
public bool CreateCustomer(FrontCustomer frontCustomer, string userId) { Customer customer = new Customer() { Name = frontCustomer.Name, Address = frontCustomer.Address, Code = "0" }; try { var custr = _unitOfWork.CustomerRepository.Add(customer); _unitOfWork.Commit(); custr.Code = string.Format("{0:0000}", custr.Id) + "-" + DateTime.Now.Year.ToString(); _unitOfWork.CustomerRepository.Update(custr); var user = _unitOfWork.UserRepository.All().Single(u => u.Id == userId); user.Customer_Id = custr.Id; _unitOfWork.UserRepository.Update(user); _unitOfWork.Commit(); return(true); } catch { return(false); } }
public IActionResult AddCustomer(FrontCustomer frontCustomer) { string userId = User.Claims.SingleOrDefault(c => c.Type == "UserID").Value; var result = _marketUoW.UseUserMngmtRepository().AssignCustomer(frontCustomer, userId).Result; if (result.Succeeded) { return(Ok()); } else { return(BadRequest()); } }
public IActionResult AddCustomer(FrontCustomer frontCustomer) { string userId = User.Claims.SingleOrDefault(c => c.Type == "UserID").Value; var result = _customerService.CreateCustomer(frontCustomer, userId); if (result) { return(Ok()); } else { return(BadRequest()); } }
public IActionResult CreateUser(FrontUser frontUser) { LoginRegisterModel loginRegisterModel = new LoginRegisterModel() { UserName = frontUser.UserName, Password = frontUser.Password }; FrontCustomer frontCustomer = new FrontCustomer() { Address = frontUser.Address, Name = frontUser.Name }; string userId = Convert.ToString(_userService.CreateUser(loginRegisterModel, "User").Data); return(Ok(_customerService.CreateCustomer(frontCustomer, userId))); }
public IActionResult CreateUser(FrontUser frontUser) { CreateUserResult result = new CreateUserResult(); LoginRegisterModel loginRegisterModel = new LoginRegisterModel() { UserName = frontUser.UserName, Password = frontUser.Password }; FrontCustomer frontCustomer = new FrontCustomer() { Address = frontUser.Address, Name = frontUser.Name }; var userCreationResult = _marketUoW.UseUserMngmtRepository().CreateUser(loginRegisterModel, "User"); if (userCreationResult.Success) { var assignResult = _marketUoW.UseUserMngmtRepository().AssignCustomer(frontCustomer, userCreationResult.UserId).Result; if (assignResult.Succeeded) { result.Success = true; } ; } return(Ok(result)); }