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; }