public async Task <ActionResult> Register(RegisterCustomerViewModel customer)
        {
            if (ModelState.IsValid)
            {
                if (await client.AddCustomer(new Customer()
                {
                    Id = Guid.NewGuid().ToString(), Email = customer.Email, Name = customer.Name, Password = customer.Password, AddressLine1 = customer.AddressLine1, AddressLine2 = customer.AddressLine2, PinCode = customer.PinCode
                }))
                {
                    LoginViewModel loginModel = new LoginViewModel();
                    loginModel.Email    = customer.Email;
                    loginModel.Password = customer.Password;
                    var authcustomer = await client.AuthenticateCustomer(new Customer()
                    {
                        Email = customer.Email, Password = customer.Password
                    });

                    if (authcustomer != null)
                    {
                        CustomPrincipalSerializeModel serializeModel = new CustomPrincipalSerializeModel();
                        serializeModel.CustomerID = authcustomer.Id;
                        serializeModel.FirstName  = authcustomer.Name;
                        serializeModel.Email      = authcustomer.Email;

                        Response.Cookies.Add(Utility.Utility.EncryptAndSet(serializeModel));
                        return(RedirectToAction("Index", "Home"));
                    }
                }
            }

            return(View(customer));
        }
        public async Task <IActionResult> Register(RegisterCustomerViewModel customerInfo)
        {
            if (!ModelState.IsValid)
            {
                return(View(customerInfo));
            }

            string username = customerInfo.Email;

            IdentityUser user = await _userManager.FindByNameAsync(username);

            if (user != null)
            {
                ModelState.AddModelError("Email", "There is allready a customer with that email.");
                return(View(customerInfo));
            }

            user = new IdentityUser(username);
            await _userManager.CreateAsync(user, customerInfo.Password);

            await _userManager.AddToRoleAsync(user, "Customer");

            Customer customer = new Customer
            {
                Name  = customerInfo.Name,
                Email = customerInfo.Email
            };

            _context.Add(customer);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index), "Home"));
        }
        public IActionResult RegisterCustomer(RegisterCustomerViewModel registerViewModel)
        {
            if (ModelState.IsValid)
            {
                CustomIdentityUser user = new CustomIdentityUser
                {
                    UserName = registerViewModel.Name,
                    Email    = registerViewModel.Email
                };

                IdentityResult result = _userManager.CreateAsync(user, registerViewModel.Password).Result;

                if (result.Succeeded)
                {
                    if (!_roleManager.RoleExistsAsync("Customer").Result)
                    {
                        CustomIdentityRole role = new CustomIdentityRole
                        {
                            Name = "Customer"
                        };

                        IdentityResult roleResult = _roleManager.CreateAsync(role).Result;

                        if (!roleResult.Succeeded)
                        {
                            ModelState.AddModelError("", "Böyle bir rol ekleyemedik");
                            return(View(registerViewModel));
                        }
                    }
                    _userManager.AddToRoleAsync(user, "Customer").Wait();
                    return(RedirectToAction("LoginCustomer"));
                }
            }
            return(View(registerViewModel));
        }
