public ActionResult Index(string companyId, string branchId, string dateFrom, string dateTo, string customerType, string phone, string supplierId) { 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); } SupplierViewModel suppliervm = new SupplierViewModel(); List <SupplierLedgerViewModel> supplierLedger = new List <SupplierLedgerViewModel>(); if (!string.IsNullOrEmpty(companyId) && !string.IsNullOrEmpty(branchId) && !string.IsNullOrEmpty(phone) && !string.IsNullOrEmpty(dateFrom) && !string.IsNullOrEmpty(dateTo)) { suppliervm = Mapper.Map <SupplierViewModel>(_supplierService.GetSupplierBySupplierMobileNumber(phone)); supplierLedger = Mapper.Map <List <SupplierLedgerViewModel> >(_rawSqlService.GetAllSupplierLedger(companyId, branchId, dfrom.ToString(), dto.ToString(), "", phone, "").ToList()); } else if (!string.IsNullOrEmpty(companyId) && !string.IsNullOrEmpty(branchId) && !string.IsNullOrEmpty(supplierId) && !string.IsNullOrEmpty(dateFrom) && !string.IsNullOrEmpty(dateTo)) { suppliervm = Mapper.Map <SupplierViewModel>(_supplierService.GetSupplierBySupplierId(supplierId)); supplierLedger = Mapper.Map <List <SupplierLedgerViewModel> >(_rawSqlService.GetAllSupplierLedger(companyId, branchId, dfrom.ToString(), dto.ToString(), "", "", supplierId).ToList()); } else if (!string.IsNullOrEmpty(companyId) && !string.IsNullOrEmpty(branchId) && !string.IsNullOrEmpty(phone)) { suppliervm = Mapper.Map <SupplierViewModel>(_supplierService.GetSupplierBySupplierMobileNumber(phone)); supplierLedger = Mapper.Map <List <SupplierLedgerViewModel> >(_rawSqlService.GetAllSupplierLedger(companyId, branchId, "", "", "", phone, "").ToList()); } else if (!string.IsNullOrEmpty(companyId) && !string.IsNullOrEmpty(branchId) && !string.IsNullOrEmpty(supplierId)) { suppliervm = Mapper.Map <SupplierViewModel>(_supplierService.GetSupplierBySupplierId(supplierId)); supplierLedger = Mapper.Map <List <SupplierLedgerViewModel> >(_rawSqlService.GetAllSupplierLedger(companyId, branchId, "", "", "", "", supplierId).ToList()); } return(View(new Tuple <IEnumerable <SupplierLedgerViewModel>, SupplierViewModel>(supplierLedger, suppliervm))); } catch (Exception ex) { return(JavaScript($"ShowResult('{ex.Message}','failure')")); } }