public void Delete(T entity) { using (Entity.Entities context = new Entity.Entities()) { context.Detach(entity); context.SaveChanges(); } }
void StatisticPayProduct(DateTime statisticStartDate, DateTime statisticEndDate) { Entity.Entities entity = new Entity.Entities(); //时间段内已支付订单 var payOrders = from o in entity.OrderInfo join i in entity.OrderItemInfo on o.Id equals i.OrderId where o.PayDate.HasValue && o.PayDate.Value >= statisticStartDate && o.PayDate.Value < statisticEndDate select new { OrderId = o.Id, OrderDate = o.OrderDate, ShopId = o.ShopId, ProductId = i.ProductId, ProductName = i.ProductName, TotalAmount = i.RealTotalPrice, //实际上是金额 OrderProductQuantity = i.Quantity, UserId = o.UserId }; var payOrderGroups = payOrders.GroupBy(e => e.ProductId); List <ProductVistiInfo> productVisitRange = new List <ProductVistiInfo>(); var pids = payOrderGroups.Select(e => e.Key).Distinct(); var oldProductVisits = entity.ProductVistiInfo.Where(e => e.Date == statisticStartDate && pids.Contains(e.ProductId)).ToList(); foreach (var g in payOrderGroups) { ProductVistiInfo productVisit = oldProductVisits.FirstOrDefault(e => e.ProductId == g.Key); if (productVisit == null) { productVisit = new ProductVistiInfo(); productVisitRange.Add(productVisit); //销售量、销售金额在订单逻辑里有实时处理,如果没有记录则进行统计 productVisit.SaleCounts = g.Sum(e => e.OrderProductQuantity); productVisit.SaleAmounts = g.Sum(e => e.TotalAmount); } productVisit.Date = statisticStartDate; productVisit.ProductId = g.Key; productVisit.PayUserCounts = g.Select(e => e.UserId).Distinct().Count(); productVisit.StatisticFlag = true; var item = g.FirstOrDefault(); if (item != null) { productVisit.ShopId = item.ShopId; } } //将没有付款记录的统计信息,统一修改为已统计 var noPayOrdersStatistic = oldProductVisits.Where(e => !pids.Any(p => p == e.ProductId)); foreach (var v in noPayOrdersStatistic) { v.StatisticFlag = true; } entity.ProductVistiInfo.AddRange(productVisitRange); entity.SaveChanges(); }
public T Update(T entity) { using (Entity.Entities context = new Entity.Entities()) { String entitySetName = typeof(T).Name; context.AttachTo(entitySetName, entity); context.SaveChanges(); } return(entity); }
public T Create(T entity) { using (Entity.Entities context = new Entity.Entities()) { String entitySetName = typeof(T).Name; context.AddObject(entitySetName, entity); context.SaveChanges(); } return(entity); }
public void Delete(IList <T> entities) { using (Entity.Entities context = new Entity.Entities()) { foreach (var o in entities) { context.Detach(o); } context.SaveChanges(); } }
public void AddProduct(Product newProduct) { Products products = new Products(); products.Code = newProduct.Code; products.Name = newProduct.Name; products.Price = newProduct.Price; products.Barcode = newProduct.Barcode; using (Store.Data_Access.Entity.Entities db = new Entity.Entities()) { db.Products.Add(products); db.SaveChanges(); } }
internal bool Delete(Entity.ProfileStudent model) { try { using (var db = new Entity.Entities()) { db.Entry(model).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); return(true); } } catch (Exception) { return(false); } }
internal bool EditeUser(Entity.User model) { try { using (var db = new Entity.Entities()) { db.Entry(model).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(true); } } catch (Exception) { return(false); } }
internal bool CreateUser(Entity.User model) { try { using (var db = new Entity.Entities()) { model.Usertype = 3; db.Entry(model).State = System.Data.Entity.EntityState.Added; db.SaveChanges(); } return(true); } catch (Exception) { return(false); } }
internal bool Create(Entity.Open_Subjects model, string id) { try { string tecger = id; using (var db = new Entity.Entities()) { model.Teacher_id = tecger; db.Entry(model).State = System.Data.Entity.EntityState.Added; db.SaveChanges(); } return(true); } catch (Exception) { return(false); } }
internal bool Create(Entity.ProfileStudent model, int id) { try { int user = id; using (var db = new Entity.Entities()) { model.User_id = user; db.Entry(model).State = System.Data.Entity.EntityState.Added; db.SaveChanges(); } return(true); } catch (Exception) { return(false); } }
internal bool Create(Entity.Register_Subjects model, string Stud) { try { using (var db = new Entity.Entities()) { model.Stud_id = Stud; model.Grad = "I"; db.Entry(model).State = System.Data.Entity.EntityState.Added; db.SaveChanges(); } return(true); } catch (Exception) { return(false); } }
void StatisticCreateOrder(DateTime statisticStartDate, DateTime statisticEndDate) { Entity.Entities entity = new Entity.Entities(); //时间段内所有订单(下单数据统计) var orders = entity.OrderInfo.Where(e => e.OrderDate >= statisticStartDate && e.OrderDate < statisticEndDate).ToList(); var orderGroups = orders.GroupBy(e => e.ShopId); //已存在的店铺统计 var shopids = orderGroups.Select(e => e.Key).Distinct(); var shopVisitInfos = entity.ShopVistiInfo.Where(e => shopids.Contains(e.ShopId) && e.Date == statisticStartDate).ToList(); List <ShopVistiInfo> shopVisitRange = new List <ShopVistiInfo>(); foreach (var g in orderGroups) { ShopVistiInfo shopVisit = shopVisitInfos.FirstOrDefault(e => e.ShopId == g.Key); if (shopVisit == null) { shopVisit = new ShopVistiInfo(); shopVisitRange.Add(shopVisit); } shopVisit.Date = statisticStartDate; shopVisit.ShopId = g.Key; shopVisit.OrderCount = g.Count(); shopVisit.OrderAmount = g.Sum(e => e.TotalAmount); shopVisit.OrderUserCount = g.Select(e => e.UserId).Distinct().Count(); shopVisit.OrderProductCount = g.Sum(e => e.OrderProductQuantity); shopVisit.StatisticFlag = true; } //将没有订单记录的统计信息,统一修改为已统计 var noOrdersStatistic = shopVisitInfos.Where(e => !shopids.Any(p => p == e.ShopId)); foreach (var v in noOrdersStatistic) { v.StatisticFlag = true; } entity.ShopVistiInfo.AddRange(shopVisitRange); entity.SaveChanges(); //时间段内已支付订单(付款数据统计) var payOrders = entity.OrderInfo.Where(e => e.PayDate.HasValue && e.PayDate.Value >= statisticStartDate && e.PayDate.Value < statisticEndDate).ToList(); var payOrderGroups = payOrders.GroupBy(e => e.ShopId); //已存在的店铺统计 shopids = payOrderGroups.Select(e => e.Key).Distinct(); shopVisitInfos = entity.ShopVistiInfo.Where(e => shopids.Contains(e.ShopId) && e.Date == statisticStartDate).ToList(); shopVisitRange = new List <ShopVistiInfo>(); foreach (var g in payOrderGroups) { ShopVistiInfo shopVisit = shopVisitInfos.FirstOrDefault(e => e.ShopId == g.Key); if (shopVisit == null) { shopVisit = new ShopVistiInfo(); shopVisitRange.Add(shopVisit); } shopVisit.Date = statisticStartDate; shopVisit.ShopId = g.Key; shopVisit.OrderPayCount = g.Count(); shopVisit.OrderPayUserCount = g.Select(e => e.UserId).Distinct().Count(); shopVisit.SaleAmounts = g.Sum(e => e.TotalAmount); shopVisit.SaleCounts = g.Sum(e => e.OrderProductQuantity); shopVisit.StatisticFlag = true; } //将没有订单记录的统计信息,统一修改为已统计 var noPayOrdersStatistic = shopVisitInfos.Where(e => !shopids.Any(p => p == e.ShopId)); foreach (var v in noPayOrdersStatistic) { v.StatisticFlag = true; } entity.ShopVistiInfo.AddRange(shopVisitRange); //平台统计 PlatVisitsInfo platVisit = entity.PlatVisitsInfo.FirstOrDefault(e => e.Date == statisticStartDate); if (platVisit == null) { platVisit = new PlatVisitsInfo(); //添加 entity.PlatVisitsInfo.Add(platVisit); } platVisit.Date = statisticStartDate; platVisit.OrderCount = orders.Count(); platVisit.OrderAmount = orders.Sum(e => e.TotalAmount); platVisit.OrderUserCount = orders.Select(e => e.UserId).Distinct().Count(); platVisit.OrderProductCount = orders.Sum(e => e.OrderProductQuantity); //已支付订单 platVisit.OrderPayCount = payOrders.Count(); platVisit.OrderPayUserCount = payOrders.Select(e => e.UserId).Distinct().Count(); platVisit.SaleAmounts = payOrders.Sum(e => e.TotalAmount); platVisit.SaleCounts = payOrders.Sum(e => e.OrderProductQuantity); platVisit.StatisticFlag = true; entity.SaveChanges(); }
public void Execute(IJobExecutionContext context) { Himall.Core.Log.Debug("OrderCommentsJob : checkDate=" + DateTime.Now); try { using (TransactionScope transaction = new TransactionScope()) { Entity.Entities entity = new Entity.Entities(); //获取所有的评分数据 var lstOrderComments = (from p in entity.OrderCommentInfo group p by p.ShopId into g select new OrderCommentsModel { ShopId = g.Key, AvgDeliveryMark = g.Average(p => p.DeliveryMark), AvgPackMark = g.Average(p => p.PackMark), AvgServiceMark = g.Average(p => p.ServiceMark), CategoryIds = entity.BusinessCategoryInfo.Where(c => c.ShopId == g.Key).Select(c => c.CategoryId).ToList() } ).ToList(); foreach (var item in lstOrderComments) { //获取同行业的诊所 List <OrderCommentsModel> peerShops = new List <OrderCommentsModel>(); foreach (var cId in item.CategoryIds) { var shops = lstOrderComments.Where(c => c.CategoryIds.Contains(cId)).Select(c => c); if (shops != null && shops.Count() > 0) { peerShops.AddRange(shops); } } var avgPackMarkPeerShops = peerShops.Count != 0 ? peerShops.Average(c => c.AvgPackMark) : 0d; var avgDeliveryMarkPeerShops = peerShops.Count != 0 ? peerShops.Average(c => c.AvgDeliveryMark) : 0d; var avgServiceMarkPeerShops = peerShops.Count != 0 ? peerShops.Average(c => c.AvgServiceMark) : 0d; var productAndDescriptionMax = peerShops.Count != 0 ? lstOrderComments.Where(c => peerShops.Where(o => o.ShopId == c.ShopId).Count() > 0).Max(c => c.AvgPackMark) : 0; var productAndDescriptionMin = peerShops.Count != 0 ? lstOrderComments.Where(c => peerShops.Where(o => o.ShopId == c.ShopId).Count() > 0).Min(c => c.AvgPackMark) : 0; var sellerServiceAttitudeMax = peerShops.Count != 0 ? lstOrderComments.Where(c => peerShops.Where(o => o.ShopId == c.ShopId).Count() > 0).Max(c => c.AvgServiceMark) : 0; var sellerServiceAttitudeMin = peerShops.Count != 0 ? lstOrderComments.Where(c => peerShops.Where(o => o.ShopId == c.ShopId).Count() > 0).Min(c => c.AvgServiceMark) : 0; var sellerDeliverySpeedMax = peerShops.Count != 0 ? lstOrderComments.Where(c => peerShops.Where(o => o.ShopId == c.ShopId).Count() > 0).Max(c => c.AvgDeliveryMark) : 0; var sellerDeliverySpeedMin = peerShops.Count != 0 ? lstOrderComments.Where(c => peerShops.Where(o => o.ShopId == c.ShopId).Count() > 0).Min(c => c.AvgDeliveryMark) : 0; //宝贝与描述相符 Save(entity, new StatisticOrderCommentsInfo { ShopId = item.ShopId, CommentKey = StatisticOrderCommentsInfo.EnumCommentKey.ProductAndDescription, CommentValue = (decimal)item.AvgPackMark }); //宝贝与描述相符 同行比较 Save(entity, new StatisticOrderCommentsInfo { ShopId = item.ShopId, CommentKey = StatisticOrderCommentsInfo.EnumCommentKey.ProductAndDescriptionPeer, CommentValue = (decimal)avgPackMarkPeerShops }); //宝贝与描述相符 同行业诊所最高得分 Save(entity, new StatisticOrderCommentsInfo { ShopId = item.ShopId, CommentKey = StatisticOrderCommentsInfo.EnumCommentKey.ProductAndDescriptionMax, CommentValue = (decimal)productAndDescriptionMax }); //宝贝与描述相符 同行业诊所最低得分 Save(entity, new StatisticOrderCommentsInfo { ShopId = item.ShopId, CommentKey = StatisticOrderCommentsInfo.EnumCommentKey.ProductAndDescriptionMin, CommentValue = (decimal)productAndDescriptionMin }); //诊所的服务态度 Save(entity, new StatisticOrderCommentsInfo { ShopId = item.ShopId, CommentKey = StatisticOrderCommentsInfo.EnumCommentKey.SellerServiceAttitude, CommentValue = (decimal)item.AvgServiceMark }); //诊所的服务态度 同行业比对 Save(entity, new StatisticOrderCommentsInfo { ShopId = item.ShopId, CommentKey = StatisticOrderCommentsInfo.EnumCommentKey.SellerServiceAttitudePeer, CommentValue = (decimal)avgServiceMarkPeerShops }); //诊所服务态度 同行业诊所最高得分 Save(entity, new StatisticOrderCommentsInfo { ShopId = item.ShopId, CommentKey = StatisticOrderCommentsInfo.EnumCommentKey.SellerServiceAttitudeMax, CommentValue = (decimal)sellerServiceAttitudeMax }); //诊所服务态度 同行业诊所最低得分 Save(entity, new StatisticOrderCommentsInfo { ShopId = item.ShopId, CommentKey = StatisticOrderCommentsInfo.EnumCommentKey.SellerServiceAttitudeMin, CommentValue = (decimal)sellerServiceAttitudeMin }); //诊所的发货速度 Save(entity, new StatisticOrderCommentsInfo { ShopId = item.ShopId, CommentKey = StatisticOrderCommentsInfo.EnumCommentKey.SellerDeliverySpeed, CommentValue = (decimal)item.AvgDeliveryMark }); //诊所的发货速度 同行业比对 Save(entity, new StatisticOrderCommentsInfo { ShopId = item.ShopId, CommentKey = StatisticOrderCommentsInfo.EnumCommentKey.SellerDeliverySpeedPeer, CommentValue = (decimal)avgDeliveryMarkPeerShops }); //诊所发货速度 同行业诊所最高得分 Save(entity, new StatisticOrderCommentsInfo { ShopId = item.ShopId, CommentKey = StatisticOrderCommentsInfo.EnumCommentKey.SellerDeliverySpeedMax, CommentValue = (decimal)sellerDeliverySpeedMax }); //诊所发货速度 同行业诊所最低得分 Save(entity, new StatisticOrderCommentsInfo { ShopId = item.ShopId, CommentKey = StatisticOrderCommentsInfo.EnumCommentKey.SellerDeliverySpeedMin, CommentValue = (decimal)sellerDeliverySpeedMin }); } int rows = entity.SaveChanges(); transaction.Complete(); } } catch (Exception ex) { string error = ex.Message; } }