Exemple #4
0
        public async Task <IdentityResult> RegisterCustomerAsync(RegisterCustomerViewModel model)
        {
            Customer customer = new Customer()
            {
                TimeStamp    = DateTime.Now,
                Email        = model.Email,
                CustomerName = model.CustomerName,
            };

            _customerService.AddCustomer(customer);

            ApplicationUser customerUserAccount = new ApplicationUser()
            {
                CustomerId = customer.Id,
                Email      = model.Email,
                FirstName  = model.CustomerName,
                UserName   = model.UserName,
                TimeStamp  = DateTime.Now
            };

            var result = await _userManager.CreateAsync(customerUserAccount, model.Password);

            if (result.Succeeded)
            {
                bool doesRoleExist = await _roleService.DoesRoleExistAsync("Admin");

                if (!doesRoleExist)
                {
                    await _roleService.CreateRoleAsync("Admin");
                }

                await _userManager.AddToRoleAsync(customerUserAccount, "Admin");
            }
            return(result);
        }
        public async Task <ActionResult> Register(RegisterCustomerViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    Id = Guid.NewGuid(), UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemple #6
0
        public async Task <ActionResult> Register(RegisterCustomerViewModel model)
        {
            ApplicationDbContext appDb = new ApplicationDbContext();

            if (ModelState.IsValid)
            {
                // create a customer table entry and a user table entry
                var customer = new Customer {
                    UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, BillingAddress = model.BillingAddress, City = model.City, Status = "registered"
                };
                var result = await UManager.CreateAsync(customer, model.Password);

                if (result.Succeeded)
                {
                    var addedToRole = await UManager.AddToRoleAsync(customer.Id, "Customer");

                    if (addedToRole.Succeeded)
                    {
                        return(RedirectToAction("Login"));
                    }
                }
                AddErrors(result);
            }
            return(View(model));
        }
        public ActionResult RegisterCustomer(RegisterCustomerViewModel model)
        {
            var address = new AddressModel
            {
                AddressId        = Guid.NewGuid(),
                StreetAddress    = model.StreetAddress,
                SecondaryAddress = model.SecondaryAddress,
                City             = model.City,
                ZipCode          = model.ZipCode,
                State            = model.State
            };

            dbContext.Addresses.Add(address);


            var customer = new CustomerModel
            {
                CustomerId    = Guid.NewGuid(),
                FirstName     = model.FirstName,
                LastName      = model.LastName,
                Status        = 0,
                PickUpDay     = model.PickUpDay,
                BaseCost      = model.BaseCost,
                ApplicationId = model.ApplicationId,
                AddressId     = address.AddressId
            };

            dbContext.Customers.Add(customer);

            var pickUp = new PickUpModel
            {
                PickUpId   = Guid.NewGuid(),
                Pending    = true,
                Completed  = false,
                Recurring  = true,
                Cost       = model.BaseCost,
                Paid       = false,
                CustomerId = customer.CustomerId
            };

            // todo: move this logic elsewhere (used in CustomerController, as well
            for (int i = 1; i < 8; i++)
            {
                DayOfWeek dayOfWeek = DateTimeOffset.UtcNow.ToLocalTime().AddDays(i).DayOfWeek;

                if (dayOfWeek == model.PickUpDay)
                {
                    pickUp.Scheduled = DateTimeOffset.UtcNow.ToLocalTime().AddDays(i).UtcDateTime;
                    break;
                }
            }

            dbContext.PickUps.Add(pickUp);

            dbContext.SaveChanges();

            return(RedirectToAction("Details", "Customer", new { Id = customer.CustomerId }));
        }
Exemple #8
0
 public ActionResult RegisterCustomer(RegisterCustomerViewModel viewModel)
 {
     if (ModelState.IsValid)
     {
         var result = _authenticationManager.Register(viewModel);
         return(RedirectToAction("ListCustomer"));
     }
     return(View(viewModel));
 }
        public ActionResult RegisterCustomer()
        {
            string userId = Request.QueryString["Id"];
            var    model  = new RegisterCustomerViewModel();

            model.ApplicationId = userId;

            return(View(model));
        }
Exemple #10
0
 public ActionResult Register(RegisterCustomerViewModel viewModel)
 {
     if (ModelState.IsValid)
     {
         var result = _authenticationManager.Register(viewModel);
         return(Content(result));
     }
     return(View(viewModel));
 }
Exemple #11
0
        public async Task <IActionResult> RegisterCustomer(RegisterCustomerViewModel vm)
        {
            //We added validation
            //So that is where isValid comes into action
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser
                {
                    UserName    = vm.Username,
                    PhoneNumber = vm.Phone,
                    Email       = vm.Email
                };

                //save to db
                //you don't want to do it in your main thread
                //this method needs to be an async method
                IdentityResult result = await _userManagerService.CreateAsync(user, vm.Password);

                if (result.Succeeded)
                {
                    if (!await _userManagerService.IsInRoleAsync(user, "Customer"))
                    {
                        await _userManagerService.AddToRoleAsync(user, "Customer");
                    }

                    IdentityUser specificUser = await _userManagerService.FindByNameAsync(user.UserName);

                    Customer newCustomer = new Customer
                    {
                        UserId    = specificUser.Id,
                        FirstName = vm.FirstName,
                        LastName  = vm.LastName
                    };

                    _customerRepo.Create(newCustomer);

                    //--------======= SMS Notification ========-----------

                    string smsContent = "Welcome to Grande Travel, " + newCustomer.FirstName + "!";

                    await _smsService.SendSmsAsync(user.PhoneNumber, smsContent);

                    return(RedirectToAction("Index", "Packages"));
                    //return RedirectToAction("Login", "Account");
                }
                else
                {
                    foreach (var err in result.Errors)
                    {
                        //ModelState.AddModelError("" , "error");
                        ModelState.AddModelError("", err.Description);
                    }
                }
            }

            return(View(vm));
        }
        //[ValidateAntiForgeryToken]
        public async Task <ActionResult> Register(RegisterCustomerViewModel model)
        {
            if (ModelState.IsValid)
            {
                #region Check for duplicate username or email
                if (UserRepo.UserNameExists(model.PhoneNumber))
                {
                    ModelState.AddModelError("", Resources.Resource.PhoneNumberExists);
                    return(View(model));
                }
                if (UserRepo.EmailExists(model.Email))
                {
                    ModelState.AddModelError("", Resources.Resource.EmailExists);
                    return(View(model));
                }
                #endregion

                var user = new User {
                    UserName    = model.PhoneNumber,
                    PhoneNumber = model.PhoneNumber,
                    Email       = model.Email,
                    FirstName   = model.FirstName,
                    LastName    = model.LastName
                };
                UserRepo.CreateUser(user, model.Password);
                if (user.Id != null)
                {
                    // Add Customer Role
                    UserRepo.AddUserRole(user.Id, StaticVariables.CustomerRoleId);

                    // Add Customer
                    var customer = new Core.Models.Customer()
                    {
                        UserId    = user.Id,
                        IsDeleted = false
                    };
                    UserRepo.AddCustomer(customer);
                    //await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                    // For more information on how to enable Auth confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Auth", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your Auth", "Please confirm your Auth by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Login", "Auth"));
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemple #13
0
        // GET: Register
        public ActionResult Index()
        {
            var model = new RegisterCustomerViewModel();

            model.sidebar.categories        = new BusinessHandler().GetCategories().ToSideBarViewModel();
            model.sidebar.productcategories = new BusinessHandler().GetProductCategories().ToSideBarViewModel();
            ViewBag.Categories      = new BusinessHandler().GetCategories().ToCategoryViewModelList();
            ViewBag.CompanyAddress  = new BusinessHandler().GetCompanyAddress().ToCompanyAdressViewModel();
            ViewBag.SocialMediaLink = new BusinessHandler().GetSocialMediaLinks().ToSocialMediaLinkViewModel();
            ViewBag.MyCart          = (Cart)Session["Cart"];
            ViewBag.UserName        = (string)Session["Username"];
            return(View(model));
        }
Exemple #14
0
        public async Task <IActionResult> Register([FromBody] RegisterCustomerViewModel model)
        {
            model.rememberMe = false;

            try
            {
                if (!ModelState.IsValid)
                {
                    var query = from state in ModelState.Values
                                from error in state.Errors
                                select error.ErrorMessage;

                    var errorList = query.ToList();

                    return(BadRequest(new RegistrationResultDTO {
                        Status = "fail",
                        ResponseCode = "01",
                        ResponseMessage = "User Registration Failed",
                        UserSignInResult = null,
                        ErrorList = errorList
                    }));
                }
                else
                {
                    var registrationResult = await _identityService.RegisterAsync(model.email, model.Password, model.rememberMe, model.lastname, model.firstname, model.phonenumber);

                    if (registrationResult.Status == "success")
                    {
                        return(Ok(registrationResult));
                    }
                    else
                    {
                        return(BadRequest(registrationResult));
                    }
                }
            }
            catch (Exception ex)
            {
                var OtherErrors = new RegistrationResultDTO
                {
                    Status           = "fail",
                    ResponseCode     = "02",
                    ResponseMessage  = ex.Message.ToString(),
                    UserSignInResult = null,
                    ErrorList        = null
                };

                return(StatusCode(500, OtherErrors));
            }
        }
Exemple #15
0
 public IActionResult RegisterCustomer
     (RegisterCustomerViewModel registerCustomerViewModel)
 {
     if (ModelState.IsValid)
     {
         registerCustomerViewModel.Account.UserName = registerCustomerViewModel.Account.UserName.Trim();
         registerCustomerViewModel.Account.Password = registerCustomerViewModel.Account.Password.Trim();
         registerCustomerViewModel.Mail             = registerCustomerViewModel.Mail.Trim();
         registerCustomerViewModel.Name             = registerCustomerViewModel.Name.Trim();
         registerCustomerViewModel.RePassword       = registerCustomerViewModel.RePassword.Trim();
         if (registerCustomerViewModel.RePassword == registerCustomerViewModel.Account.Password)
         {
             Customer customer = Mapper.Map <RegisterCustomerViewModel, Customer>(registerCustomerViewModel);
             int      check    = this.CustomerService.GetCustomerIdByEmail(customer.Mail);
             if (check == 0)
             {
                 if (CustomerService.InsertCustomer(customer, StaticValue.StaticValue.PERMISSION_STAFF))
                 {
                     //var customerModel = Mapper.Map<Customer, CustomerModel>(customer);
                     SessionModel session = new SessionModel();
                     session.CustomerId   = this.CustomerService.GetCustomerIdByEmail(customer.Mail);
                     session.CustomerName = customer.Name;
                     HttpContext.Session.SetSession("session", session);
                     HttpContext.Session.SetSession("permission", StaticValue.StaticValue.PERMISSION_STAFF);
                     return(RedirectToAction("HomePage", "Product"));
                 }
                 else
                 {
                     ModelState.AddModelError("Account.UserName", "Tài khoản trùng");
                     return(View(registerCustomerViewModel));
                 }
             }
             else
             {
                 ModelState.AddModelError("Mail", "Mail đã tồn tại!");
                 return(View(registerCustomerViewModel));
             }
         }
         else
         {
             ModelState.AddModelError("RePassword", "Mật khẩu nhập lại không đúng!");
             return(View(registerCustomerViewModel));
         }
     }
     else
     {
         return(View(registerCustomerViewModel));
     }
 }
Exemple #16
0
        public async Task <ActionResult> RegisterCustomer(RegisterCustomerViewModel model, string returnUrl)//Yahan masla hey
        {
            if (returnUrl != null)
            {
                return(RedirectToLocal(returnUrl));
            }
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email, UserType = "Customer"
                };

                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    //await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
                    UserManager.AddToRole(user.Id, "Customer");
                    Customer customer = new Customer()
                    {
                        FirstName         = model.FirstName,
                        LastName          = model.LastName,
                        Address           = model.Address,
                        PhoneNumber       = model.PhoneNumber,
                        ApplicationUserId = user.Id,
                        CompanyName       = model.CompanyName,
                    };

                    ApplicationDbContext db = new ApplicationDbContext();


                    db.customers.Add(customer);
                    Console.WriteLine(customer);
                    db.SaveChanges();

                    return(RedirectToAction("Index", "Home", null));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public async Task <int> AddCustomer(RegisterCustomerViewModel model, string UserId)
        {
            Customer customer = new Customer
            {
                Firstname = model.FirstName,
                Lastname  = model.LastName,
                Address   = model.Address,
                UserId    = UserId
            };

            db.Customer.Add(customer);
            await db.SaveChangesAsync();

            return(customer.ID);
        }
Exemple #18
0
        public async Task <IActionResult> RegisterCustomerAsync([Microsoft.AspNetCore.Mvc.FromBody] RegisterCustomerViewModel model)
        {
            if (ModelState.IsValid)
            {
                var result = await _customerService.RegisterCustomerAsync(model);

                if (result.IsSuccess)
                {
                    return(Ok(result));
                }

                return(BadRequest(result));
            }

            return(BadRequest("Some properties are not valid")); // Status Code: 400
        }
Exemple #19
0
        public async Task <IActionResult> RegisterCustomer(RegisterCustomerViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var user = new CustomerUser
                {
                    UserName      = model.UserName,
                    FullName      = model.FullName,
                    Email         = model.Email,
                    PhoneNumber   = model.Phone,
                    Region        = model.Region,
                    Manufacturing = model.Manufacturing,
                    Country       = model.Country,
                    Position      = model.Position
                };
                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    var role = "Customer";
                    if (!await this.roleManager.RoleExistsAsync(role))
                    {
                        await this.roleManager.CreateAsync(new IdentityRole
                        {
                            Name = role
                        });
                    }

                    var res = await this._userManager.AddToRoleAsync(user, role);

                    if (res.Succeeded)
                    {
                        _logger.LogInformation("User created a new account with password.");

                        //await _signInManager.SignInAsync(user, isPersistent: false);
                        //_logger.LogInformation("User created a new account with password.");
                        return(Redirect("../../Home/Index"));
                    }
                }

                AddErrors(result);
            }

            return(View(model));
        }
        public IActionResult Edit(int id, RegisterCustomerViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var vehicle = customerDB.AddOrUpdate(new Customer
                    {
                        Id             = id,
                        FirstName      = model.FirstName,
                        LastName       = model.LastName,
                        Caption        = model.Caption,
                        IdentityNumber = model.IdentityNumber,
                        Birthdate      = model.Birthdate,
                        Gender         = model.Gender,
                        TaxNumber      = model.TaxNumber,
                        TaxOffice      = model.TaxOffice,
                        Mobile         = model.Mobile,
                        HomePhone      = model.HomePhone,
                        OfficePhone    = model.OfficePhone,
                        CityId         = model.CityId,
                        Address        = model.Address,
                        IsActive       = model.IsActive
                    });

                    if (vehicle.Id != null)
                    {
                        return(RedirectToAction("Index"));
                    }
                }

                model.States = locationDB.GetStates().Select(s => new SelectListItem {
                    Value = s.Id.ToString(), Text = s.Name
                }).ToList();
                model.Cities = locationDB.GetCities(model.StateId).Select(s => new SelectListItem {
                    Value = s.Id.ToString(), Text = s.Name
                }).ToList();
            }
            catch (Exception ex)
            {
                //loglanmalı
            }


            return(View(model));
        }
        public ActionResult Register(RegisterCustomerViewModel model)
        {
            var viewModel = new RegisterCustomerViewModel();
            var customer  = mapper.Map <RegisterCustomerViewModel, Customer>(model);

            var returnStatus = customerAccountService.CreateCustomer(customer);

            if (returnStatus == MembershipCreateStatus.Success)
            {
                var customerData = mapper.Map <RegisterCustomerViewModel, Customer>(model);
                mailer.NewCustomer(customer).Send();
                authentication.Signin(customer.Email, customerData);
                return(RedirectToAction("ThankYouForJoining"));
            }
            viewModel.HasError     = true;
            viewModel.CreateStatus = new CustomerCreationError(returnStatus);
            return(View(viewModel));
        }
        //[ValidateAntiForgeryToken]
        public async Task <ActionResult> RegisterCustomer(RegisterCustomerViewModel model)
        {
            ApplicationDbContext appDb = new ApplicationDbContext();

            if (ModelState.IsValid)
            {
                var customer = new Customer {
                    UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, BillingAddress = model.BillingAddress, City = model.City, Status = "registered"
                };
                var result = await UserManager.CreateAsync(customer, model.Password);

                if (result.Succeeded)
                {
                    return(View("AccountRegistered"));
                }
                AddErrors(result);
            }
            return(View(model));
        }
        public async Task <ActionResult> ManageCustomer(string returnUrl)
        {
            ViewBag.Message = "Lists the Customers";
            List <RegisterCustomerViewModel> customerList = new List <RegisterCustomerViewModel>();
            List <Customer> customers = await client.CustomerGetAll();

            foreach (Customer cust in customers)
            {
                RegisterCustomerViewModel temp = new RegisterCustomerViewModel();
                temp.Name         = cust.Name;
                temp.Email        = cust.Email;
                temp.AddressLine1 = cust.AddressLine1;
                temp.AddressLine2 = cust.AddressLine2;
                temp.PinCode      = cust.PinCode;

                customerList.Add(temp);
            }
            return(View(customerList));
        }
