Ejemplo n.º 1
0
        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());
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        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());
            }
        }
Ejemplo n.º 4
0
        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());
            }
        }
Ejemplo n.º 5
0
        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)));
        }
Ejemplo n.º 6
0
        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));
        }