//[CheckSession] public virtual ActionResult CustomerSearch(DataSourceRequest command, HardwareListModel model) { //var UserItems = _groupService.SearchCustomer(model.GroupName, model.Description); var CustomerItems = _hardwareService.SearchCustomers(model.CustomerNameInSearch, model.MobileNo, model.SubscriptionCode, model.TelNo); var ProductItems = _productService.GetAllProducts(); var CustomerProductItems = _productService.GetAllCustomerProducts(); var query1 = from cus in CustomerItems join cusprod in CustomerProductItems on cus.Customer_ID equals cusprod.Customer_ID select new { cus.Customer_ID, cus.CustomerName, cus.SubscriptionCode, cus.TelNo, cus.MobileNo, cusprod.Products_ID }; var query2 = from qu1 in query1 join prod in ProductItems on qu1.Products_ID equals prod.Products_ID select new { qu1.Customer_ID, qu1.CustomerName, qu1.SubscriptionCode, qu1.TelNo, qu1.MobileNo, prod.ProductsName }; var gridModel = new DataSourceResult { Data = query2.Select(x => new HardwareModel { TelNo = x.TelNo, SubscriptionCode = x.SubscriptionCode, MobileNo = x.MobileNo, Customer_ID = x.Customer_ID, ProductsName = x.ProductsName, CustomerNameInSearch = x.CustomerName }), Total = query2.Count() }; return Json(gridModel); }
//[CheckSession] public virtual ActionResult CustomerSearch(DataSourceRequest command, PreInvoiceListModel model) { try { if (string.IsNullOrEmpty(model.CustomerNameInSearch) && string.IsNullOrEmpty(model.MobileNo) && string.IsNullOrEmpty(model.SubscriptionCode) && string.IsNullOrEmpty(model.TelNo)) { var customer = _customerService.GetAllCustomers(); //_hardwareService.SearchCustomers(model.CustomerNameInSearch, model.MobileNo, model.SubscriptionCode, model.TelNo); var hardwareRequests = _hardwareService.GetAllHardware(); var softwareRequests = _softwareService.GetAllSoftware(); var softwareChangeRequests = _softwareService.GetAllSoftwareChange(); //var CustomerProductItems = _productService.GetAllCustomerProducts(); var query1 = from cus in customer join hr in hardwareRequests on cus.Customer_ID equals hr.Customer_ID where hr.Status.Equals(0) select new { cus.Customer_ID, cus.CustomerName, hr.Description, hr.Amount }; var query2 = from cus in customer join sr in softwareRequests on cus.Customer_ID equals sr.Customer_ID where sr.Status.Equals(0) select new { cus.Customer_ID, cus.CustomerName, sr.Description, sr.Amount }; var query3 = from cus in customer join scr in softwareRequests on cus.Customer_ID equals scr.Customer_ID where scr.Status.Equals(0) select new { cus.Customer_ID, cus.CustomerName, scr.Description, scr.Amount }; var gridModel = new DataSourceResult { Data = query1.Select(x => new PreInvoiceModel { Customer_ID = x.Customer_ID, CustomerNameInSearch = x.CustomerName, ReqType = "خرید سختافزار", Amount = x.Amount.ToString(), ReqDesc = x.Description }).Concat(query2.Select(y => new PreInvoiceModel { Customer_ID = y.Customer_ID, CustomerNameInSearch = y.CustomerName, ReqType = "خرید نرمافزار", Amount = y.Amount.ToString(), ReqDesc = y.Description }).Concat(query3.Select(z => new PreInvoiceModel { Customer_ID = z.Customer_ID, CustomerNameInSearch = z.CustomerName, ReqType = "تغییر نرمافزار", Amount = z.Amount.ToString(), ReqDesc = z.Description }))), Total = query1.Count() + query2.Count() + query3.Count() }; return(Json(gridModel)); } else { //var UserItems = _groupService.SearchCustomer(model.GroupName, model.Description); var customer = _hardwareService.SearchCustomers(model.CustomerNameInSearch, model.MobileNo, model.SubscriptionCode, model.TelNo); var hardwareRequests = _hardwareService.GetHardwareOfCusomer(customer.FirstOrDefault().Customer_ID); var softwareRequests = _softwareService.GetSoftwareOfCusomer(customer.FirstOrDefault().Customer_ID); var softwareChangeRequests = _softwareService.GetSoftwareChangeOfCusomer(customer.FirstOrDefault().Customer_ID); //var CustomerProductItems = _productService.GetAllCustomerProducts(); var query1 = from cus in customer join hr in hardwareRequests on cus.Customer_ID equals hr.Customer_ID where hr.Status.Equals(0) select new { cus.Customer_ID, cus.CustomerName, hr.Description, hr.Amount }; var query2 = from cus in customer join sr in softwareRequests on cus.Customer_ID equals sr.Customer_ID where sr.Status.Equals(0) select new { cus.Customer_ID, cus.CustomerName, sr.Description, sr.Amount }; var query3 = from cus in customer join scr in softwareRequests on cus.Customer_ID equals scr.Customer_ID where scr.Status.Equals(0) select new { cus.Customer_ID, cus.CustomerName, scr.Description, scr.Amount }; var gridModel = new DataSourceResult { Data = query1.Select(x => new PreInvoiceModel { Customer_ID = x.Customer_ID, CustomerNameInSearch = x.CustomerName, ReqType = "خرید سختافزار", Amount = x.Amount.ToString(), ReqDesc = x.Description }).Concat(query2.Select(y => new PreInvoiceModel { Customer_ID = y.Customer_ID, CustomerNameInSearch = y.CustomerName, ReqType = "خرید نرمافزار", Amount = y.Amount.ToString(), ReqDesc = y.Description }).Concat(query3.Select(z => new PreInvoiceModel { Customer_ID = z.Customer_ID, CustomerNameInSearch = z.CustomerName, ReqType = "تغییر نرمافزار", Amount = z.Amount.ToString(), ReqDesc = z.Description }))), Total = query1.Count() + query2.Count() + query3.Count() }; return(Json(gridModel)); } } catch (Exception ex) { List <PreInvoiceModel> emptylist = new List <PreInvoiceModel>(); return(Json(new DataSourceResult() { Data = emptylist, Total = 0 })); } }