public IHttpActionResult GetAccountById(int?Id) { var response = new DataResponse <EntityAccount>(); var repository = new RepositoryAccount(); if (Id.HasValue) { response = repository.GetAccountById(Id.Value); } else { response.Model = new EntityAccount(); response.Model.Practice = new EntityPractice(); } return(Ok <DataResponse>(response)); }
public FileStreamResult pdf(PDFModel PDFModel) { if (PDFModel.IsAccount) { var repository = new RepositoryAccount(); var model = repository.GetAccountById(PDFModel.Id).Model; ViewData.Model = new PDFViewModel { Practice = model.Practice, Providers = model.Practice.Providers, Address = model.Practice.Address, CreatedByName = model.CreatedByName, CreatedOn = model.CreatedOn, EnrolledDate = model.EnrolledDate, Rep = model.Rep, }; PDFModel.Content = RazorHelper.RenderRazorViewToString("~/Views/Shared/accountPDF.cshtml", this); } else { var repository = new RepositoryLead(); var model = repository.GetLeadById(PDFModel.Id).Model; ViewData.Model = new PDFViewModel { Practice = model.Practice, Providers = model.Practice.Providers, Address = model.Practice.Address, CreatedByName = model.CreatedByName, CreatedOn = model.CreatedOn, Rep = model.Rep, }; PDFModel.Content = RazorHelper.RenderRazorViewToString("~/Views/Shared/leadPDF.cshtml", this); } var accountPdfContent = @"<?xml version=""1.0"" encoding=""UTF-8""?> <!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd""> <html xmlns=""http://www.w3.org/1999/xhtml"" xml:lang=""en"" lang=""en""> <head> <title>Account Details</title> </head> <body>" + PDFModel.Content + "</body></html>"; var leadPdfContent = @"<?xml version=""1.0"" encoding=""UTF-8""?> <!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd""> <html xmlns=""http://www.w3.org/1999/xhtml"" xml:lang=""en"" lang=""en""> <head> <title>Lead Details</title> </head> <body>" + PDFModel.Content + "</body></html>"; var bytes = System.Text.Encoding.UTF8.GetBytes(PDFModel.IsAccount ? accountPdfContent : leadPdfContent); using (var input = new MemoryStream(bytes)) { var output = new MemoryStream(); var document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 0, 0, 0, 0); var writer = PdfWriter.GetInstance(document, output); writer.CloseStream = false; document.Open(); var xmlWorker = XMLWorkerHelper.GetInstance(); xmlWorker.ParseXHtml(writer, document, input, default(Stream)); document.Close(); output.Position = 0; return(new FileStreamResult(output, "application/pdf")); } }
public IHttpActionResult GetVmAccountObject(int?id) { var response = new DataResponse <VMAccount>(); if (id.HasValue) { var repository = new RepositoryAccount(); var model = repository.GetAccountById(id.Value).Model; if (model != null) { var PracticeAddress = model.Practice.Address.Where(a => a.AddressTypeId == 1).Select(a => new VMLocation { AddressId = a.AddressId, PhoneId = a.Phone.Count() > 0 ? a.Phone.First().PhoneId : 0, AddressLine1 = a.Line1, AddressLine2 = a.Line2, PhoneNumber = a.Phone.Count() > 0 ? a.Phone.First().PhoneNumber : null, Extension = a.Phone.Count() > 0 ? a.Phone.First().Extension : null, City = a.City, Fax = a.Fax, StateId = a.StateId, Zip = a.Zip, AddressTypeId = a.TypeId, }).FirstOrDefault(); var practiceContact = model.Practice.Contact.FirstOrDefault(a => a.AddressId == (PracticeAddress != null ? PracticeAddress.AddressId : 0)); if (practiceContact != null) { PracticeAddress.ManagerName = practiceContact.ManagerName; PracticeAddress.ManagerEmail = practiceContact.ManagerEmail; PracticeAddress.ManagerPhone = practiceContact.ManagerPhone; PracticeAddress.BillingContact = practiceContact.BillingContact; PracticeAddress.BillingContactEmail = practiceContact.BillingContactEmail; PracticeAddress.BillingContactPhone = practiceContact.BillingContactPhone; PracticeAddress.WorkingHours = practiceContact.officedayshrs; } int?SpecialityTypeId = model.Practice.SpecialityTypeId, RepId = model.Rep.Id, RepGroupId = model.Rep.GroupId; response.Model = new VMAccount { Id = id.Value, EnrolledDate = model.EnrolledDate, PracticeName = model.Practice.Name, PracticeId = model.Practice.Id, SpecialityTypeId = SpecialityTypeId == null ? 0 : (int)SpecialityTypeId, ServiceInterest = model.LeadServiceIntrest, RepGroupId = RepGroupId == null ? 0 : (int)RepGroupId, RepId = RepId == null ? 0 : (int)RepId, AddressId = PracticeAddress == null ? 0 : PracticeAddress.AddressId, PracticeAddressLine1 = PracticeAddress == null ? null : PracticeAddress.AddressLine1, PracticeAddressLine2 = PracticeAddress == null ? null : PracticeAddress.AddressLine2, PhoneNumber = PracticeAddress == null ? null : PracticeAddress.PhoneNumber, PhoneExtension = PracticeAddress == null ? null : PracticeAddress.Extension, City = PracticeAddress == null ? null : PracticeAddress.City, Fax = PracticeAddress == null ? null : PracticeAddress.Fax, StateId = PracticeAddress == null ? null : PracticeAddress.StateId, Zip = PracticeAddress == null ? null : PracticeAddress.Zip, LeadSourceId = model.LeadSourceId, NewSpectialityName = model.Practice.SpecialityType, SpecialityId = model.Practice.Specialities.Count() == 1 ? model.Practice.Specialities.First().PracticeSpecialityId : 0, SpecialityIds = model.Practice.Specialities.Count() > 0 ? model.Practice.Specialities.Select(a => a.PracticeSpecialityId.ToString()).ToArray() : null, EnrolledServices = ((string[])model.ServiceIds), MethodOfContact = model.Practice.ContactPreferenceId, ReportDeliveryEmail = model.Practice.ReportDeliveryEmail, ReportDeliveryFax = model.Practice.ReportDeliveryFax, ManagerName = practiceContact != null ? practiceContact.ManagerName : null, ManagerEmail = practiceContact != null ? practiceContact.ManagerEmail : null, ManagerPhone = practiceContact != null ? practiceContact.ManagerPhone : null, BillingContact = practiceContact != null ? practiceContact.BillingContact : null, BillingContactEmail = practiceContact != null ? practiceContact.BillingContactEmail : null, BillingContactPhone = practiceContact != null ? practiceContact.BillingContactPhone : null, WorkingHours = practiceContact != null ? practiceContact.officedayshrs : null }; response.Model.Locations = model.Practice.Address.Where(s => s.AddressTypeId != 1).Select(a => new VMLocation { AddressId = a.AddressId, PhoneId = a.Phone.Count() > 0 ? a.Phone.FirstOrDefault().PhoneId : 0, AddressLine1 = a.Line1, AddressLine2 = a.Line2, PhoneNumber = a.Phone.Count() > 0 ? a.Phone.First().PhoneNumber : null, Extension = a.Phone.Count() > 0 ? a.Phone.First().Extension : null, City = a.City, StateId = a.StateId, Zip = a.Zip, Fax = a.Fax, AddressTypeId = a.TypeId, }).ToList(); foreach (var location in response.Model.Locations) { var contact = model.Practice.Contact.FirstOrDefault(a => a.AddressId == location.AddressId); if (contact != null) { location.ManagerName = contact.ManagerName; location.ManagerEmail = contact.ManagerEmail; location.ManagerPhone = contact.ManagerPhone; location.BillingContact = contact.BillingContact; location.BillingContactEmail = contact.BillingContactEmail; location.BillingContactPhone = contact.BillingContactPhone; location.WorkingHours = contact.officedayshrs; } } response.Model.Providers = model.Practice.Providers.Select(a => new VMProvider { Id = a.ProviderId, DegreeName = a.DegreeName, DegreeId = a.DegreeId, FirstName = a.FirstName, LastName = a.LastName, MiddleName = a.MiddleName, NPI = a.NPI, Location = a.Address != null ? new VMLocation { AddressId = a.Address.AddressId, PhoneId = a.Address.Phone.Count() > 0 ? a.Address.Phone.FirstOrDefault().PhoneId : 0, AddressLine1 = a.Address.Line1, AddressLine2 = a.Address.Line2, PhoneNumber = a.Address.Phone.Count() > 0 ? a.Address.Phone.First().PhoneNumber : null, Extension = a.Address.Phone.Count() > 0 ? a.Address.Phone.First().Extension : null, City = a.Address.City, ManagerName = a.Address.ManagerName, StateId = a.Address.StateId, Zip = a.Address.Zip, Fax = a.Address.Fax, AddressTypeId = a.Address.AddressTypeId } : response.Model.Locations.FirstOrDefault() }).ToList(); return(Ok <DataResponse>(response)); } else { return(Ok <dynamic>(new { IsSuccess = 0, Status = HttpStatusCode.InternalServerError, Message = "No record found!" })); } } response.Model = new VMAccount(); //response.Model.EnrolledDate = DateTime.UtcNow; return(Ok <DataResponse>(response)); }