Exemplo n.º 1
0
        public JsonResult ApproveApplication(AdminApproveViewModel model)
        {
            var errors = ModelState.Values.SelectMany(v => v.Errors);

            if (ModelState.IsValid)
            {
                using (DBModel db = new DBModel())
                {
                    //Update application Details
                    var currentUserId     = User.Identity.GetUserId();
                    var ApplicationUpdate = db.EMarketApplications.SingleOrDefault(c => c.Id == model.ApplicationID);
                    var _action           = "ApproveApplication";
                    if (ApplicationUpdate != null)
                    {
                        try
                        {
                            ApplicationUpdate.POAApproved       = true;
                            ApplicationUpdate.POADateApproved   = DateTime.Now;
                            ApplicationUpdate.POAWhoApproved    = currentUserId;
                            ApplicationUpdate.POAApprovalStatus = 1;
                            ApplicationUpdate.POAComments       = model.Comments;
                            db.SaveChanges();

                            //Send Email to Client
                            string EmailBody = string.Empty;
                            using (System.IO.StreamReader reader = new StreamReader(Server.MapPath("~/Content/emails/ApplicationApproved.html")))
                            {
                                EmailBody = reader.ReadToEnd();
                            }
                            EmailBody = EmailBody.Replace("{CompanyName}", model.CompanyName);

                            var SendRegistrationCompleteEmail = MailHelper.SendMailMessage(MailHelper.EmailFrom, model.CompanyEmail, "Application Approved", EmailBody);

                            if (SendRegistrationCompleteEmail == true)
                            {
                                //Log email sent notification
                                LogNotification.AddSucsessNotification(MailHelper.EmailFrom, EmailBody, model.CompanyEmail, _action);
                            }
                            else
                            {
                                //Log Email failed notification
                                LogNotification.AddFailureNotification(MailHelper.EmailFrom, EmailBody, model.CompanyEmail, _action);
                            }
                        }
                        catch (Exception ex)
                        {
                            throw (ex);
                        }
                    }
                    else
                    {
                        return(Json("Error! Unable to approve application!", JsonRequestBehavior.AllowGet));
                    }
                }
                return(Json("success", JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json("Model Invalid! " + errors + " ", JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 2
0
        public JsonResult ApproveApplication(AdminApproveViewModel model)
        {
            var errors = ModelState.Values.SelectMany(v => v.Errors);

            if (ModelState.IsValid)
            {
                using (DBModel db = new DBModel())
                {
                    //1. Update application Details
                    var currentUserId     = User.Identity.GetUserId();
                    var ApplicationUpdate = db.EMarketApplications.SingleOrDefault(c => c.Id == model.ApplicationID);
                    var CompanyDetails    = db.ClientCompanies.SingleOrDefault(s => s.Id == ApplicationUpdate.CompanyID);
                    var _action           = "ApproveApplication";

                    if (ApplicationUpdate != null)
                    {
                        try
                        {
                            //2. Update application status
                            ApplicationUpdate.OPSApproved       = true;
                            ApplicationUpdate.OPSDateApproved   = DateTime.Now;
                            ApplicationUpdate.OPSWhoApproved    = currentUserId;
                            ApplicationUpdate.OPSApprovalStatus = 1;
                            ApplicationUpdate.OPSComments       = model.Comments;
                            var savedApplicationDetails = db.SaveChanges();
                            if (savedApplicationDetails > 0)
                            {
                                //3. Send email notification to Poa for approval
                                var DDUserRole = (from p in db.AspNetUserRoles
                                                  join e in db.AspNetUsers on p.UserId equals e.Id
                                                  where p.RoleId == "1f477b75-8a56-4662-b4d1-48551bed6111" && e.Status == 1
                                                  select new
                                {
                                    EmailID = e.Email
                                }).ToList();
                                foreach (var email in DDUserRole)
                                {
                                    var DDMessageBody = "Dear Team <br/><br/> Kindly note that the following client's application has been approved by the Operations Team. <br/>" +
                                                        "Company Name: " + CompanyDetails.CompanyName + ", Company Email: " + CompanyDetails.BusinessEmailAddress + " " +
                                                        "<br/><br/> Kind Regards,<br/><img src=\"https://e-documents.stanbicbank.co.ke/Content/images/EmailSignature.png\"/>";
                                    var SendDDNotificationEmail = MailHelper.SendMailMessage(MailHelper.EmailFrom, email.EmailID, "Ops Approved Application", DDMessageBody);
                                    if (SendDDNotificationEmail == true)
                                    {
                                        //Log email sent notification
                                        LogNotification.AddSucsessNotification(MailHelper.EmailFrom, DDMessageBody, email.EmailID, _action);
                                    }
                                    else
                                    {
                                        //Log Email failed notification
                                        LogNotification.AddFailureNotification(MailHelper.EmailFrom, DDMessageBody, email.EmailID, _action);
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            throw (ex);
                        }
                    }
                    else
                    {
                        return(Json("Unable to approve application!", JsonRequestBehavior.AllowGet));
                    }
                }
                return(Json("success", JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json("Model Invalid! " + errors + " ", JsonRequestBehavior.AllowGet));
            }
        }