Пример #1
0
        /// <summary>
        /// Send Email to admin for Approvel
        /// </summary>
        public virtual void SendEmailToAdmin(string UserEmail, RegisterViewModel model)
        {
            string Emailto = System.Web.Configuration.WebConfigurationManager.AppSettings["Email_To"].ToString();  // '*****@*****.**';
            string subject = "Please Review New Account";
            // string body = "New User Added in Mondofi";
            string body = "<html><head><meta content=\"text/html;" +
                   "charset=utf-8\" /></head><body>" +

                   "<p>'" + model.UserName + "' is  new User Added in Mondofi</p>" +
                      "<p>First Name: " + model.FirstName + "</p>" +
                   "<p>Last Name: " + model.LastName + "</p>" +
                       "<p>Email: " + model.UserName + "</p>" +
                        "<p>Venue Name: " + model.RestaurantName + "</p>" +
                            "<p>Venue Phone #: " + model.phone + "</p>" +
                            "<p>Notes: " + model.Notes + "</p>" +

                      "</body></html>";
            SendEmail.SendEmail(subject, body, Emailto, null, UserEmail, null);
        }
Пример #2
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {


            if (model.TermAndCondition == false)
            {
                ViewBag.Countries = new SelectList(db.tabCountry.ToList(), "CountryId", "CountryName");
                ModelState.AddModelError("", "Select Terms & Conditions.");
                return View(model);
            }

            if (ModelState.IsValid)
            {
                var user = new UserProfile { UserName = model.UserName, Email = model.UserName };
                var userget = UserManager.FindByName(model.UserName);
                if (userget != null)
                {
                    if (userget.UserName == model.UserName)
                    {
                        ViewBag.Countries = new SelectList(db.tabCountry.ToList(), "CountryId", "CountryName");
                        ModelState.AddModelError("", "Email already exists.");
                        return View(model);
                    }
                }

                var RestaurantName = db.Users.Where(c => c.RestaurantName.Trim() == model.RestaurantName.Trim()).FirstOrDefault();
                if (RestaurantName != null)
                {

                    if (RestaurantName.RestaurantName.Trim() == RestaurantName.RestaurantName.Trim())
                    {
                        ViewBag.Countries = new SelectList(db.tabCountry.ToList(), "CountryId", "CountryName");
                        ModelState.AddModelError("", "Venue Name already exists.");
                        return View(model);
                    }
                }

                Address address = new Address();
                address.City = model.Address.City;
                address.State = model.Address.State;
                address.CountryId = model.Address.CountryId;
                address.PostalCode = model.Address.PostalCode;
                db.tabAddress.Add(address);
                db.SaveChanges();

                var result = UserManager.Create(new UserProfile
                {
                    Email = model.UserName,
                    FirstName = model.FirstName,
                    LastName = model.LastName,
                    UserName = model.UserName,
                    PhoneNumber = model.phone,
                    Notes = model.Notes,
                    AddressId = address.AddressId,
                    RestaurantName = model.RestaurantName,
                    TermAndCondition = model.TermAndCondition,
                    Approved = false

                }, model.Password);
                if (result.Succeeded)
                {

                    var getUser = UserManager.FindByName(model.UserName);
                    var roleresult = UserManager.AddToRole(getUser.Id, "user");
                    try
                    {
                        send.SendEmailToAdmin(model.UserName, model);
                        send.SendEmailToUserWaitForApprovel(model.UserName, model.FirstName);
                    }
                    catch (Exception)
                    {
                        var getuser = UserManager.FindById(getUser.Id);
                        var logins = getuser.Logins;

                        foreach (var login in logins.ToList())
                        {
                            UserManager.RemoveLogin(login.UserId, new UserLoginInfo(login.LoginProvider, login.ProviderKey));
                        }

                        var rolesForUser = UserManager.GetRoles(getUser.Id);

                        if (rolesForUser.Count() > 0)
                        {
                            foreach (var item in rolesForUser.ToList())
                            {
                                // item should be the name of the role
                                var getresult = UserManager.RemoveFromRole(getuser.Id, item);
                            }
                        }
                        try
                        {
                            UserManager.Delete(getuser);
                        }
                        catch (Exception)
                        {

                            throw;
                        }

                        return RedirectToAction("NotRegister", "Account");

                    }

                    return RedirectToAction("ThankYouRegister", "Account");

                }
                AddErrors(result);
            }
            ViewBag.Countries = new SelectList(db.tabCountry.ToList(), "CountryId", "CountryName");
            // If we got this far, something failed, redisplay form
            return View(model);
        }
Пример #3
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser { 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 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", "Home");
                }
                AddErrors(result);
            }

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