Ejemplo n.º 1
0
        public async Task <IActionResult> AddDealer(DealerAddModel model)
        {
            if (ModelState.IsValid)
            {
                model.Address = model.Address + "  -" + model.City + "/" + model.District;
                await _dealerService.AddDealerAsync(model);

                return(RedirectToAction("Index", "Dealer"));
            }
            else
            {
                return(View(model));
            }
        }
Ejemplo n.º 2
0
        public async Task AddDealerAsync(DealerAddModel model)
        {
            MultipartFormDataContent formDataContent = new MultipartFormDataContent();

            formDataContent.Add(new StringContent(model.Name), nameof(model.Name));
            formDataContent.Add(new StringContent(model.Address), nameof(model.Address));
            formDataContent.Add(new StringContent(model.Email), nameof(model.Email));
            formDataContent.Add(new StringContent(model.PhoneNumber), nameof(model.PhoneNumber));

            var user = _accessor.HttpContext.Session.GetObject <AppUserViewModel>("activeUser");

            model.AppUserId = user.Id;
            formDataContent.Add(new StringContent(model.AppUserId.ToString()), nameof(model.AppUserId));

            _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _accessor.HttpContext.Session.GetString("token"));
            await _httpClient.PostAsync("", formDataContent);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("FirstName,LastName,Telephone,Address,City,JoinDate", "Email", "Password")] DealerAddModel model)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser testUser = await _userManager.FindByEmailAsync(model.Email);

                if (testUser == null)
                {
                    ApplicationUser newUser = new ApplicationUser();
                    newUser.Email    = model.Email;
                    newUser.UserName = model.Email;

                    string         pass   = model.Password;
                    IdentityResult result = await _userManager.CreateAsync(newUser, pass);

                    if (result.Succeeded)
                    {
                        await _userManager.AddToRoleAsync(newUser, "Dealer");

                        Dealer dealer = new Dealer()
                        {
                            Address         = model.Address,
                            City            = model.City,
                            FirstName       = model.FirstName,
                            LastName        = model.LastName,
                            JoinDate        = DateTime.Now,
                            Telephone       = model.Telephone,
                            ApplicationUser = newUser
                        };
                        _context.Add(dealer);
                        await _context.SaveChangesAsync();

                        return(RedirectToAction(nameof(Index)));
                    }
                }
                ModelState.AddModelError("testUser", "Already a Member");
                return(View(model));
            }
            return(View(model));
        }