Ejemplo n.º 1
0
        public ActionResult MyAccountDesignReview_Post([Bind(Prefix = "DesignReview")] DesignReview designReview)
        {
            bool         received = false;
            SkyberryUser user     = UOW.SkyberryUsers.GetById(User.Identity.GetUserId());
            string       from     = "*****@*****.**";

            if (user.Contacts != null && user.Contacts.Count > 0)
            {
                foreach (var item in user.Contacts)
                {
                    if (item.ContactType == "Email")
                    {
                        from = item.ContactData;
                    }
                }
            }

            DesignReview   dbDesignReview   = UOW.DesignReviews.GetById(designReview.Id);
            ReviewDocument dbReviewDocument = UOW.ReviewDocuments.GetById(designReview.SelectedReviewDocumentId);

            if (dbDesignReview != null && !dbDesignReview.AcceptedDate.HasValue && dbReviewDocument != null)
            {
                dbDesignReview.SelectedComment          = designReview.SelectedComment;
                dbDesignReview.AdditionalComment        = designReview.AdditionalComment;
                dbDesignReview.SelectedReviewDocumentId = designReview.SelectedReviewDocumentId;

                UOW.Commit();
                designReview = dbDesignReview;

                string description = "Skyberry Design Review Submission";

                StringBuilder body = new StringBuilder();

                body.Append("<table cellpadding='3' border='0'>");
                body.AppendFormat("<tr><td style='background-color:#d7d7d7;white-space:nowrap;text-align:right;vertical-align:top;'><strong>{0}</strong></td><td style='background-color:#e6e6e5;text-align:left;vertical-align:top;'>{1} {2} ({3})</td></tr>", "User", user.FirstName, user.LastName, user.UserName);
                body.AppendFormat("<tr><td style='background-color:#d7d7d7;white-space:nowrap;text-align:right;vertical-align:top;'><strong>{0}</strong></td><td style='background-color:#e6e6e5;text-align:left;vertical-align:top;'>{1} | {2} | {3}</td></tr>", "Design Review", dbDesignReview.Project.Account.Name, dbDesignReview.Project.Name, dbDesignReview.Title);
                body.AppendFormat("<tr><td style='background-color:#d7d7d7;white-space:nowrap;text-align:right;vertical-align:top;'><strong>{0}</strong></td><td style='background-color:#e6e6e5;text-align:left;vertical-align:top;'>{1}</td></tr>", "Selected Option", dbReviewDocument.Title);
                body.AppendFormat("<tr><td style='background-color:#d7d7d7;white-space:nowrap;text-align:right;vertical-align:top;'><strong>{0}</strong></td><td style='background-color:#e6e6e5;text-align:left;vertical-align:top;'>{1}</td></tr>", "Selected Comment", dbDesignReview.SelectedComment);
                body.AppendFormat("<tr><td style='background-color:#d7d7d7;white-space:nowrap;text-align:right;vertical-align:top;'><strong>{0}</strong></td><td style='background-color:#e6e6e5;text-align:left;vertical-align:top;'>{1}</td></tr>", "Additional Comment", dbDesignReview.AdditionalComment);
                body.AppendFormat("<tr><td style='background-color:#d7d7d7;white-space:nowrap;text-align:right;vertical-align:top;'><strong>{0}</strong></td><td style='background-color:#e6e6e5;text-align:left;vertical-align:top;'>{1}{2}</td></tr>", "Shortcut", HtmlUtil.GetDomain(Request.Url), @Url.Action("MyAccountDesignReview", "MyAccount", new { id = dbReviewDocument.DesignReviewId }));
                body.AppendFormat("<tr><td style='background-color:#d7d7d7;white-space:nowrap;text-align:right;vertical-align:top;'><strong>{0}</strong></td><td style='background-color:#e6e6e5;text-align:left;vertical-align:top;'>{1}</td></tr>", "Timestamp", DateTime.UtcNow.AddHours(-8).ToString("MM/dd/yyyy @ h:mm tt"));
                body.AppendFormat("<tr><td style='background-color:#d7d7d7;white-space:nowrap;text-align:right;vertical-align:top;'><strong>{0}</strong></td><td style='background-color:#e6e6e5;text-align:left;vertical-align:top;'>{1}</td></tr>", "Users IP", HtmlUtil.GetUserIP());
                body.Append("</table>");

                MailMessage message = new MailMessage();
                message.From = new MailAddress(from);
                message.To.Add(new MailAddress("*****@*****.**"));
                message.Subject         = description;
                message.IsBodyHtml      = true;
                message.Body            = body.ToString();
                message.BodyEncoding    = System.Text.Encoding.UTF8;
                message.SubjectEncoding = System.Text.Encoding.UTF8;


                SmtpClient SMTPServer = new SmtpClient(WebConfigurationManager.AppSettings["SMTP_HOST"]);
                SMTPServer.Port = Int16.Parse(WebConfigurationManager.AppSettings["SMTP_PORT"]);
                //SMTPServer.Credentials = new System.Net.NetworkCredential(WebConfigurationManager.AppSettings["SMTP_USERNAME"], WebConfigurationManager.AppSettings["SMTP_PASSWORD"]);

                try
                {
#if DEBUG
                    string debugAddress = WebConfigurationManager.AppSettings["DEBUG_EMAIL"];
                    if (!string.IsNullOrEmpty(debugAddress))
                    {
                        message.To.Clear();
                        message.CC.Clear();
                        message.Bcc.Clear();
                        message.To.Add(debugAddress);
                    }
#endif
                    SMTPServer.Send(message);
                    received = true;
                }
                catch (Exception ex)
                {
#if DEBUG
                    ModelState.AddModelError(string.Empty, "Exception: " + ex.Message);
#endif
                }
                message.Dispose();
            }

            Account    account = null;
            HttpCookie cookie  = Request.Cookies.Get("accountId");
            if (cookie != null)
            {
                try
                {
                    account = UOW.Accounts.GetById(Guid.Parse(cookie.Value));
                }
                catch { }
            }
            if (account == null && user.Accounts != null && user.Accounts.Count > 0)
            {
                foreach (var item in user.Accounts)
                {
                    account = UOW.Accounts.GetById(item.Id);
                    break;
                }
            }

            MyAccountDesignReviewVM vm = new MyAccountDesignReviewVM
            {
                User         = user,
                Account      = account,
                DesignReview = designReview,
                Received     = received
            };
            return(View(vm));
        }