public MSI_MediaRequestResponse Post(MSI_MediaRequestResponse submittedRequest)
        {
            string thisMethod = string.Format("{0}.{1}", thisClass, System.Reflection.MethodBase.GetCurrentMethod().Name);
            string logMessage = string.Format("{0}|Method incoming parameters RequestId={1}", thisMethod, submittedRequest.Id);
            LogHelper.Info(logMessage);

            DataQueries query = new DataQueries();
            bool isMediaRequestTypeUpdateMode = false;
            CascadeBusiness.MediaRequest business = new CascadeBusiness.MediaRequest();
            string userRole="";
            List<string> emailRecipients = new List<string>();
            List<string> userIds = new List<string>();
            try
            {
                if (string.IsNullOrEmpty(submittedRequest.Id))
                {
                    submittedRequest.Id = Guid.NewGuid().ToString();

                    foreach (MSI_MediaRequestTypes mediaReqType in submittedRequest.MSI_MediaRequestTypes)
                    {
                        if (mediaReqType.RequestStatusId.HasValue)
                        {
                            if (mediaReqType.RequestStatusId == (int)CascadeBusiness.MediaRequestStatus.Fulfilled)
                            {
                                isMediaRequestTypeUpdateMode = true;
                                business.PerfomPostFulfillmentProcess(mediaReqType.Id, mediaReqType.RespondedUserID.Value);
                            }
                            else if (mediaReqType.RequestStatusId == (int)CascadeBusiness.MediaRequestStatus.RequestComplete)
                            {
                                isMediaRequestTypeUpdateMode = true;
                                business.PerfomCompleteRequest(mediaReqType.Id, mediaReqType.RespondedUserID.Value);
                            }
                            else if (mediaReqType.RequestStatusId == (int)CascadeBusiness.MediaRequestStatus.OriginatorUpdateRequested ||
                                mediaReqType.RequestStatusId == (int)CascadeBusiness.MediaRequestStatus.OriginatorInProcess ||
                                mediaReqType.RequestStatusId == (int)CascadeBusiness.MediaRequestStatus.NoOriginatorMediaAvailable ||
                                mediaReqType.RequestStatusId == (int)CascadeBusiness.MediaRequestStatus.OriginatorFulfilled ||
                                mediaReqType.RequestStatusId == (int)CascadeBusiness.MediaRequestStatus.OriginatorResearching ||
                                mediaReqType.RequestStatusId == (int)CascadeBusiness.MediaRequestStatus.SentToOriginator
                                )
                            {
                                isMediaRequestTypeUpdateMode = true;
                                business.PerfomUpdateRequest(mediaReqType.Id, mediaReqType.RespondedUserID.Value, mediaReqType.RequestStatusId.Value);
                            }
                        }
                        else
                        {
                            // When Initial Media request through Agency to Media Admin or MediaAdmin to originator
                            userRole = Roles.GetRolesForUser(Membership.GetUser(submittedRequest.RequestedByUserId).UserName).Single();
                            mediaReqType.Id = Guid.NewGuid().ToString();
                            mediaReqType.RequestedId = submittedRequest.Id;
                            mediaReqType.RequestStatusId = business.EvaluateMediaRequestStatus(CascadeBusiness.MediaRequestLevel.Initiate, (CascadeBusiness.UserRoles)Enum.Parse(typeof(CascadeBusiness.UserRoles), userRole, true));
                            mediaReqType.LastUpdatedDate = DateTime.Now;
                            mediaReqType.LastUpdatedBy = submittedRequest.RequestedByUserId;
                        }
                    }
                    submittedRequest.RequestedDate = DateHelper.GetDateWithTimings(submittedRequest.RequestedDate);
                    if (!isMediaRequestTypeUpdateMode)
                    {
                        business.SaveMediaRequestResponse(submittedRequest);

                        business.PerfomPreFulfillmentProcess(submittedRequest.ACCOUNT, null);

                        #region SentToOwner OR SentToOriginator Notification

                        if (userRole == CascadeBusiness.UserRoles.mediaAdmin.ToString())
                        {
                            emailRecipients.Add(System.Configuration.ConfigurationManager.AppSettings["emailOriginatorAccount"]);
                            userIds.Add(Membership.GetUser(Membership.GetUserNameByEmail(System.Configuration.ConfigurationManager.AppSettings["emailOriginatorAccount"])).ProviderUserKey.ToString());
                        }
                        else if (userRole == CascadeBusiness.UserRoles.agency.ToString())
                        {
                            emailRecipients = MemberShipHelper.GetEmailAddressUserInRole(CascadeBusiness.UserRoles.mediaAdmin.ToString());
                            userIds = MemberShipHelper.GetUserIdsUserInRole(CascadeBusiness.UserRoles.mediaAdmin.ToString());
                        }
                        if (emailRecipients.Count > 0)
                        {
                            CascadeBusiness.NotificationMessage message = business.GetInitialMediaRequestMessage(submittedRequest);
                            Emailer.SendMessage(Emailer.CreateMessage(message.Subject, emailRecipients, message.BodyText, ""));
                            business.SaveMessageNotification(message, userIds);
                        }

                        #endregion
                    }
                    else
                    {
                        #region OriginatorUpdateRequested Notifications
                        MSI_MediaRequestTypes requestType = submittedRequest.MSI_MediaRequestTypes.Where(record => record.RequestStatusId == (int)CascadeBusiness.MediaRequestStatus.OriginatorUpdateRequested).FirstOrDefault();
                        if (requestType != null)
                        {
                            userRole = Roles.GetRolesForUser(Membership.GetUser(requestType.RespondedUserID.Value).UserName).Single();

                            if (userRole == CascadeBusiness.UserRoles.mediaAdmin.ToString())
                            {
                                emailRecipients.Add(System.Configuration.ConfigurationManager.AppSettings["emailOriginatorAccount"]);
                                userIds.Add(Membership.GetUser(Membership.GetUserNameByEmail(System.Configuration.ConfigurationManager.AppSettings["emailOriginatorAccount"])).ProviderUserKey.ToString());
                            }
                            else if (userRole == CascadeBusiness.UserRoles.agency.ToString())
                            {
                                emailRecipients = MemberShipHelper.GetEmailAddressUserInRole(CascadeBusiness.UserRoles.mediaAdmin.ToString());
                                userIds = MemberShipHelper.GetUserIdsUserInRole(CascadeBusiness.UserRoles.mediaAdmin.ToString());
                            }
                            if (emailRecipients.Count > 0)
                            {
                                CascadeBusiness.NotificationMessage message = business.GetUpdateRequestedToOriginatorMessage(submittedRequest.MSI_MediaRequestTypes.Where(record => record.RequestStatusId== (int)CascadeBusiness.MediaRequestStatus.OriginatorUpdateRequested));
                                Emailer.SendMessage(Emailer.CreateMessage(message.Subject, emailRecipients, message.BodyText, ""));
                                business.SaveMessageNotification(message, userIds);
                            }

                        }
                        #endregion

                        #region Fulfilled Notifications
                        requestType = null;
                        requestType = submittedRequest.MSI_MediaRequestTypes.Where(record => record.RequestStatusId == (int)CascadeBusiness.MediaRequestStatus.Fulfilled).FirstOrDefault();
                        if (requestType != null)
                        {
                            string userEmail = MemberShipHelper.GetEmailAddress(requestType.RequestedUserID.Value);
                            if (!string.IsNullOrEmpty(userEmail))
                            {
                                emailRecipients.Add(userEmail);
                                userIds.Add(requestType.RequestedUserID.ToString());
                            }
                            if (emailRecipients.Count > 0)
                            {
                                CascadeBusiness.NotificationMessage message = business.GetRequestFulfillmentMessage(submittedRequest.MSI_MediaRequestTypes.Where(record => record.RequestStatusId == (int)CascadeBusiness.MediaRequestStatus.Fulfilled));
                                Emailer.SendMessage(Emailer.CreateMessage(message.Subject, emailRecipients, message.BodyText, ""));
                                business.SaveMessageNotification(message, userIds);
                            }

                        }

                        #endregion

                        #region Sent To Originator Notification
                        requestType = null;
                        requestType = submittedRequest.MSI_MediaRequestTypes.Where(record => record.RequestStatusId == (int)CascadeBusiness.MediaRequestStatus.SentToOriginator).FirstOrDefault();
                        if (requestType != null)
                        {
                            emailRecipients.Add(System.Configuration.ConfigurationManager.AppSettings["emailOriginatorAccount"]);
                            userIds.Add(Membership.GetUser(Membership.GetUserNameByEmail(System.Configuration.ConfigurationManager.AppSettings["emailOriginatorAccount"])).ProviderUserKey.ToString());

                            if (emailRecipients.Count > 0)
                            {
                                CascadeBusiness.NotificationMessage message = business.GetInitialMediaRequestMessage(submittedRequest.MSI_MediaRequestTypes.Where(record => record.RequestStatusId == (int)CascadeBusiness.MediaRequestStatus.SentToOriginator));
                                Emailer.SendMessage(Emailer.CreateMessage(message.Subject, emailRecipients, message.BodyText, ""));
                                business.SaveMessageNotification(message, userIds);
                            }

                        }

                        #endregion
                    }

                }
                else
                {
                    MSI_MediaRequestTypes mediaType = null;
                    foreach (MSI_MediaRequestTypes mediaReqType in submittedRequest.MSI_MediaRequestTypes)
                    {
                        mediaType = query.GetMediaRequestdType(submittedRequest.Id, mediaReqType.TypeId);
                        if (mediaType == null)
                        {
                            userRole = Roles.GetRolesForUser(Membership.GetUser(submittedRequest.RequestedByUserId).UserName).Single();
                            mediaReqType.Id = Guid.NewGuid().ToString();
                            mediaReqType.RequestedId = submittedRequest.Id;
                            mediaReqType.RequestStatusId = business.EvaluateMediaRequestStatus(CascadeBusiness.MediaRequestLevel.Initiate, (CascadeBusiness.UserRoles)Enum.Parse(typeof(CascadeBusiness.UserRoles), userRole, true));
                            mediaReqType.LastUpdatedDate = DateTime.Now;
                            mediaReqType.LastUpdatedBy = submittedRequest.RequestedByUserId;

                            business.SaveMediaRequestdType(mediaReqType);

                            business.PerfomPreFulfillmentProcess(submittedRequest.ACCOUNT, null);
                        }
                        else
                        {
                        }
                        mediaType = null;

                    }

                    mediaType = submittedRequest.MSI_MediaRequestTypes.Where(record => record.RequestStatusId == (int)CascadeBusiness.MediaRequestStatus.SentToOriginator || record.RequestStatusId == (int)CascadeBusiness.MediaRequestStatus.SentToOwner).FirstOrDefault();
                    if (mediaType != null)
                    {
                        #region SentToOwner OR SentToOriginator Notification

                        if (userRole == CascadeBusiness.UserRoles.mediaAdmin.ToString())
                        {
                            emailRecipients.Add(System.Configuration.ConfigurationManager.AppSettings["emailOriginatorAccount"]);
                            userIds.Add(Membership.GetUser(Membership.GetUserNameByEmail(System.Configuration.ConfigurationManager.AppSettings["emailOriginatorAccount"])).ProviderUserKey.ToString());
                        }
                        else if (userRole == CascadeBusiness.UserRoles.agency.ToString())
                        {
                            emailRecipients = MemberShipHelper.GetEmailAddressUserInRole(CascadeBusiness.UserRoles.mediaAdmin.ToString());
                            userIds = MemberShipHelper.GetUserIdsUserInRole(CascadeBusiness.UserRoles.mediaAdmin.ToString());
                        }
                        if (emailRecipients.Count > 0)
                        {
                            CascadeBusiness.NotificationMessage message = business.GetInitialMediaRequestMessage(submittedRequest);
                            Emailer.SendMessage(Emailer.CreateMessage(message.Subject, emailRecipients, message.BodyText, ""));
                            business.SaveMessageNotification(message, userIds);
                        }

                        #endregion
                    }

                }
            }

            catch (Exception ex)
            {
                ErrorLogHelper.Error(logMessage, ex);
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content = new StringContent(string.Format("Error occur in POST MediaRequest : {0}", ex.Message))
                });

            }

            return submittedRequest;
        }
        public ActionResult UploadAllDocuments(IEnumerable<HttpPostedFileBase> AfdvtIssuerfiles, IEnumerable<HttpPostedFileBase> AfdvtSellerfiles,
            IEnumerable<HttpPostedFileBase> Applicationfiles, IEnumerable<HttpPostedFileBase> Contactfiles,
            IEnumerable<HttpPostedFileBase> Statementfiles, IEnumerable<HttpPostedFileBase> ChargeOffStmtfiles, IEnumerable<HttpPostedFileBase> RightOfCurefiles,
            IEnumerable<HttpPostedFileBase> BalanceLtrfiles, IEnumerable<HttpPostedFileBase> NoticeOfIntentfiles,
            IEnumerable<HttpPostedFileBase> CardHolderAgrmtfiles, IEnumerable<HttpPostedFileBase> TermAndCndfiles)
        {
            //Collect information from the hiddern fields
            string PIMSAcctNumber = Request.Form["hdnpimsAccountNumber"];
            string OrigAcctNumber = Request.Form["hdnoriginalAccountNumber"];
            string hdnstatementStDt = Request.Form["hdnstatementStDt"];
            string hdnstatementEndDt = Request.Form["hdnstatementEndDt"];
            string hdnRedirectAction = Request.Form["hdnRedirectAction"];
            //Get the Object
            MSI_MediaTracker _mediaTracker = new MSI_MediaTracker();
            //Get the necessary Information
            _mediaTracker.Account = PIMSAcctNumber;
            _mediaTracker.OriginalAccount = OrigAcctNumber;
            _mediaTracker.CreatedDate = DateTime.Now;
            _mediaTracker.CreatedBy = UserId.ToString();
            _mediaTracker.IsActive = true;
            //For Files
            #region [[ Affedavit(Issuer) ]]
            if (AfdvtIssuerfiles != null)
            {
                if (AfdvtIssuerfiles.Count() >= 1)
                {
                    PerformFileUploadOperation(_mediaTracker, 1, AfdvtIssuerfiles);
                }
            }
            #endregion

            #region [[ Affedavit(Seller) ]]
            if (AfdvtSellerfiles != null)
            {
                if (AfdvtSellerfiles.Count() >= 1)
                {
                    PerformFileUploadOperation(_mediaTracker, 2, AfdvtSellerfiles);
                }
            }
            #endregion

            #region [[ Application ]]
            if (Applicationfiles != null)
            {
                if (Applicationfiles.Count() >= 1)
                {
                    PerformFileUploadOperation(_mediaTracker, 3, Applicationfiles);
                }
            }
            #endregion

            #region [[ Contact ]]
            if (Contactfiles != null)
            {
                if (Contactfiles.Count() >= 1)
                {
                    PerformFileUploadOperation(_mediaTracker, 4, Contactfiles);
                }
            }
            #endregion

            #region [[ Charge of Statement ]]
            if (ChargeOffStmtfiles != null)
            {
                if (ChargeOffStmtfiles.Count() >= 1)
                {
                    PerformFileUploadOperation(_mediaTracker, 6, ChargeOffStmtfiles);
                }
            }
            #endregion

            #region [[ Right of Cure ]]
            if (RightOfCurefiles != null)
            {
                if (RightOfCurefiles.Count() >= 1)
                {
                    PerformFileUploadOperation(_mediaTracker, 7, RightOfCurefiles);
                }
            }
            #endregion

            #region [[ Balance Letter ]]
            if (BalanceLtrfiles != null)
            {
                if (BalanceLtrfiles.Count() >= 1)
                {
                    PerformFileUploadOperation(_mediaTracker, 8, BalanceLtrfiles);
                }
            }
            #endregion

            #region [[ Notice of Intent ]]
            if (NoticeOfIntentfiles != null)
            {
                if (NoticeOfIntentfiles.Count() >= 1)
                {
                    PerformFileUploadOperation(_mediaTracker, 9, NoticeOfIntentfiles);
                }
            }
            #endregion

            #region [[ Card Holder Agreement ]]
            if (CardHolderAgrmtfiles != null)
            {
                if (CardHolderAgrmtfiles.Count() >= 1)
                {
                    PerformFileUploadOperation(_mediaTracker, 10, CardHolderAgrmtfiles);
                }
            }
            #endregion

            #region [[ Terms and Conditions ]]
            if (TermAndCndfiles != null)
            {
                if (TermAndCndfiles.Count() >= 1)
                {
                    PerformFileUploadOperation(_mediaTracker, 11, TermAndCndfiles);
                }
            }
            #endregion

            //IMPORTANT: Do it at the end so TypeConstraints are added for only Statement type media
            #region [[ Statement ]]
            if (Statementfiles != null)
            {
                if (Statementfiles.Count() >= 1)
                {
                    if (hdnstatementStDt != "" && hdnstatementEndDt != "")
                    {
                        _mediaTracker.TypeConstraints = hdnstatementStDt + ":" + hdnstatementEndDt;
                    }
                    PerformFileUploadOperation(_mediaTracker, 5, Statementfiles);
                }
            }
            #endregion

            CascadeBusiness.MediaRequest business = new CascadeBusiness.MediaRequest();
            business.PerfomPreFulfillmentProcess(PIMSAcctNumber, UserId);
            //Exit
            if (string.IsNullOrEmpty(hdnRedirectAction))
                return RedirectToAction("Index", "Home");
            else
                return RedirectToAction(hdnRedirectAction, "Media");
        }
 public void MediaRequestStatusUpdate(string id)
 {
     CascadeBusiness.MediaRequest business = new CascadeBusiness.MediaRequest();
     business.PerformRequestStatusUpdate(id, UserId);
 }
 public ActionResult MediaDownloaded(string id)
 {
     CascadeBusiness.MediaRequest business = new CascadeBusiness.MediaRequest();
     business.PerformRequestDownloaded(id, UserId);
     return View("MediaRequestReadyDownload");
 }
 public ActionResult GetMediaRequestReadyDownload()
 {
     CascadeBusiness.MediaRequest business = new CascadeBusiness.MediaRequest();
     IEnumerable<MediaRequestTypes> data = business.GetDownloadable(UserAgency, UserId);
     return PartialView("_mediaRequestReadyDownload", data);
 }
 public ActionResult GetMediaNotFulfilled(string id)
 {
     CascadeBusiness.MediaRequest business = new CascadeBusiness.MediaRequest();
     IEnumerable<MediaRequestTypes> data;
     PartialViewResult returnView = null;
     if (id == "ByAgency")
     {
         ViewBag.RoleBasedHeaderTitle = (UserRoles.Contains("agency")) ? "Media Request" : "Media Fulfillment";
         data = business.GetNotFulfilled(UserAgency, UserId);
         returnView = PartialView("_mediaRequestNotFulfilled", data);
     }
     else if (id == "All")
     {
         ViewBag.RoleBasedHeaderTitle = (UserRoles.Contains("agency")) ? "Media Request" : "Media Fulfillment";
         data = business.GetNotCimpleted();
         returnView = PartialView("_mediaRequestAllNotFulfilled", data);
     }
     return returnView;
 }