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 MSI_ComplaintMain Post(MSI_ComplaintMain complaint)
        {
            MSI_ComplaintMain complaintToSave = null;
            MSI_ComplaintMainRepository repository = null;
            bool editingRequired = true;
            try
            {

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

                if (data.Count() > 0)
                {
                    complaintToSave = data.First();
                }
                else
                {
                    editingRequired = false;
                    complaintToSave = new MSI_ComplaintMain();
                }

                complaintToSave.AgencyId = complaint.AgencyId;
                complaintToSave.Account = complaint.Account;
                complaintToSave.LastName = complaint.LastName;
                complaintToSave.FirstName = complaint.FirstName;
                complaintToSave.Address = complaint.Address;
                complaintToSave.City = complaint.City;
                complaintToSave.State = complaint.State;
                complaintToSave.Zip = complaint.Zip;
                complaintToSave.HomePhone = complaint.HomePhone;
                complaintToSave.WorkPhone = complaint.WorkPhone;
                complaintToSave.MobilePhone = complaint.MobilePhone;
                complaintToSave.LastFourSSN = complaint.LastFourSSN;
                complaintToSave.DebtorIdentityVerified = complaint.DebtorIdentityVerified;
                complaintToSave.ContactMethodId = complaint.ContactMethodId;
                complaintToSave.ContactTimeId = complaint.ContactTimeId;
                complaintToSave.CreditorName = complaint.CreditorName;
                complaintToSave.DebtProductId = complaint.DebtProductId;
                complaintToSave.DebtPurchaseBalance = complaint.DebtPurchaseBalance;
                complaintToSave.DebtCurrentBalance = complaint.DebtCurrentBalance;
                complaintToSave.DisputeDebt = complaint.DisputeDebt;
                complaintToSave.DisputeDebtAmount = complaint.DisputeDebtAmount;
                complaintToSave.DisputeDebtDueDate = complaint.DisputeDebtDueDate;
                complaintToSave.ComplaintID = complaint.ComplaintID;
                complaintToSave.ComplaintDate = complaint.ComplaintDate;
                complaintToSave.ComplaintReceivedByMethodId = complaint.ComplaintReceivedByMethodId;
                complaintToSave.ComplaintIssueId = complaint.ComplaintIssueId;
                complaintToSave.ComplaintNotes = complaint.ComplaintNotes;
                complaintToSave.ComplaintSubmitedToAgency = complaint.ComplaintSubmitedToAgency;
                complaintToSave.ComplaintSubmitedToAgencyDate = complaint.ComplaintSubmitedToAgencyDate;
                complaintToSave.MoreInfoReqdFromDebtor = complaint.MoreInfoReqdFromDebtor;
                complaintToSave.MoreInfoRequestedDate = complaint.MoreInfoRequestedDate;
                complaintToSave.MoreInfoRequested = complaint.MoreInfoRequested;
                complaintToSave.MoreInfoReceivedFromDebtor = complaint.MoreInfoReceivedFromDebtor;
                complaintToSave.MoreInfoReceivedDate = complaint.MoreInfoReceivedDate;
                complaintToSave.MoreInfoReceived = complaint.MoreInfoReceived;
                complaintToSave.ComplaintSubmittedToOwner = complaint.ComplaintSubmittedToOwner;
                complaintToSave.ComplaintSubmittedDate = complaint.ComplaintSubmittedDate;
                complaintToSave.TimeToSubmitDays = complaint.TimeToSubmitDays;
                complaintToSave.MoreInfoFromAgency = complaint.MoreInfoFromAgency;
                complaintToSave.MoreInfoFromAgencyRequestedDate = complaint.MoreInfoFromAgencyRequestedDate;
                complaintToSave.MoreInfoFromAgencyRequested = complaint.MoreInfoFromAgencyRequested;
                complaintToSave.MoreInfoFromAgencyReceived = complaint.MoreInfoFromAgencyReceived;
                complaintToSave.MoreInfoFromAgencyReceivedDate = complaint.MoreInfoFromAgencyReceivedDate;
                complaintToSave.OwnerResponseId = complaint.OwnerResponseId;
                complaintToSave.OwnerResponseDate = complaint.OwnerResponseDate;
                complaintToSave.OwnerResponseDays = complaint.OwnerResponseDays;
                if (complaint.AgencyResponseToDebtorDate.HasValue)
                    complaintToSave.AgencyResponseToDebtorDate = complaint.AgencyResponseToDebtorDate;
                complaintToSave.TotalResponseTimeDays = complaint.TotalResponseTimeDays;
                complaintToSave.DebtorAgree = complaint.DebtorAgree;
                complaintToSave.NeedFurtherAction = complaint.NeedFurtherAction;
                complaintToSave.FinalActionStepId = complaint.FinalActionStepId;
                complaintToSave.IsViewedByOwner = complaint.IsViewedByOwner;
                complaintToSave.CreatedBy = complaint.CreatedBy;
                complaintToSave.IsViewedByAgency = complaint.IsViewedByAgency;

                if (editingRequired)
                {
                    repository.Update(complaintToSave);
                }
                else
                {
                    complaintToSave.ComplaintSubmitedToAgency = true;
                    complaintToSave.ComplaintSubmitedToAgencyDate = DateTime.Now;
                    repository.Add(complaintToSave);
                }
            }
            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 complaintToSave;
        }
 public ActionResult UploadDocument()
 {
     string account = Request.Form["hdnAccount"];
     string agency = Request.Form["hdnAgency"];
     string complaintDocument, debtOwnerProcessDocument;
     complaintDocument = Request.Files["complaintDocument"].FileName;
     debtOwnerProcessDocument = Request.Files["debtOwnerProcessDocument"].FileName;
     Cascade.Data.Repositories.MSI_ComplaintMainRepository repository = new MSI_ComplaintMainRepository();
     Cascade.Data.Models.MSI_ComplaintMain complaint = (from existingComplaint in repository.GetAll().Where(record => record.AgencyId == agency && record.Account == account)
                                                select existingComplaint).First();
     if (!string.IsNullOrEmpty(complaintDocument))
     {
         complaint.ComplaintDocument = fileProcessor.SaveUploadedFile(Request.Files["complaintDocument"]) + "_" + complaintDocument;
         repository.Update(complaint);
     }
     if (!string.IsNullOrEmpty(debtOwnerProcessDocument))
     {
         complaint.DebtOwnerProcessDocument = fileProcessor.SaveUploadedFile(Request.Files["debtOwnerProcessDocument"]) + "_" + debtOwnerProcessDocument;
         repository.Update(complaint);
     }
     return RedirectToAction("ViewEdit", "Home", new { id = account, agency = agency });
 }