public ActionResult Index(string companyId, string branchId, string dateFrom, string dateTo, string phone, string customerId) { try { DateTime?dfrom = null; DateTime?dto = null; if (!string.IsNullOrEmpty(dateFrom)) { dfrom = Convert.ToDateTime(dateFrom); dfrom = new DateTime(dfrom.Value.Year, dfrom.Value.Month, dfrom.Value.Day, 0, 0, 0); } if (!string.IsNullOrEmpty(dateTo)) { dto = Convert.ToDateTime(dateTo); dto = new DateTime(dto.Value.Year, dto.Value.Month, dto.Value.Day, 23, 59, 59); } CustomerViewModel customervm = new CustomerViewModel(); List <CustomerLedgerViewModel> customerLedger = new List <CustomerLedgerViewModel>(); if (!string.IsNullOrEmpty(companyId) && !string.IsNullOrEmpty(branchId) && !string.IsNullOrEmpty(phone) && !string.IsNullOrEmpty(dateFrom) && !string.IsNullOrEmpty(dateTo)) { customervm = Mapper.Map <CustomerViewModel>(_customerService.GetCustomerByMobileNumberWithCompanyBranchId(phone, companyId, branchId)); customerLedger = Mapper.Map <List <CustomerLedgerViewModel> >(_rawSqlService.GetAllCustomerLedger(companyId, branchId, dfrom.ToString(), dto.ToString(), "", phone, "").ToList()); } else if (!string.IsNullOrEmpty(companyId) && !string.IsNullOrEmpty(branchId) && !string.IsNullOrEmpty(customerId) && !string.IsNullOrEmpty(dateFrom) && !string.IsNullOrEmpty(dateTo)) { customervm = Mapper.Map <CustomerViewModel>(_customerService.GetCustomerByIdWithCompanyBranchId(customerId, companyId, branchId)); customerLedger = Mapper.Map <List <CustomerLedgerViewModel> >(_rawSqlService.GetAllCustomerLedger(companyId, branchId, dfrom.ToString(), dto.ToString(), "", "", customerId).ToList()); } else if (!string.IsNullOrEmpty(companyId) && !string.IsNullOrEmpty(branchId) && !string.IsNullOrEmpty(phone)) { customervm = Mapper.Map <CustomerViewModel>(_customerService.GetCustomerByMobileNumberWithCompanyBranchId(phone, companyId, branchId)); customerLedger = Mapper.Map <List <CustomerLedgerViewModel> >(_rawSqlService.GetAllCustomerLedger(companyId, branchId, "", "", "", phone, "").ToList()); } else if (!string.IsNullOrEmpty(companyId) && !string.IsNullOrEmpty(branchId) && !string.IsNullOrEmpty(customerId)) { customervm = Mapper.Map <CustomerViewModel>(_customerService.GetCustomerByIdWithCompanyBranchId(customerId, companyId, branchId)); customerLedger = Mapper.Map <List <CustomerLedgerViewModel> >(_rawSqlService.GetAllCustomerLedger(companyId, branchId, "", "", "", "", customerId).ToList()); } return(View(new Tuple <IEnumerable <CustomerLedgerViewModel>, CustomerViewModel>(customerLedger, customervm))); } catch (Exception ex) { return(JavaScript($"ShowResult('{ex.Message}','failure')")); } }