public ActionResult Advance(string account, string originator, string seller, string investor, string columnToSort, string sortDirection,GridSortOptions gridSortOptions, int? page)
 {
     if (Request.IsAjaxRequest())
     {
         gridSortOptions.Column = columnToSort;
         gridSortOptions.Direction = (sortDirection == "ASC") ? MvcContrib.Sorting.SortDirection.Ascending : MvcContrib.Sorting.SortDirection.Descending;
     }
     if (account == "account #")
         account = "";
     if (originator == "originator")
         originator = "";
     if (seller == "seller")
         seller = "";
     if (investor == "investor")
         investor = "";
     var dataQueries = new DataQueries();
     IQueryable<SearchResult> results = dataQueries.GetSearchResults(account, originator, seller, investor);
     //return PartialView("_BasicPartial", results);
     var pagedViewModel = new PagedViewModel<SearchResult>
     {
         ViewData = ViewData,
         Query = results,
         GridSortOptions = gridSortOptions,
         DefaultSortColumn = "ACCOUNT",
         Page = page,
         PageSize = 20,
     }
     .Setup();
     if (Request.IsAjaxRequest())
         return PartialView("_BasicPartial",pagedViewModel);
     return View("Basic",pagedViewModel);
 }
        public vwAccount Details(string accountNumber, string searchType)
        {
            DataQueries query = new DataQueries();
            vwAccount account = null;
            try
            {
                account = query.GetAccount(accountNumber, searchType);
                account.GUID = System.Guid.NewGuid().ToString();
            }
            catch (Exception ex)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content = new StringContent(string.Format("Error occur in GetAccount : {0}", ex.Message))
                });

            }
            if (account == null)
            {
                var resp = new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content = new StringContent(string.Format("No account information found for account number = {0}", accountNumber)),
                    ReasonPhrase = "Product ID Not Found"
                };
                throw new HttpResponseException(resp);
            }
            return account;
        }
 public ActionResult Basic(string basicSearchVal, string columnToSort, string sortDirection, GridSortOptions gridSortOptions, int? page)
 {
     if (Request.IsAjaxRequest())
     {
         gridSortOptions.Column = columnToSort;
         gridSortOptions.Direction = (sortDirection == "ASC") ? MvcContrib.Sorting.SortDirection.Ascending : MvcContrib.Sorting.SortDirection.Descending;
     }
     var dataQueries = new DataQueries();
     IQueryable<SearchResult> results = dataQueries.GetSearchResults(basicSearchVal);
     //return PartialView("_BasicPartial", results);
     var pagedViewModel = new PagedViewModel<SearchResult>
     {
         ViewData = ViewData,
         Query = results,
         GridSortOptions = gridSortOptions,
         DefaultSortColumn = "ACCOUNT",
         Page = page,
         PageSize = 50,
     }
     .Setup();
     if (Request.IsAjaxRequest())
         return PartialView("_BasicPartial", pagedViewModel);
     return View(pagedViewModel);
     //return PartialView("_BasicPartial",pagedViewModel);
 }
        public MSI_MediaRequestResponse Details(string id)
        {
            MSI_MediaRequestResponse data = null;
            DataQueries query = new DataQueries();
            try
            {
                data = query.GetMediaRequestResponse(id);
            }

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

            }
            if (data == null)
            {
                var resp = new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content = new StringContent(string.Format("No data available id = {0}", id)),
                    ReasonPhrase = "No request found"
                };
                throw new HttpResponseException(resp);
            }
            return data;
        }
        public ActionResult Export(string ReportType)
        {
            Response.AddHeader("Content-Type", "application/vnd.ms-excel");
            var dataQueries = new DataQueries();
            IEnumerable<MediaViewEditResult> results;
            ViewBag.ReportType = ReportType;

            switch (ReportType)
            {

                case "MediaNotSubmitted":
                    results = dataQueries.GetMediaNotSubmittedReportRecords("Yes");
                    return PartialView("_export", results);

                case "MediaNotConfirmed":
                    results = dataQueries.GetMediaNotSubmittedReportRecords("Yes");
                    return PartialView("_export", results);

                case "MediaNotReceived":
                    results = dataQueries.GetMediaNotSubmittedReportRecords("Yes");
                    return PartialView("_export", results);

                case "MediaNotForwarded":
                    results = dataQueries.GetMediaNotSubmittedReportRecords("Yes");
                    return PartialView("_export", results);

                default:
                    return PartialView();
            }
        }
        public ActionResult GetReportData(string ReportType)
        {
            var dataQueries = new DataQueries();
            ViewBag.ReportType = ReportType;
            IEnumerable<MediaViewEditResult> results;
            //For Report based on Report Type selection
            switch (ReportType)
            {
                case "MediaNotSubmitted":
                    results = dataQueries.GetMediaNotSubmittedReportRecords(null);
                    return PartialView("_mediaNotSubmitted", results);

                case "MediaNotConfirmed":
                    results = dataQueries.GetMediaNotSubmittedReportRecords(null);
                    return PartialView("_mediaNotConfirmed", results);

                case "MediaNotReceived":
                    results = dataQueries.GetMediaNotSubmittedReportRecords(null);
                    return PartialView("_mediaNotReceived", results);

                case "MediaNotForwarded":
                    results = dataQueries.GetMediaNotSubmittedReportRecords(null);
                    return PartialView("_mediaNotForwarded", results);

                default:
                    return PartialView();
            }
        }
        public ActionResult GetReportData(string ReportType)
        {
            var dataQueries = new DataQueries();
            ViewBag.ReportType = ReportType;
            IEnumerable<RecallViewEditResult> results;
            IEnumerable<DPSViewEditResult> resultsDPS;
            //For Report based on Report Type selection
            switch (ReportType)
            {
                case "RecallsUpload":
                    results = dataQueries.GetRecallsUploadReportRecords(null);
                    return PartialView("_recallsUpload", results);

                case "RecallsNotClosed":
                    results = dataQueries.GetRecallsNotClosedReportRecords(null);
                    return PartialView("_recallsNotClosed", results);

                case "RecallsNoNoteSent":
                    results = dataQueries.GetRecallsNoNoteSentReportRecords(null);
                    return PartialView("_recallsNoNoteSent", results);

                case "RecallsNotUploaded":
                    results = dataQueries.GetRecallsNotUploadedReportRecords(null);
                    return PartialView("_recallsNotUploaded", results);

                case "AddSellerCheck":
                    results = dataQueries.GetAddSellerCheckReportRecords(null);
                    return PartialView("_addSellerCheck", results);

                case "RecallsReceivable":
                    results = dataQueries.GetRecallsReceivableReportRecords(null, "RecallsReceivable");
                    return PartialView("_recallsReceivable", results);
                case "RecallsInvoiceLookup":
                    results = dataQueries.GetRecallsReceivableReportRecords(null, "RecallsInvoiceLookup");
                    return PartialView("_recallsInvoiceLookup", results);
                case "RecallsSellerCheckLookup":
                    results = dataQueries.GetRecallsReceivableReportRecords(null, "RecallsSellerCheckLookup");
                    return PartialView("_recallsSellerCheckLookup", results);
                case "RecallsPayable":
                    results = dataQueries.GetRecallsReceivableReportRecords(null, "RecallsPayable");
                    return PartialView("_recallsPayable", results);
                case "RecallsPaidByOurCheck":
                    results = dataQueries.GetRecallsReceivableReportRecords(null, "RecallsPaidByOurCheck");
                    return PartialView("_recallsPaidByOurCheck", results);
                case "DPSCheckDetail":
                    resultsDPS = dataQueries.GetDPSReportRecords(null, "DPSCheckDetail");
                    return PartialView("_dpsCheckDetails", resultsDPS);
                case "DPSPayable":
                    resultsDPS = dataQueries.GetDPSReportRecords(null, "DPSPayable");
                    return PartialView("_dpsPayable", resultsDPS);
                case "DPSPaidByOurCheck":
                    resultsDPS = dataQueries.GetDPSReportRecords(null, "DPSPaidByOurCheck");
                    return PartialView("_dpsPaidByOurCheck", resultsDPS);
                //

                default:
                    return PartialView();
            }
        }
        public ActionResult Export(string ReportType)
        {
            Response.AddHeader("Content-Type", "application/vnd.ms-excel");
            var dataQueries = new DataQueries();
            IEnumerable<RecallViewEditResult> results;
            IEnumerable<DPSViewEditResult> resultsDPS;
            ViewBag.ReportType = ReportType;

            switch (ReportType)
            {
                case "RecallsUpload":
                    results = dataQueries.GetRecallsUploadReportRecords("Yes");
                    return PartialView("_export", results);

                case "RecallsNotClosed":
                    results = dataQueries.GetRecallsNotClosedReportRecords("Yes");
                    return PartialView("_export", results);

                case "RecallsNoNoteSent":
                    results = dataQueries.GetRecallsNoNoteSentReportRecords("Yes");
                    return PartialView("_export", results);

                case "RecallsNotUploaded":
                    results = dataQueries.GetRecallsNotUploadedReportRecords("Yes");
                    return PartialView("_export", results);

                case "AddSellerCheck":
                    results = dataQueries.GetAddSellerCheckReportRecords("Yes");
                    return PartialView("_export", results);

                case "RecallsReceivable":
                    results = dataQueries.GetRecallsReceivableReportRecords("Yes", "RecallsReceivable");
                    return PartialView("_export", results);
                case "RecallsInvoiceLookup":
                    results = dataQueries.GetRecallsReceivableReportRecords("Yes", "RecallsInvoiceLookup");
                    return PartialView("_export", results);
                case "RecallsSellerCheckLookup":
                    results = dataQueries.GetRecallsReceivableReportRecords("Yes", "RecallsSellerCheckLookup");
                    return PartialView("_export", results);
                case "RecallsPayable":
                    results = dataQueries.GetRecallsReceivableReportRecords("Yes", "RecallsPayable");
                    return PartialView("_export", results);
                case "RecallsPaidByOurCheck":
                    results = dataQueries.GetRecallsReceivableReportRecords("Yes", "RecallsPaidByOurCheck");
                    return PartialView("_export", results);
                case "DPSCheckDetail":
                    resultsDPS = dataQueries.GetDPSReportRecords("Yes", "DPSCheckDetail");
                    return PartialView("_exportDPS", resultsDPS);
                case "DPSPayable":
                    resultsDPS = dataQueries.GetDPSReportRecords("Yes", "DPSPayable");
                    return PartialView("_exportDPS", resultsDPS);
                case "DPSPaidByOurCheck":
                    resultsDPS = dataQueries.GetDPSReportRecords("Yes", "DPSPaidByOurCheck");
                    return PartialView("_exportDPS", resultsDPS);

                default:
                    return PartialView();
            }
        }
 //GetExistingUploadMediaDetails
 public ActionResult Export(DateTime? StartDate, DateTime? EndDate, string PortfolioOwner, string Responsibility, string Account, string GUID)
 {
     Response.AddHeader("Content-Type", "application/vnd.ms-excel");
     var dataQueries = new DataQueries();
     IEnumerable<MediaViewEditResult> results = dataQueries.GetMediaViewEditRecordsExport(StartDate, EndDate, PortfolioOwner, Responsibility, Account, GUID);
     //return View();
     return PartialView("Export", results.ToList());
 }
        public MSI_ComplaintMain Get(string accountNumber, string agencyId, string userRole)
        {
            MSI_ComplaintMainRepository repository = null;
            MSI_ComplaintMain complaint = null; ;
            try
            {

                repository = new MSI_ComplaintMainRepository();
                IEnumerable<MSI_ComplaintMain> data = (from existingComplaint in repository.GetAll().Where(record => record.AgencyId == agencyId && record.Account == accountNumber)
                                                       select existingComplaint);

                if (data.Count() > 0)
                {
                    complaint = data.First();
                    if (!string.IsNullOrEmpty(userRole))
                    {
                        if (userRole == "user")
                            complaint.IsViewedByOwner = true;
                        if (userRole == "agency")
                            complaint.IsViewedByAgency = true;
                        repository.Update(complaint);
                    }
                }
                else
                {
                    complaint = new MSI_ComplaintMain();
                    complaint.AgencyId = agencyId;
                    complaint.ComplaintDate = DateTime.Now;
                    IEnumerable<MSI_Debtor> debtors = null;
                    DataQueries query = new DataQueries();
                    debtors = query.GetDebtors(accountNumber);

                    PopulateDebtInfo(debtors.First(), complaint);
                    //PopulateComplaintID(complaint);
                }
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException validationException)
            {
                foreach (System.Data.Entity.Validation.DbEntityValidationResult errorResult in validationException.EntityValidationErrors)
                {
                    foreach (System.Data.Entity.Validation.DbValidationError error in errorResult.ValidationErrors)
                    {
                        string data = error.ErrorMessage;
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return complaint;
        }
        public IEnumerable<vw_Account> Get(int? pageNo, int? pageSize, string userRole, string roleEntityValue = "", string firstOrLastName = "", string accountNumber = "", string creditorName = "", string accountOriginal = "", string phone = "")
        {
            IEnumerable<vw_Account> accounts = null;

            try
            {
                DataQueries query = new DataQueries();
                accounts = query.GetAccounts(firstOrLastName, accountNumber, creditorName, accountOriginal, roleEntityValue, phone, pageNo, pageSize, (UserRole)Enum.Parse(typeof(UserRole), userRole));
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return accounts;
        }
        public IEnumerable<vwAccount> Get(string nameSearch)
        {
            DataQueries query = new DataQueries();
            IEnumerable<vwAccount> accounts = null;
            try
            {
                accounts = query.GetAccounts(nameSearch);
            }
            catch (Exception ex)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content = new StringContent(string.Format("Error occur in GetAccount : {0}", ex.Message))
                });

            }
            return accounts;
        }
        public MSI_MediaRequestResponse Details(string accountNumber, string agency, Guid userId)
        {
            MSI_MediaRequestResponse data = null;
            DataQueries query = new DataQueries();
            try
            {
                data = query.GetMediaRequestResponse(accountNumber, agency, userId);
            }

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

            }
            return data;
        }
        public IEnumerable<MSI_Port_CollectionsTrans> GetCollectionsTransactions(string portfolioNumber, bool isOriginal, string userId = "")
        {
            string thisMethod = string.Format("{0}.{1}", thisClass, System.Reflection.MethodBase.GetCurrentMethod().Name);
            string logMessage = string.Format("{0}|Method incoming parameters portfolioNumber={1}, userId={2}", thisMethod, portfolioNumber, userId);
            LogHelper.Info(logMessage);

            IEnumerable<MSI_Port_CollectionsTrans> transactions = null;

            try
            {
                DataQueries query = new DataQueries();
                transactions = query.GetPortfolioCollectionsSummary(portfolioNumber, userId, isOriginal);
            }
            catch (Exception ex)
            {
                ErrorLogHelper.Error(logMessage, ex);
            }
            return transactions;
        }
        public IEnumerable<MSI_MediaRequestResponse> Get(string agency, Guid userId)
        {
            IEnumerable<MSI_MediaRequestResponse> data = null;
            DataQueries query = new DataQueries();
            try
            {
                data = from requestResponse in query.GetMediaRequestResponses(agency, userId).Where(record => record.AgencyId == agency)
                       select requestResponse;
            }

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

            }
            return data;
        }
 public ActionResult GetReportData(string ReportType)
 {
     var dataQueries = new DataQueries();
     IEnumerable<ComplianceViewResult> results;
     //For Report based on Report Type selection
     results = dataQueries.GetComplianceReportRecords(UserAgency, ReportType);
     ViewBag.ReportType = ReportType;
     return PartialView("_compliance"+ReportType, results);
 }
 public MediaRequest()
 {
     query = new DataQueries();
 }
        public ActionResult GetReportData(DateTime? StartDate, DateTime? EndDate, int? Company, string ToRange, string FromRange, string ReportType)
        {
            //Get Bockett Company Repository
            if (Company == null)
            {
                //We are just setting it up// This report does not require Company
                Company = 1;
            }
            //BockettCompanyRepository bockettCompRepo = new BockettCompanyRepository();
            //Find out Company Name
            //var _companyName = bockettCompRepo.GetAll().Where(x => x.Id == Company).SingleOrDefault().Company;
            var _companyName = "";
            RProductCodeRepository rProdCodeRepo = new RProductCodeRepository();
            if (Company == 1)
            {
                _companyName = rProdCodeRepo.GetAll().Where(x => x.ProductID == 1 || x.ProductID == 330).SingleOrDefault().PRODUCT_CODE;
            }
            else
            {
                _companyName = rProdCodeRepo.GetAll().Where(x => x.ProductID == Company).SingleOrDefault().PRODUCT_CODE;
            }

            var dataQueries = new DataQueries();
            //For Report based on Report Type selection
            switch (ReportType)
            {
                case "CashFlow":
                    //Get the View Repository
                    PortCashFlowRepository portCashFlowRepo = new PortCashFlowRepository();
                    //Get the Report Data
                    var _cashFlowreportData = from cashFlow in portCashFlowRepo.GetAll().Distinct()
                                              where cashFlow.Company == _companyName
                                              && cashFlow.ClosingDate >= StartDate
                                              && cashFlow.ClosingDate <= EndDate
                                              select cashFlow;
                    //return the data
                    return PartialView("_portfolioCashFlow", _cashFlowreportData.ToList());

                case "CashPosition":
                    //Get the View Repository
                    PortCashPositionRepository portCashPositionRepo = new PortCashPositionRepository();
                    //Get the Report Data
                    var _cashPositionreportData = portCashPositionRepo.GetAll().Distinct().Where(p => p.Company == _companyName);
                    return PartialView("_portfolioCashPosition", _cashPositionreportData.ToList());

                case "Purchases":

                    IEnumerable<Purchases> results = dataQueries.GetPurchases(StartDate, EndDate, _companyName);
                    return PartialView("_purchases", results);

                case "Sales":

                    IEnumerable<Sales> salesresults = dataQueries.GetSales(StartDate, EndDate, _companyName);
                    return PartialView("_sales", salesresults);

                case "CollectionsRecon":
                    //Get the View Repository
                    CollectionsReconRepository collectionsReconRepo = new CollectionsReconRepository();
                    //Get the Report Data
                    var _collectionsReconData = from collectionRecon in collectionsReconRepo.GetAll().Distinct()
                                                where collectionRecon.Company == _companyName
                                              && collectionRecon.ClosingDate >= StartDate
                                              && collectionRecon.ClosingDate <= EndDate
                                                select collectionRecon;
                    //return the data
                    return PartialView("_collectionsRecon", _collectionsReconData.ToList());

                case "PortfolioSummary":

                    IEnumerable<PortfolioSummary> portSummaryresults = dataQueries.GetPortfolioSummaryReports(_companyName);
                    return PartialView("_portfolioSummary", portSummaryresults);

                case "PortTransactions":

                    IEnumerable<PortfolioTransactions> portTransactionsresults = dataQueries.GetPortfolioTransactionsReports(_companyName);
                    return PartialView("_portfolioTransactions", portTransactionsresults);

                case "AddDPSCheck":
                    //Get the View Repository
                    AddDPSCheckRepository portDPSRepo = new AddDPSCheckRepository();
                    //Get the Report Data
                    var _portDPSAddCheckData = from addCheckData in portDPSRepo.GetAll().Distinct()
                                               where addCheckData.Company == _companyName
                                               select addCheckData;
                    //return the data
                    return PartialView("_portDPSAddCheck", _portDPSAddCheckData.ToList());

                default:
                    return PartialView();
            }
        }
 public ActionResult GetAllMediaRecords(DateTime? StartDate, DateTime? EndDate, int? Portfolio, string Responsibility, string Account, string GUID)
 {
     var dataQueries = new DataQueries();
     string _portfolioowner = null;
     RProductCodeRepository rProdCodeRepo = new RProductCodeRepository();
     if (Portfolio != null)
     {
         _portfolioowner = rProdCodeRepo.Get(x => x.ProductID == Portfolio).PRODUCT_CODE;
     }
     if (Responsibility == "undefined")
     {
         Responsibility = null;
     }
     if (GUID == "")
     {
         GUID = null;
     }
     if (Account == "")
     {
         Account = null;
     }
     IEnumerable<MediaViewEditResult> results = dataQueries.GetMediaViewEditRecords(StartDate, EndDate, _portfolioowner, Responsibility, Account, GUID);
     #region Store selected Criteria in the VieBag for Export to Excel use
     if (StartDate != null && EndDate != null)
     {
         ViewBag.StartDate = StartDate.ToString();
         ViewBag.EndDate = EndDate.ToString();
     }
     else
     {
         ViewBag.StartDate = null;
         ViewBag.EndDate = null;
     }
     if (_portfolioowner != null)
     {
         ViewBag.PortfolioOwner = _portfolioowner;
     }
     else
     {
         ViewBag.PortfolioOwner = null;
     }
     if (Responsibility != null)
     {
         ViewBag.Responsibility = Responsibility;
     }
     else
     {
         ViewBag.Responsibility = null;
     }
     if (Account != null)
     {
         ViewBag.Account = Account;
     }
     else
     {
         ViewBag.Account = null;
     }
     if (GUID != null)
     {
         ViewBag.GUID = GUID;
     }
     else
     {
         ViewBag.GUID = null;
     }
     #endregion
     return PartialView("_mediaRecords", results.ToList());
 }
 public Original()
 {
     query = new DataQueries();
 }
 public ActionResult GetPIMSDataForMedia(string nameSearch)
 {
     IEnumerable<vwAccount> data = new DataQueries().GetAccounts(nameSearch);
     return PartialView("_pimsMediaRecords", data);
 }
        public ActionResult Export(string ReportType)
        {
            Response.AddHeader("Content-Type", "application/vnd.ms-excel");
            var dataQueries = new DataQueries();
            IEnumerable<ComplianceViewResult> results;
            ViewBag.ReportType = ReportType;

            results = dataQueries.GetComplianceReportRecordsExport(UserAgency, ReportType);

            return PartialView("Export", results);
        }
        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 new void LoadChart()
        {
            DataQueries queries = null;
            //List<string> colorCodes = ColorCodeHelper.GetColorCodes();
            int index = 0;
            string[] colors = ConfigurationManager.AppSettings["colorCodes"].Split(new char[] { '#' });
            try
            {
                queries = new DataQueries();
                switch (this.Id)
                {
                    case ChartID.WorkStatusBreakdown:
                        //colors = new string[] {
                        //    "CC6600",
                        //    "9900CC",
                        //    "FF3300",
                        //    "0099FF",
                        //    "00CC66",
                        //    "FFFF00",
                        //    "CC6600",
                        //    "9900CC",
                        //    "800000",
                        //    "A52A2A",
                        //    "DC143c",
                        //    "FF6347",
                        //    "CD5C5C",
                        //    "F08080",
                        //    "FFA500",
                        //    "FFD700",
                        //    "B8860B",
                        //    "9ACD32",
                        //    "556B2F",
                        //    "00FF00",
                        //    "32CD32",
                        //    "90EE90",
                        //    "00FA9A",
                        //    "2E8B57",
                        //    "40E0D0",
                        //    "6495ED",
                        //    "1E90FF",
                        //    "191970",
                        //    "00008B",
                        //    "8A2BE2",
                        //    "8B008B",
                        //    "BA55D3",
                        //    "FF00FF",
                        //    "DA70D6",
                        //    "FF1493",
                        //    "F5F5DC",
                        //    "F5DEB3",
                        //    "8B4513",
                        //    "D2691E",
                        //    "D2B48C",
                        //    "708090",
                        //    "F5DEB3",
                        //    "BC8F8F",
                        //    "696969",
                        //    "808000",
                        //    "800080",
                        //    "008080",
                        //    "000080",
                        //    "FF0000",
                        //    "000000",
                        //    "FFFFFF"
                        //};
                        IEnumerable<PortfolioPieRpt> portfiloData = queries.GetPortfolioWorkStationDescription();
                        if (portfiloData != null)
                        {
                            int totalCount = portfiloData.Sum(r => int.Parse(r.Count));

                            foreach (var record in portfiloData)
                            {
                                this.SetsCollection.Add(new SetValue { Color = colors.GetValue(index).ToString(), Label = record.KeyText, Value = ((double.Parse(record.Count) / totalCount) * 100).ToString("f2") });
                                index++;
                            }

                        }
                        break;
                    case ChartID.PortfolioOwnerBreakdown:

                        portfiloData = queries.GetPortfolioOwner();
                        if (portfiloData != null)
                        {
                            int totalCount = portfiloData.Sum(r => int.Parse(r.Count));

                            foreach (var record in portfiloData)
                            {
                                this.SetsCollection.Add(new SetValue { Color = colors.GetValue(index).ToString(), Label = record.KeyText, Value = ((double.Parse(record.Count) / totalCount) * 100).ToString("f2") });
                                index++;
                            }

                        }
                        break;
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public JsonResult GetExistingMediaDetails(string account)
 {
     var dataQueries = new DataQueries();
     IEnumerable<MSI_MediaTracker> results = dataQueries.GetExistingUploadMediaDetails(account);
     //Send Back Response
     return Json(results.ToList(), JsonRequestBehavior.AllowGet);
 }
        public IEnumerable<MSI_Debtor> Get(string accountNumber)
        {
            IEnumerable<MSI_Debtor> debtors = null;

            try
            {
                DataQueries query = new DataQueries();
                debtors = query.GetDebtors(accountNumber);
            }
            catch (Exception ex)
            {
            }
            return debtors;
        }
 public ActionResult GetMediaRequests()
 {
     IEnumerable<MSI_MediaRequestResponse> data = null;
     DataQueries query = new DataQueries();
     try
     {
         data = query.GetMediaRequestResponses(UserAgency, UserId);
     }
     catch (Exception ex)
     {
     }
     return PartialView("_mediaRequests", data);
 }