public ActionResult Reject(int?id)
        {
            Owner owner = db.owners.Where(p => p.ownerID == id).FirstOrDefault();

            if (owner.Status == "Rejected" || owner.Status == "Approved")
            {
                TempData["AlertMessage"] = "Th application has already been Rejected";
                return(RedirectToAction("AdminIndex"));
            }
            else
            {
                owner.Status          = "Rejected";
                db.Entry(owner).State = EntityState.Modified;
                db.SaveChanges();
                var mailTo = new List <MailAddress>();
                mailTo.Add(new MailAddress(owner.Email, owner.FullName));
                var body = $"Good Day {owner.FullName}, we apologize to inform you that your application has been rejected because your documentation(Title Deed) is incorrect.";

                Accommodation.Services.Implementation.EmailService emailService = new Accommodation.Services.Implementation.EmailService();
                emailService.SendEmail(new EmailContent()
                {
                    mailTo          = mailTo,
                    mailCc          = new List <MailAddress>(),
                    mailSubject     = "Application Statement  | Ref No.:" + owner.ownerID,
                    mailBody        = body,
                    mailFooter      = "<br/> Many Thanks, <br/> <b>Alliance</b>",
                    mailPriority    = MailPriority.High,
                    mailAttachments = new List <Attachment>()
                });
                TempData["AlertMessage"] = $"{owner.FullName} has been rejected";

                return(RedirectToAction("AdminIndex"));
            }
        }
        public ActionResult Approve(int?id)
        {
            Owner owner = db.owners.Where(p => p.ownerID == id).FirstOrDefault();

            if (owner.Status == "Approved" || owner.Status == "Rejected")
            {
                TempData["AlertMessage"] = "Th application has already been Rejected/Approved";
                return(RedirectToAction("AdminIndex"));
            }
            else
            {
                ApprovedOwnerss approvedOwnerss = new ApprovedOwnerss();
                approvedOwnerss.ownerID          = owner.ownerID;
                approvedOwnerss.FullName         = owner.FullName;
                approvedOwnerss.LastName         = owner.LastName;
                approvedOwnerss.Email            = owner.Email;
                approvedOwnerss.IDNumber         = owner.IDNumber;
                approvedOwnerss.Phone            = owner.Phone;
                approvedOwnerss.Type             = owner.Type;
                approvedOwnerss.FileName         = owner.FileName;
                approvedOwnerss.AltContactNumber = owner.AltContactNumber;
                approvedOwnerss.Status           = "Approved";
                db.ApprovedOwners.Add(approvedOwnerss);
                db.SaveChanges();
                //var userId = User.;
                //var nno = db.owners.ToList().Where(p => p.Email == approvedOwnerss.Email).Select(p => p.FullName).FirstOrDefault();
                //var user = db.owners.Find(owner.UserId);

                var mailTo = new List <MailAddress>();
                mailTo.Add(new MailAddress(owner.Email, owner.FullName));
                var body = $"Hello {owner.FullName}, Congratulations. We are glad to inform you that your application has been approved. You can now procced to adding your building details. You are required to pay the Subscription Fee in order for your building to be active to the Tenants <br/> Regards,<br/><br/> HomeLink <br/> .";

                Accommodation.Services.Implementation.EmailService emailService = new Accommodation.Services.Implementation.EmailService();
                emailService.SendEmail(new EmailContent()
                {
                    mailTo          = mailTo,
                    mailCc          = new List <MailAddress>(),
                    mailSubject     = "Application Statement | Ref No.:" + owner.ownerID,
                    mailBody        = body,
                    mailFooter      = "<br/> Many Thanks, <br/> <b>Alliance</b>",
                    mailPriority    = MailPriority.High,
                    mailAttachments = new List <Attachment>()
                });
                db.owners.Remove(owner);
                db.SaveChanges();
                //UserManager.AddToRole(user.Id, "Landlord");
                _userManager.AddToRole(owner.UserId, "Landlord");
                TempData["AlertMessage"] = $"{owner.FullName} has been successfully approved";

                return(RedirectToAction("AdminIndex"));
            }
        }
Esempio n. 3
0
        public async Task <ActionResult> RegisterManager(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var    OwnerEmail = User.Identity.GetUserName();
                string pwd        = "@User001";
                var    user       = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, pwd);

                model.Password        = pwd;
                model.ConfirmPassword = pwd;
                Manager manager = new Manager();
                manager.FullName         = model.FullName;
                manager.LastName         = model.LastName;
                manager.Email            = model.Email;
                manager.Gender           = model.Gender;
                manager.Nationality      = "South African";
                manager.AltContactNumber = model.AltContactNumber;
                manager.Phone            = model.Phone;
                manager.OwnerEmail       = OwnerEmail;
                db.Managers.Add(manager);
                db.SaveChanges();

                var provider = new DpapiDataProtectionProvider("SampleAppName");
                UserManager.UserTokenProvider = new DataProtectorTokenProvider <ApplicationUser>(
                    provider.Create("SampleTokenName"));

                string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                var callbackUrl = Url.Action("ConfirmEmail", "Users", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                var mailTo      = new List <MailAddress>();
                mailTo.Add(new MailAddress(model.Email, model.FullName));
                var body = $"Hello {model.FullName}, Alliance Properties SA Team have created an account on your behalf as a Manager. <br/><br/>Your login credentials are as follows<br/><br/>" +
                           "Email (Username) : " + model.Email +
                           "<br/>Password : "******"tempPassword").ToString() +
                           "<br/><br/> " +
                           "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>";

                Accommodation.Services.Implementation.EmailService emailService = new Accommodation.Services.Implementation.EmailService();
                emailService.SendEmail(new EmailContent()
                {
                    mailTo          = mailTo,
                    mailCc          = new List <MailAddress>(),
                    mailSubject     = "Confirm your account",
                    mailBody        = body,
                    mailFooter      = "<br/> Many Thanks, <br/> <b>Homelink</b>",
                    mailPriority    = MailPriority.High,
                    mailAttachments = new List <Attachment>()
                });
                UserManager.AddToRole(user.Id, "Manager");


                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, "Manager");
                    return(RedirectToAction("Index", "Managers"));
                }
                AddErrors(result);
            }

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