public IEnumerable <TextValueViewModel <int> > ReadProductDetails(DataSourceRequest request) { IList <TextValueViewModel <int> > result = new List <TextValueViewModel <int> >(); ServerFilterInfo filterInfo = request.ServerFiltering.FilterCollection.Where(f => f.Field == "ProductId").SingleOrDefault(); if (string.IsNullOrEmpty(filterInfo.Value)) { return(result); } int productId = Convert.ToInt32(filterInfo.Value); string cmdText = @" SELECT d.ProductDetailId [Value], d.ProductId Parent, s1.[Name]+' '+s2.[Name] [Text] FROM ProductDetail d LEFT JOIN ProductSpecification s1 ON d.FirstSpecificationId = s1.ProductSpecificationId LEFT JOIN ProductSpecification s2 ON d.SecondSpecificationId = s2.ProductSpecificationId WHERE d.ProductId = @ProductId"; this.ReadData(dataReader => { result.Add(new TextValueViewModel <int> { Text = dataReader["Text"].ToString(), Value = Convert.ToInt32(dataReader["Value"]), Parent = Convert.ToInt32(dataReader["Parent"]) }); }, cmdText, new SqlParameter("ProductId", productId)); return(result); }
public DataSourceResponse <SpecificationViewModel> Read(DataSourceRequest request) { var responseData = this.DbContext.ProductSpecifications.Select(s => s); if (request.ServerFiltering != null) { ServerFilterInfo filterInfo = request.ServerFiltering.FilterCollection.Where(f => f.Field == "Parent").SingleOrDefault(); int productCategoryId = Convert.ToInt32(filterInfo.Value); responseData = responseData.Where(s => s.ProductCategoryId == productCategoryId); } var response = new DataSourceResponse <SpecificationViewModel> { TotalRowCount = responseData.Count() }; if (request.ServerPaging != null) { int skip = Math.Max(request.ServerPaging.PageSize * (request.ServerPaging.Page - 1), val2: 0); responseData = responseData.OrderBy(s => s.ProductSpecificationId).Skip(skip).Take(request.ServerPaging.PageSize); } response.DataCollection = responseData.Select(s => new SpecificationViewModel { Text = s.Name, Value = s.ProductSpecificationId, Parent = s.ProductCategoryId }).ToList(); return(response); }
public IEnumerable <SpecificationViewModel> ReadSpecifications(DataSourceRequest request) { var responseData = this.DbContext.ProductSpecifications.Select(s => s); if (request.ServerFiltering != null) { ServerFilterInfo filterInfo = request.ServerFiltering.FilterCollection.Where(f => f.Field == "Parent").SingleOrDefault(); int productCategoryId = Convert.ToInt32(filterInfo.Value); responseData = responseData.Where(s => s.ProductCategoryId == productCategoryId); } var response = responseData.Select(s => new SpecificationViewModel { Text = s.Name, Value = s.ProductSpecificationId, Parent = s.ProductCategoryId }); return(response); }
public DataSourceResponse <TrackingRecordViewModel> Read(DataSourceRequest request) { // 公司端、督導、技術指導 var responseData = this.DbContext.TrackingRecords.Select(r => r); if (request.ServerFiltering != null) { ServerFilterInfo filterInfo = request.ServerFiltering.FilterCollection.Where(f => f.Field == "CustomerId").SingleOrDefault(); int customerId = Convert.ToInt32(filterInfo.Value); responseData = responseData.Where(r => r.CustomerId == customerId); } var response = new DataSourceResponse <TrackingRecordViewModel> { TotalRowCount = responseData.Count() }; if (request.ServerPaging != null) { int skip = Math.Max(request.ServerPaging.PageSize * (request.ServerPaging.Page - 1), val2: 0); responseData = responseData.OrderBy(r => r.TrackingRecordId).Skip(skip).Take(request.ServerPaging.PageSize); } response.DataCollection = responseData.Select(r => new TrackingRecordViewModel { TrackingRecordId = r.TrackingRecordId, CustomerId = r.CustomerId, ReferralTime = r.ReferralTime, BustUp = r.BustUp, BustDown = r.BustDown, MilkCapacity = r.MilkCapacity, Abdominal = r.Abdominal, Waist = r.Waist, Hip = r.Hip, LegLeft = r.LegLeft, LegRight = r.LegRight, Design = r.Design, Buy = r.Buy }).ToList(); return(response); }
public DataSourceResponse <QueryDetailViewModel> ReadQueryDetails(DataSourceRequest request, IIdentity identity) { string cmdText = @" SELECT c.[Name], ur.RoleId FROM Customer c JOIN AspNetUserRoles ur ON c.UserId = ur.UserId WHERE c.UserId = @UserId"; var currentUserId = identity.GetUserId(); var roles = this.userService.GetRoles(); WebApplication.Models.Role.Role currentRole; string currentName = string.Empty; this.ReadDataSingle(dataReader => { string currentRoleId = dataReader["RoleId"].ToString(); currentRole = roles[currentRoleId]; currentName = dataReader["Name"].ToString(); }, cmdText, new SqlParameter("UserId", currentUserId)); ServerFilterInfo yearFilterInfo = request.ServerFiltering.FilterCollection.Where(f => f.Field == "Year").SingleOrDefault(); int year = Convert.ToInt32(yearFilterInfo.Value); ServerFilterInfo monthFilterInfo = request.ServerFiltering.FilterCollection.Where(f => f.Field == "Month").SingleOrDefault(); int month = Convert.ToInt32(monthFilterInfo.Value); var shipments = this.DbContext.Shipments.Where(s => s.UserId == currentUserId && s.Date.Year == year && s.Date.Month == month).ToList(); IDictionary <int, string> customers = new Dictionary <int, string>(); IList <QueryDetailViewModel> responseData = new List <QueryDetailViewModel>(); foreach (var shipment in shipments) { var viewModel = new QueryDetailViewModel { PurchaseId = shipment.ShipmentId, Year = year, Month = month, ShipmentDate = shipment.Date }; if (shipment.CustomerId.HasValue) { if (customers.ContainsKey(shipment.CustomerId.Value)) { viewModel.CustomerName = customers[shipment.CustomerId.Value]; } else { var customer = this.DbContext.Customers.Where(c => c.CustomerId == shipment.CustomerId.Value).SingleOrDefault(); if (customer != null) { customers.Add(shipment.CustomerId.Value, customer.Name); viewModel.CustomerName = customer.Name; } } } else { viewModel.CustomerName = currentName; } var shipmentDetails = this.DbContext.ShipmentDetails.Where(d => d.ShipmentId == shipment.ShipmentId).ToList(); foreach (var shipmentDetail in shipmentDetails) { viewModel.TotalAmount += shipmentDetail.SubtotalAmount; } responseData.Add(viewModel); } var response = new DataSourceResponse <QueryDetailViewModel> { TotalRowCount = responseData.Count }; if (request.ServerPaging != null) { int skip = Math.Max(request.ServerPaging.PageSize * (request.ServerPaging.Page - 1), val2: 0); response.DataCollection = responseData.OrderBy(v => v.PurchaseId).Skip(skip).Take(request.ServerPaging.PageSize).ToList(); } return(response); }
public DataSourceResponse <ProductDetailViewModel> Read(DataSourceRequest request) { var responseData = this.DbContext.ProductDetails.Select(d => d); if (request.ServerFiltering != null) { ServerFilterInfo filterInfo = request.ServerFiltering.FilterCollection.Where(f => f.Field == "ProductId").SingleOrDefault(); int productId = Convert.ToInt32(filterInfo.Value); responseData = responseData.Where(d => d.ProductId == productId); } var response = new DataSourceResponse <ProductDetailViewModel> { TotalRowCount = responseData.Count() }; if (request.ServerPaging != null) { int skip = Math.Max(request.ServerPaging.PageSize * (request.ServerPaging.Page - 1), val2: 0); responseData = responseData.OrderBy(d => d.ProductDetailId).Skip(skip).Take(request.ServerPaging.PageSize); } var collection = responseData.Select(d => new { ProductDetailId = d.ProductDetailId, ProductId = d.ProductId, Price = d.Price, SafeStock = d.SafeStock, FirstSpecificationProductCategoryName = d.FirstSpecification.ProductCategory.Name, FirstSpecificationProductCategoryProductCategoryId = d.FirstSpecification.ProductCategory.ProductCategoryId, FirstSpecificationName = d.FirstSpecification.Name, FirstSpecificationProductSpecificationId = d.FirstSpecification.ProductSpecificationId, FirstSpecificationProductCategoryId = d.FirstSpecification.ProductCategoryId, SecondSpecificationId = d.SecondSpecificationId, SecondSpecificationProductCategoryName = d.SecondSpecification.ProductCategory.Name, SecondSpecificationProductCategoryProductCategoryId = d.SecondSpecification.ProductCategory.ProductCategoryId, SecondSpecificationName = d.SecondSpecification.Name, SecondSpecificationProductSpecificationId = d.SecondSpecification.ProductSpecificationId, SecondSpecificationProductCategoryId = d.SecondSpecification.ProductCategoryId }).ToList(); foreach (var data in collection) { var viewModel = new ProductDetailViewModel { ProductDetailId = data.ProductDetailId, ProductId = data.ProductId, Price = data.Price, SafeStock = data.SafeStock }; var firstCategory = new SelectListItem { Text = data.FirstSpecificationProductCategoryName, Value = data.FirstSpecificationProductCategoryProductCategoryId.ToString() }; viewModel.FirstCategory = firstCategory; var firstSpecification = new FirstSpecificationViewModel { Text = data.FirstSpecificationName, Value = data.FirstSpecificationProductSpecificationId, Parent = data.FirstSpecificationProductCategoryId }; viewModel.FirstSpecification = firstSpecification; if (data.SecondSpecificationId.HasValue) { var secondCategory = new SelectListItem { Text = data.SecondSpecificationProductCategoryName, Value = data.SecondSpecificationProductCategoryProductCategoryId.ToString() }; viewModel.SecondCategory = secondCategory; var secondSpecification = new SpecificationViewModel { Text = data.SecondSpecificationName, Value = data.SecondSpecificationProductSpecificationId, Parent = data.SecondSpecificationProductCategoryId }; viewModel.SecondSpecification = secondSpecification; } response.DataCollection.Add(viewModel); } return(response); }
public DataSourceResponse <ShipmentDetailViewModel> Read(DataSourceRequest request) { var responseData = this.DbContext.ShipmentDetails.Select(d => d); if (request.ServerFiltering != null) { ServerFilterInfo filterInfo = request.ServerFiltering.FilterCollection.Where(f => f.Field == "ShipmentId").SingleOrDefault(); int shipmentId = Convert.ToInt32(filterInfo.Value); responseData = responseData.Where(d => d.ShipmentId == shipmentId); } var response = new DataSourceResponse <ShipmentDetailViewModel> { TotalRowCount = responseData.Count() }; if (request.ServerPaging != null) { int skip = Math.Max(request.ServerPaging.PageSize * (request.ServerPaging.Page - 1), val2: 0); responseData = responseData.OrderBy(d => d.ShipmentDetailId).Skip(skip).Take(request.ServerPaging.PageSize); } var collection = responseData.Select(d => new { ShipmentDetailId = d.ShipmentDetailId, ShipmentId = d.ShipmentId, Quantity = d.Quantity, SubtotalAmount = d.SubtotalAmount }).ToList(); foreach (var data in collection) { var viewModel = new ShipmentDetailViewModel { ShipmentDetailId = data.ShipmentDetailId, ShipmentId = data.ShipmentId, Product = new SelectListItem(), ProductDetail = new SelectListItem(), Quantity = data.Quantity, SubtotalAmount = data.SubtotalAmount }; var product = (from d in this.DbContext.ShipmentDetails join p in this.DbContext.Products on d.ProductId equals p.ProductId where d.ShipmentDetailId == data.ShipmentDetailId select new { p.ProductId, p.Name }).SingleOrDefault(); if (product != null) { viewModel.Product.Text = product.Name; viewModel.Product.Value = product.ProductId.ToString(); } var productDetail = (from d in this.DbContext.ShipmentDetails join pd in this.DbContext.ProductDetails on d.ProductDetailId equals pd.ProductDetailId join ps1 in this.DbContext.ProductSpecifications on pd.FirstSpecificationId equals ps1.ProductSpecificationId join ps2 in this.DbContext.ProductSpecifications on pd.SecondSpecificationId equals ps2.ProductSpecificationId into ps2Group where d.ShipmentDetailId == data.ShipmentDetailId from ps2New in ps2Group.DefaultIfEmpty() select new { Name = ps1.Name + (ps2New == null ? "" : " " + ps2New.Name), ProductDetailId = pd.ProductDetailId }).SingleOrDefault(); if (productDetail != null) { viewModel.ProductDetail.Text = productDetail.Name; viewModel.ProductDetail.Value = productDetail.ProductDetailId.ToString(); } response.DataCollection.Add(viewModel); } return(response); }