public ICollection <CustomerReportDto> GetCustomerClients() { try { var customer = _dbContext.Customer; if (customer != null) { ICollection <CustomerReportDto> customerDto = new List <CustomerReportDto>(); foreach (var item in customer) { var clientNumber = _dbContext.Client.Where(x => x.CustomerId == item.CustomerId).Count(); CustomerReportDto cust = new CustomerReportDto(); cust.CustomerId = item.CustomerId; cust.CustomerName = item.CustomerName; cust.NumberOfClient = clientNumber; customerDto.Add(cust); } return(customerDto); } } catch (Exception ex) { throw new NSIException(ex.InnerException.Message, Level.Error, ErrorType.InvalidParameter, HttpStatusCode.BadRequest); } return(null); }
public ActionResult ExportCustomers() { var customerList = _customService.GetAllCustomers(); //CustomerList _customerList = new CustomerList(); //_customerList.Customers = customerList; List <CustomerReportDto> _customerList = new List <CustomerReportDto>(); CustomerReportDto customer = null; foreach (var customers in customerList) { customer = new CustomerReportDto(); customer.CusName = customers.CusName; customer.CusFatherName = customers.CusFatherName; customer.CusMotherName = customers.CusMotherName; customer.CusPhone = customers.CusPhone; _customerList.Add(customer); } // _customerList = customerList; ReportDocument rd = new ReportDocument(); rd.Load(Path.Combine(Server.MapPath("~/Reports/Report"), "CustomerInfo.rpt")); rd.Refresh(); rd.SetDataSource(_customerList); Response.Buffer = false; Response.ClearContent(); Response.ClearHeaders(); Stream stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat); stream.Seek(0, SeekOrigin.Begin); return(File(stream, "application/pdf", "CustomerList.pdf")); }
public CustomerReportDto GetCustomerCasesMonthly(int CustomerId, int Year) { try { var customer = _dbContext.Customer.FirstOrDefault(x => x.CustomerId == CustomerId); if (customer != null && Year > 0 && Year < 9999) { CustomerReportDto customerDto = new CustomerReportDto(); var clientNumber = _dbContext.Client.Where(x => x.CustomerId == CustomerId).Count(); customerDto.CustomerId = customer.CustomerId; customerDto.CustomerName = customer.CustomerName; customerDto.NumberOfClient = clientNumber; var cases = _dbContext.CaseInfo.Where(x => x.CustomerId == CustomerId && x.DateCreated.Year == Year).ToList(); IEnumerable <CaseInfo> filteredList = cases.GroupBy(CaseInfo => CaseInfo.DateCreated.Month) .Select(group => group.First()); ICollection <CustomerCasesDto> customerCaseDto = new List <CustomerCasesDto>(); foreach (var ca in filteredList) { CustomerCasesDto custCase = new CustomerCasesDto(); custCase.MonthOfCases = ca.DateCreated.Month; custCase.NumberOfCases = _dbContext.CaseInfo.Where(x => x.CustomerId == CustomerId && x.DateCreated.Year == Year && x.DateCreated.Month == ca.DateCreated.Month).Count(); customerCaseDto.Add(custCase); } customerDto.Cases = customerCaseDto; return(customerDto); } } catch (Exception ex) { throw new NSIException(ex.InnerException.Message, Level.Error, ErrorType.InvalidParameter, HttpStatusCode.BadRequest); } return(null); }