Exemplo n.º 1
0
        public ActionResult Index(CustomerRegisterModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (User != null && User.Identity != null && User.Identity.IsAuthenticated)
                    {
                        model.Email = User.Identity.Name;
                    }
                    else
                    {
                        var x = WebSecurity.CreateUserAndAccount(model.Email, model.Password);
                        WebSecurity.Login(model.Email, model.Password);
                    }

                    model.CustomerID = WebSecurity.GetUserId(model.Email);
                    var customer = _CustomerQueries.details(model);
                    _CustomerQueries.InsertCustomer(customer);
                    return(RedirectToAction("Index", "CustomerDetails", new { id = model.CustomerID }));
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return(View(model));
        }
Exemplo n.º 2
0
 public IActionResult Post([FromBody] CustomerRegisterModel model)
 {
     if (ModelState.IsValid)
     {
         _customerOperations.Add(model);
     }
     else
     {
         return(BadRequest());
     }
     return(Ok());
 }
Exemplo n.º 3
0
 public void AddCustomer(CustomerRegisterModel model)
 {
     Context.Customers.Add(new Customer
     {
         CustomerId   = model.CustomerId,
         City         = model.City,
         CompanyName  = model.CompanyName,
         ContactName  = model.ContactName,
         ContactTitle = model.ContactTitle,
         Country      = model.Country,
         Region       = model.Region
     });
 }
Exemplo n.º 4
0
        public void Add(CustomerRegisterModel model)
        {
            _logger.LogInformation($"{MethodBase.GetCurrentMethod().Name} started");
            var modelCheck = _repositories.Customers.GetSingle(u => u.CustomerId == model.CustomerId);

            if (modelCheck == null)
            {
                _repositories.Customers.AddCustomer(model);
                _repositories.SaveChanges();
            }
            else
            {
                throw new LogicException("There is already customer with that Id");
            }
            _logger.LogInformation($"{MethodBase.GetCurrentMethod().Name} finished");
        }
Exemplo n.º 5
0
        public CustomerDetail details(CustomerRegisterModel model)
        {
            var customer = new CustomerDetail();
            var DOB      = new DateTime(model.Birthyear, model.Birthmonth, model.Birthday);

            customer.Firstname       = model.FristName;
            customer.Lastname        = model.LastName;
            customer.CustomerID      = model.CustomerID;
            customer.Location        = model.location;
            customer.DateCreated     = DateTime.Now;
            customer.TypeofInsurance = model.TypeofInsurance;
            customer.Amount          = model.Amount;
            customer.DateofBirth     = DOB;
            customer.CustomerAge     = DateTime.Now.Year - DOB.Year;
            customer.NumOfYears      = model.NumOfYears;
            customer.Status          = false;
            return(customer);
        }
Exemplo n.º 6
0
        public async Task <ActionResult> Register(CustomerRegisterModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.UserName, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await UserManager.AddToRoleAsync(user.Id, UserRoles.Customer);

                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    model.Id                = user.Id;
                    model.IsCanOrder        = true;
                    TempData["NewCustomer"] = model;
                    return(RedirectToAction("Create", "Customer"));
                }
                AddErrors(result);
            }
            return(View(model));
        }