Example #1
0
        public async Task <IActionResult> Create(CustomerRequest customerRequest)
        {
            var customer = new Customers
            {
                DocumentNumber = customerRequest.DocumentNumber,
                FullName       = customerRequest.FullName,
                CreditLimit    = customerRequest.CreditLimit
            };

            try
            {
                Customers result = await _customersManager.CreateCustomer(customer);

                return(Ok(result));
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public IActionResult Register(RegisterModelView viewRegistration)
        {
            TempData["FName"]    = viewRegistration.FirstName;
            TempData["LName"]    = viewRegistration.LastName;
            TempData["Email"]    = viewRegistration.Email;
            TempData["UserName"] = viewRegistration.Username;
            TempData["Address"]  = viewRegistration.Address;
            TempData["City"]     = viewRegistration.City;
            TempData["Province"] = viewRegistration.Province;
            TempData["Country"]  = viewRegistration.Country;
            TempData["Phone"]    = viewRegistration.Phone;
            if (viewRegistration.FirstName == "" || viewRegistration.FirstName == null)
            {
                TempData["ErrorMessage"] = "First Name is required.";
                return(RedirectToAction("Register", "Account"));
            }
            else
            {
                if (viewRegistration.LastName == "" || viewRegistration.LastName == null)
                {
                    TempData["ErrorMessage"] = "Last Name is required.";
                    return(RedirectToAction("Register", "Account"));
                }
                else
                {
                    if (viewRegistration.Email == "" || viewRegistration.Email == null)
                    {
                        TempData["ErrorMessage"] = "Email is required.";
                        return(RedirectToAction("Register", "Account"));
                    }
                    else
                    {
                        if (viewRegistration.Username == "" || viewRegistration.Username == null)
                        {
                            TempData["ErrorMessage"] = "Usernamel is required.";
                            return(RedirectToAction("Register", "Account"));
                        }
                        else
                        {
                            if (viewRegistration.Password == "" || viewRegistration.Password == null)
                            {
                                TempData["ErrorMessage"] = "Passord is required.";
                                return(RedirectToAction("Register", "Account"));
                            }
                            else
                            {
                                int id;
                                var auth = new Authentication
                                {
                                    Username = viewRegistration.Username,
                                    Password = viewRegistration.Password
                                };
                                lock (Lock)
                                {
                                    id = UsersManager.CreateAuthentication(auth);
                                }
                                if (id > 0)
                                {
                                    var user = new Users
                                    {
                                        Address          = viewRegistration.Address,
                                        AuthenticationId = id,
                                        City             = viewRegistration.City,
                                        Country          = viewRegistration.Country,
                                        Email            = viewRegistration.Email,
                                        Province         = viewRegistration.Province,
                                        Phone            = viewRegistration.Phone,
                                        LastName         = viewRegistration.LastName,
                                        FirstName        = viewRegistration.FirstName
                                    };
                                    UsersManager.CreateUser(user);
                                    int UserId   = UsersManager.GetUserIdByAuthId(id);
                                    var customer = new Customers
                                    {
                                        UserId = UserId
                                    };
                                    CustomersManager.CreateCustomer(customer);
                                    TempData["Message"]      = "Regitration completed! Login to Access the TableReady portal.";
                                    TempData["ErrorMessage"] = null;
                                    return(RedirectToAction("Login", "Account"));
                                }

                                else
                                {
                                    TempData["Message"]      = null;
                                    TempData["ErrorMessage"] = "USERNAME already exist.Try another one.";
                                    return(RedirectToAction(nameof(Register)));
                                }
                            }
                        }
                    }
                }
            }
        }