public ActionResult List(int length, int start, string search, SearchStoreModel model) { int total; var data = _service.Search(new PagingModel { offset = start, limit = length, search = search }, model, out total); var recordsTotal = total; var recordsFiltered = recordsTotal; var draw = 1; var obj = new SearchStoreModel { Lenght = length, Start = start }; Session[SessctionSearch] = obj; try { draw = int.Parse(Request.Params["draw"]); } catch { // ignored } return(Json(new { draw, recordsTotal, recordsFiltered, data }, JsonRequestBehavior.AllowGet)); }
public List <Vw_Store> Search(PagingModel page, SearchStoreModel search, out int total) { if (page == null) { page = new PagingModel { offset = 0, limit = 100 } } ; if (page.search == null) { page.search = ""; } using (var db = _connectionData.OpenDbConnection()) { List <Vw_Store> lstProductStore = new List <Vw_Store>(); if (search.StoreId == 0) { var query = db.From <Vw_Store>(); if (!comm.IsSuperAdmin()) { query = query.Where(e => e.SysHotelID == comm.GetHotelId()); } DateTime fDateTime; DateTime tDateTime; //if (!string.IsNullOrEmpty(search.FromDate) && !string.IsNullOrEmpty(search.ToDate)) //{ // fDateTime = CommService.ConvertStringToDate(search.FromDate); // tDateTime = CommService.ConvertStringToDate(search.ToDate); // query = query.Where(x => x.CreateDate >= fDateTime && x.CreateDate <= tDateTime); //} query.OrderByDescending(x => x.ProductGroupID); var count = query.ToCountStatement(); total = db.Select <int>(count).FirstOrDefault(); var offset = 0; try { offset = page.offset; } catch { // ignored } int limit = 10;//int.Parse(Request.Params["limit"]); try { limit = page.limit; } catch { // ignored } var lst = db.Select(query).Skip(offset).Take(limit).ToList(); lstProductStore = lst; } else { var query = db.From <Vw_Store1>(); if (!comm.IsSuperAdmin()) { query = query.Where(e => e.SysHotelID == comm.GetHotelId()); } query.Where(e => e.storeid == search.StoreId); DateTime fDateTime; DateTime tDateTime; //if (!string.IsNullOrEmpty(search.FromDate) && !string.IsNullOrEmpty(search.ToDate)) //{ // fDateTime = CommService.ConvertStringToDate(search.FromDate); // tDateTime = CommService.ConvertStringToDate(search.ToDate); // query = query.Where(x => x.CreateDate >= fDateTime && x.CreateDate <= tDateTime); //} query.OrderByDescending(x => x.ProductGroupID); var count = query.ToCountStatement(); total = db.Select <int>(count).FirstOrDefault(); var offset = 0; try { offset = page.offset; } catch { // ignored } int limit = 10;//int.Parse(Request.Params["limit"]); try { limit = page.limit; } catch { // ignored } var lst = db.Select(query).Skip(offset).Take(limit).ToList(); foreach (var obj in lst) { var obj1 = new Vw_Store(); obj1.Code = obj.Code; obj1.Createby = obj.Createby; obj1.CreateDate = obj.CreateDate; obj1.DateOrder = obj.DateOrder; obj1.Description = obj.Description; obj1.GroupName = obj.GroupName; obj1.ID = obj.ID; obj1.Modifyby = obj.Modifyby; obj1.ModifyDate = obj.ModifyDate; obj1.Name = obj.Name; obj1.ProductGroupID = obj.ProductGroupID; obj1.QuotaMinimize = obj.QuotaMinimize; obj1.SalePrice = obj.SalePrice; obj1.Status = obj.Status; obj1.SupplierID = obj.SupplierID; obj1.SupplierName = obj.SupplierName; obj1.SysHotelID = obj.SysHotelID; obj1.TonKho = obj.TonKho; obj1.UnitID = obj.UnitID; obj1.UnitName = obj.UnitName; obj1.XuatKho = obj.XuatKho; lstProductStore.Add(obj1); } //clone to that //lstProductStore = lst; } return(lstProductStore); } }