Example #1
0
        public ActionResult Edit(WebOrderRequestEditViewModel viewModel)
        {
            string            emailRecipientList = String.Empty;
            ResultContainer   resultContainer    = null;
            GRINGlobalService grinGlobalService  = new GRINGlobalService(this.AuthenticatedUserSession.Environment);
            SmtpService       smtpService        = new SmtpService();

            try
            {
                WebOrderRequest webOrderRequest = new WebOrderRequest();
                webOrderRequest.ID         = viewModel.ID;
                webOrderRequest.StatusCode = viewModel.Action;

                if (viewModel.Action == OrderRequestAction.NRRReviewEnd)
                {
                    grinGlobalService.SetReviewStatus(viewModel.ID, AuthenticatedUser.Cooperator.WebCooperator.ID, false);
                }
                else
                {
                    if ((viewModel.Action != "NRR_NOTE") && (viewModel.Action != "NRR_INFO"))
                    {
                        resultContainer = grinGlobalService.UpdateWebOrderRequest(webOrderRequest);
                    }
                    resultContainer = grinGlobalService.AddWebOrderRequestAction(new WebOrderRequestAction {
                        WebOrderRequestID = viewModel.ID, ActionCode = viewModel.Action, Note = viewModel.ActionNote, CreatedByCooperatorID = AuthenticatedUser.WebUserID
                    });

                    if (viewModel.Action == "NRR_APPROVE")
                    {
                        emailRecipientList = grinGlobalService.GetEmailNotificationList(viewModel.ID);
                        grinGlobalService.SendEmail(viewModel.ID, "CAP", emailRecipientList);
                        resultContainer = grinGlobalService.AddWebOrderRequestAction(new WebOrderRequestAction {
                            WebOrderRequestID = viewModel.ID, ActionCode = viewModel.Action, Note = viewModel.ActionNote, CreatedByCooperatorID = AuthenticatedUser.WebUserID
                        });
                    }
                    else
                    if (viewModel.Action == "NRR_REJECT")
                    {
                        emailRecipientList = grinGlobalService.GetEmailNotificationList(viewModel.ID);
                        grinGlobalService.SendEmail(viewModel.ID, "CCL", emailRecipientList);
                        grinGlobalService.SendEmail(viewModel.ID, "RRJ", viewModel.WebCooperator.EmailAddress);
                        resultContainer = grinGlobalService.AddWebOrderRequestAction(new WebOrderRequestAction {
                            WebOrderRequestID = viewModel.ID, ActionCode = viewModel.Action, Note = viewModel.ActionNote, CreatedByCooperatorID = AuthenticatedUser.WebUserID
                        });
                    }
                    else
                    if (viewModel.Action == "NRR_INFO")
                    {
                        grinGlobalService.SendEmail(viewModel.ID, "RQI", viewModel.WebCooperator.EmailAddress);
                    }

                    if (resultContainer.ResultCode == ResultContainer.ResultCodeValue.Error.ToString())
                    {
                        throw new Exception("Error sending mail: " + resultContainer.ResultMessage + resultContainer.ResultDescription);
                    }
                }
                if ((viewModel.Action != "NRR_NOTE") && (viewModel.Action != "NRR_INFO"))
                {
                    return(RedirectToAction("Index", "WebOrder"));
                }
                else
                {
                    return(RedirectToAction("Edit", "WebOrder", new { id = viewModel.ID }));
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, ex.Message);
                return(RedirectToAction("InternalServerError", "Error"));
            }
        }