Exemple #24
0
        public async Task <ActionResult> Register(RegisterCustomerViewModel model)
        {
            var roleStore   = new RoleStore <IdentityRole>(db);
            var roleManager = new RoleManager <IdentityRole>(roleStore);

            if (ModelState.IsValid)
            {
                var customer = new Customer()
                {
                    Email     = model.Email,
                    UserName  = "******",
                    FirstName = model.FirstName,
                    LastName  = model.LastName,
                };
                IdentityResult result;
                result = await UserManager.CreateAsync(customer, model.Password);

                if (result.Succeeded)
                {
                    if (roleManager.FindByName("Admin") == null)
                    {
                        result = roleManager.Create(new IdentityRole {
                            Name = "Admin"
                        });
                    }
                    if (result.Succeeded)
                    {
                        result = UserManager.AddToRole(customer.Id, "Admin");
                        if (result.Succeeded)
                        {
                            await SignInAsync(customer, isPersistent : false);

                            return(RedirectToAction("Index", "Home"));
                        }
                    }
                }

                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public async Task <ActionResult> RegisterCustomer(RegisterCustomerViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new CustomerUser {
                    Id = Guid.NewGuid(), UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, CustomerNumber = model.CustomerNumber
                };
                var result = await UserManager.CreateAsync(user, model.Password);

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

                    // Add default water meter.
                    // NOTE: This is for demonstration purposes only! In the actual application, water meters would not be addef from the customer portal.
                    WaterMeter waterMeter = new WaterMeter()
                    {
                        CustomerUserGuid = user.Id,
                        Id = "123456789",
                    };
                    using (VesiPortalDbContext context = new VesiPortalDbContext())
                    {
                        WaterMeter.Add(context, waterMeter);
                    }

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

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    TempData[StaticMembers.MESSAGE] = Resources.Messages.Messages.RegisterSuccess;
                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public IActionResult Edit(int id)
        {
            var model = new RegisterCustomerViewModel();

            try
            {
                var detay = customerDB.Get(new Customer {
                    Id = id
                });
                model = new RegisterCustomerViewModel
                {
                    Id             = id,
                    FirstName      = detay.FirstName,
                    LastName       = detay.LastName,
                    Caption        = detay.Caption,
                    IdentityNumber = detay.IdentityNumber,
                    Birthdate      = detay.Birthdate,
                    Gender         = detay.Gender,
                    TaxNumber      = detay.TaxNumber,
                    TaxOffice      = detay.TaxOffice,
                    Mobile         = detay.Mobile,
                    HomePhone      = detay.HomePhone,
                    OfficePhone    = detay.OfficePhone,
                    StateId        = detay.StateId,
                    CityId         = detay.CityId,
                    Address        = detay.Address,
                    IsActive       = detay.IsActive.Value
                };
                model.States = locationDB.GetStates().Select(s => new SelectListItem {
                    Value = s.Id.ToString(), Text = s.Name
                }).ToList();
                model.Cities = locationDB.GetCities(detay.StateId).Select(s => new SelectListItem {
                    Value = s.Id.ToString(), Text = s.Name
                }).ToList();
            }
            catch (Exception ex)
            {
                //loglama
            }

            return(View(model));
        }
        public IActionResult Create()
        {
            var model = new RegisterCustomerViewModel();

            try
            {
                var stateList = locationDB.GetStates();
                model.States = stateList.Select(s => new SelectListItem {
                    Value = s.Id.ToString(), Text = s.Name
                }).ToList();
                model.Cities = locationDB.GetCities(stateList.First().Id).Select(s => new SelectListItem {
                    Value = s.Id.ToString(), Text = s.Name
                }).ToList();
            }
            catch (Exception ex)
            {
                //loglama
            }
            return(View(model));
        }
Exemple #28
0
        public IActionResult Register(RegisterCustomerViewModel user)
        {
            if (ModelState.IsValid)
            {
                var customer = new Customers
                {
                    Firstname            = user.Firstname,
                    Lastname             = user.Lastname,
                    SocialSecurityNumber = user.SocialSecurityNumber,
                    Address = user.Address
                };

                _context.Customers.Add(customer);
                _context.SaveChanges();
                TempData["Operation"] = "Customer Registration Successful.";
                return(RedirectToAction("Index", "Home", TempData));
            }

            return(View(user));
        }
Exemple #29
0
        public ActionResult <CustomerCreationViewModel> Post([FromBody] RegisterCustomerViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var id = Guid.NewGuid().ToString();
            //var pw = authService.HashPassword(model.Password);
            var customer = new Customer
            {
                Id                  = id,
                Email               = model.Email,
                Password            = model.Password,
                CustomerNumber      = new Random().Next(0, 100).ToString(),
                PersonalInformation = new Person
                {
                    FirstName            = model.FirstName,
                    LastName             = model.LastName,
                    Id                   = id,
                    SocialSecurityNumber = model.SocialSecurityNumber,
                    TelephoneNumber      = model.TelephoneNumber,
                    Address              = new Address
                    {
                        City                = model.City,
                        Country             = model.Country,
                        Id                  = id,
                        PostalCode          = model.PostalCode,
                        StreetNameAndNumber = model.StreetNameAndNumber
                    }
                }
            };

            customerRepository.Add(customer);
            customerRepository.Commit();

            return(new CustomerCreationViewModel
            {
                CustomerNumber = customer.CustomerNumber
            });
        }
        public async Task <IActionResult> Register(RegisterCustomerViewModel customer)
        {
            // If the register form is valid
            if (ModelState.IsValid)
            {
                var result = await _customerRegistrationService.RegisterCustomerAsync(customer);

                if (result.Succeeded)
                {
                    // If successful, return to log in page
                    return(RedirectToAction("index", "Home"));
                }

                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError("", error.Description);
                }
            }

            return(View());
        }