Exemplo n.º 1
0
        public bool CreateAgency(RegisterViewModelAgency data, string userid)
        {
           
            var agency = new Agency
            {
                UserId = userid,
                AgencyEmail = data.Agency.AgencyEmail,
                AgencyName = data.Agency.AgencyName,
                PostCode = data.Agency.PostCode,
                AddressLine = data.Agency.AddressLine,
                Country = data.Agency.Country,
                City = data.Agency.City,
                PhoneNumber = data.Agency.PhoneNumber,
            };
            if (AgencyContext.CreateAgency(agency)) return true;

            return false;

        }
Exemplo n.º 2
0
        public async Task<ActionResult> RegisterAgency(RegisterViewModelAgency model)
        {
            //get payment
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser { UserName = model.Agency.AgencyEmail, Email = model.Agency.AgencyEmail };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                    if (CreateAgency(model, user.Id))
                    {
                        if (!Roles.RoleExists("Agency"))
                            Roles.CreateRole("Agency");
                        Roles.AddUserToRole(model.Agency.AgencyEmail, "Agency");

                        // For more information on how to enable account 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", "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", "Agencies");
                    }
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }