public OPC_OrgInfo Add(OPC_OrgInfo orgInfo)
 {
     using (var db = new YintaiHZhouContext())
     {
         if (orgInfo != null)
         {
             var lst = db.OPC_OrgInfos.Where(t => t.ParentID == orgInfo.ParentID).OrderByDescending(t => t.OrgID);
             var e   = lst.FirstOrDefault();
             if (e == null)
             {
                 orgInfo.OrgID = orgInfo.ParentID + "001";
             }
             else
             {
                 int d = int.Parse(e.OrgID);
                 orgInfo.OrgID = (d + 1).ToString();
             }
             orgInfo.IsDel = false;
             var a = db.OPC_OrgInfos.Add(orgInfo);
             db.SaveChanges();
             return(a);
         }
         return(null);
     }
 }
        protected PageResult <TEntity> Select2 <TEntity, S>(Expression <Func <TEntity, bool> > filter, Expression <Func <TEntity, S> > orderByLambda, bool isAsc, int pageIndex, int pageSize = 20) where TEntity : class
        {
            using (var db = new YintaiHZhouContext())
            {
                IDbSet <TEntity> set = db.Set <TEntity>();
                int count            = set.Where(filter).Count();

                pageIndex = pageIndex - 1;
                if (pageIndex < 0)
                {
                    pageIndex = 0;
                }
                IList <TEntity> lst;
                if (isAsc)
                {
                    lst = set.Where(filter).OrderBy(orderByLambda).Skip(pageIndex * pageSize).Take(pageSize).ToList();
                }
                else
                {
                    lst = set.Where(filter).OrderByDescending(orderByLambda).Skip(pageIndex * pageSize).Take(pageSize).ToList();
                }


                return(new PageResult <TEntity>(lst, count));
            }
        }
 public void Action(Action <DbContext> action)
 {
     using (var c = new YintaiHZhouContext())
     {
         action(c);
     }
 }
Beispiel #4
0
 public int Count(string orderNo)
 {
     using (var db = new YintaiHZhouContext())
     {
         return(db.OPC_SaleRMAs.Count(t => t.OrderNo == orderNo));
     }
 }
Beispiel #5
0
        public AuthUser(int uid)
        {
            using (var db = new YintaiHZhouContext())
            {
                var user = db.OPC_AuthUsers.FirstOrDefault(x => x.Id == uid);
                if (user == null)
                {
                    throw new UnauthorizedAccessException("未授权用户");
                }

                IsAdmin = user.IsSystem;
                if (IsAdmin)
                {
                    _authStoreIds.AddRange(db.Stores.Where(x => x.Status == 1).Select(t => t.Id));
                    return;
                }

                var authStore = db.OPC_OrgInfos.FirstOrDefault(o => o.OrgID == user.DataAuthId && o.OrgType == 5);
                if (authStore == null || !authStore.StoreOrSectionID.HasValue)
                {
                    throw new UserException(string.Format("用户关联的组织机构不存在:user id :{0}, userName {1}", uid, user.Name));
                }


                _authStoreIds.Add(authStore.Id);
            }
        }
Beispiel #6
0
        public PageResult <OrderItemDto> GetByOrderNo(string orderNo, int pageIndex, int pageSize)
        {
            using (var db = new YintaiHZhouContext())
            {
                IQueryable <OrderItem> query = db.OrderItems.Where(t => t.OrderNo == orderNo);

                IQueryable <OPC_RMADetail> query2 = db.OrderItems.Where(t => t.OrderNo == orderNo)
                                                    .Join(db.OPC_RMADetails, t => t.Id, o => o.OrderItemId, (t, o) => o);
                var filter = from q in query
                             join b in db.Brands on q.BrandId equals b.Id into cs
                             join rmaDetail in query2 on q.Id equals rmaDetail.OrderItemId into rma
                             select new { Order = q, Brand = cs.FirstOrDefault(), Rma = rma.FirstOrDefault() };
                filter = filter.OrderByDescending(t => t.Order.CreateDate);
                var list = filter.ToPageResult(pageIndex, pageSize);
                IList <OrderItemDto> lstDtos = new List <OrderItemDto>();
                foreach (var t in list.Result)
                {
                    OrderItemDto o = Mapper.Map <OrderItem, OrderItemDto>(t.Order);
                    o.BrandName = t.Brand == null ? "" : t.Brand.Name;
                    if (t.Rma != null)
                    {
                        o.NeedReturnCount = t.Order.Quantity - t.Rma.BackCount;
                        o.ReturnCount     = t.Rma.BackCount;
                    }
                    lstDtos.Add(o);
                }
                return(new PageResult <OrderItemDto>(lstDtos, list.TotalCount));
            }
        }
 public IList <OPC_Sale> GetSaleOrdersByPachageId(int packageId)
 {
     using (var db = new YintaiHZhouContext())
     {
         return(db.OPC_Sales.Where(x => x.ShippingSaleId.HasValue && x.ShippingSaleId.Value == packageId).ToList());
     }
 }
Beispiel #8
0
        public PageResult <OPC_ShippingSale> QueryShippingSales(ExpressRequestDto request, int shippingStatus, int uid)
        {
            using (var db = new YintaiHZhouContext())
            {
                Expression <Func <OPC_ShippingSale, bool> > filterExpression =
                    t =>
                    t.CreateDate >= request.StartDate && t.CreateDate < request.EndDate &&
                    t.ShippingStatus == shippingStatus;

                if (!string.IsNullOrEmpty(request.OrderNo))
                {
                    filterExpression = filterExpression.And(x => x.OrderNo == request.OrderNo);
                }

                IAuthUser user = new AuthUser(uid);
                if (!user.IsAdmin)
                {
                    filterExpression =
                        filterExpression.And(x => user.AuthenticatedStores().ToArray().Contains(x.StoreId.Value));
                }

                int cnt = db.OPC_ShippingSales.Count(filterExpression);

                var list =
                    db.OPC_ShippingSales.Where(filterExpression)
                    .OrderBy(o => o.CreateDate)
                    .Skip(request.PagerRequest.SkipCount)
                    .Take(request.PagerRequest.PageSize)
                    .ToList();
                return(new PageResult <OPC_ShippingSale>(list, cnt));
            }
        }
Beispiel #9
0
        public OrderStatusResultDto GetRMAStatusById(OPC_RMA saleRMA)
        {
            OPC_Stock opcStock;;

            using (var db = new YintaiHZhouContext())
            {
                opcStock = db.OPC_Stock.FirstOrDefault(a => a.SectionId == saleRMA.SectionId);
            }

            if (opcStock == null)
            {
                throw new StockNotExistsException(string.Format(""));
            }

            var result = _apiClient.Post(new GetOrderStatusByIdRequest()
            {
                Data = new
                {
                    id      = saleRMA.RMANo,
                    storeno = opcStock.StoreCode
                }
            });

            if (!result.Status)
            {
                Log.ErrorFormat("查询订单信息失败,message:{0}", result.Message);
                return(null);
            }
            return(AutoMapper.Mapper.Map <OrderStatusResult, OrderStatusResultDto>(result.Data));
        }
        public void Process(Repository.DTO.ProductDto product, Inventory inventory)
        {
            if (string.IsNullOrEmpty(product.BrandSizeCode) && string.IsNullOrEmpty(product.BrandSizeName))
            {
                return;
            }

            using (var db = new YintaiHZhouContext())
            {
                var rpv =
                    db.OPC_StockPropertyValueRaw.FirstOrDefault(
                        x => x.InventoryId == inventory.Id && x.SourceStockId == product.ProductId);
                if (rpv == null)
                {
                    db.OPC_StockPropertyValueRaw.Add(new OPC_StockPropertyValueRaw()
                    {
                        BrandSizeCode = product.BrandSizeCode,
                        BrandSizeName = product.BrandSizeName,
                        Channel       = SystemDefine.IntimeChannel,
                        InventoryId   = inventory.Id,
                        PropertyData  = string.Empty,
                        SourceStockId = product.ProductId,
                        UpdateDate    = DateTime.Now.AddDays(-1)
                    });
                }
                else
                {
                    rpv.BrandSizeName = product.BrandSizeName;
                    rpv.BrandSizeCode = product.BrandSizeCode;
                }
                db.SaveChanges();
            }
        }
Beispiel #11
0
        private void SaleRMAPaidNotified(OPC_RMA rma)
        {
            using (var db = new YintaiHZhouContext())
            {
                var opcRMA = db.OPC_RMA.FirstOrDefault(x => x.Id == rma.Id);
                if (opcRMA == null)
                {
                    Logger.Error(string.Format("Invalid RMA ({0})", rma.RMANo));
                    return;
                }

                if (rma.Status != (int)EnumRMAStatus.NotifyProduct)
                {
                    Logger.ErrorFormat("invalid rma status {0}", rma.Status);
                    return;
                }

                opcRMA.UpdatedDate   = DateTime.Now;
                opcRMA.RMACashStatus = 5;//5表示已送收银
                opcRMA.UpdatedUser   = -10000;
                db.SaveChanges();

                db.OPC_RMANotificationLog.Add(new OPC_RMANotificationLog
                {
                    CreateDate = DateTime.Now,
                    CreateUser = -10000,
                    RMANo      = rma.RMANo,
                    Status     = (int)NotificationStatus.Paid,
                    Message    = string.Empty,
                });
                db.SaveChanges();
            }
        }
Beispiel #12
0
        public PageResult <RmaDetail> GetByRmaNo(string rmaNo, int pageIndex, int pageSize)
        {
            using (var db = new YintaiHZhouContext())
            {
                var query =
                    db.OPC_RMADetails.Where(t => t.RMANo == rmaNo)
                    .Join(db.OrderItems, t => t.OrderItemId, o => o.Id, (t, o) => new { RmaDetail = t, OrderItem = o })
                    .Join(db.Brands, t => t.OrderItem.BrandId, o => o.Id,
                          (t, o) => new { t.OrderItem, t.RmaDetail, BrandName = o.Name });
                var lst    = query.ToList();
                var lstDto = new List <RmaDetail>();
                foreach (var o in lst)
                {
                    var d = Mapper.Map <OPC_RMADetail, RmaDetail>(o.RmaDetail);
                    d.BrandName      = o.BrandName;
                    d.SizeValueName  = o.OrderItem.SizeValueName;
                    d.ColorValueName = o.OrderItem.ColorValueName;
                    d.StoreItemNo    = o.OrderItem.StoreItemNo;
                    d.LablePrice     = o.OrderItem.UnitPrice.HasValue?d.LablePrice:o.OrderItem.ItemPrice;
                    d.Discount       = o.OrderItem.UnitPrice.HasValue
                        ? d.LablePrice
                        : o.OrderItem.ItemPrice - o.OrderItem.ItemPrice;

                    lstDto.Add(d);
                }
                return(new PageResult <RmaDetail>(lstDto, lstDto.Count));
            }
        }
 /// <summary>
 ///     查询销售单明细信息
 /// </summary>
 /// <param name="saleIDs">销售单ID串</param>
 /// <returns></returns>
 public IList <OPC_SaleDetail> SelectSaleDetail(IEnumerable <string> saleNos)
 {
     using (var db = new YintaiHZhouContext())
     {
         return(db.OPC_SaleDetails.Where(t => saleNos.Contains(t.SaleOrderNo)).ToList());
     }
 }
        public PageResult <OPC_Sale> Select(DateTime startDate, DateTime endDate, string orderNo, string saleOrderNo, int pageIndex, int pageSize = 20)
        {
            using (var db = new YintaiHZhouContext())
            {
                var filterExpression =
                    db.OPC_Sales.Where(t => t.SellDate >= startDate && t.SellDate < endDate)
                    .Join(
                        db.Sections.Where(
                            s =>
                            s.Status != -1 && s.StoreId.HasValue &&
                            CurrentUser.StoreIds.Contains(s.StoreId.Value)), o => o.SectionId, s => s.Id,
                        (o, s) => o);

                if (!string.IsNullOrEmpty(orderNo))
                {
                    filterExpression = filterExpression.Where(p => p.OrderNo.Contains(orderNo));
                }
                if (!string.IsNullOrEmpty(saleOrderNo))
                {
                    filterExpression = filterExpression.Where(p => p.SaleOrderNo.Contains(saleOrderNo));
                }

                if (CurrentUser != null)
                {
                    var ll = CurrentUser.SectionIds;
                    filterExpression = filterExpression.Where(t => t.SectionId.HasValue && ll.Contains(t.SectionId.Value));
                }

                filterExpression = filterExpression.OrderByDescending(t => t.CreatedDate);
                return(filterExpression.ToPageResult(pageIndex, pageSize));
            }
        }
Beispiel #15
0
        /// <summary>
        /// 保存拆单失败的订单
        /// </summary>
        /// <param name="orderNo"></param>
        /// <param name="ErrorReason"></param>
        /// <returns></returns>
        public bool SaveSplitOrderLog(string orderNo, string reason, int status)
        {
            using (var db = new YintaiHZhouContext())
            {
                var log =
                    db.OPC_OrderSplitLog.FirstOrDefault(
                        x => x.OrderNo == orderNo && reason == x.Reason && x.Status == status);
                if (log == null)
                {
                    var opc_OrderSplitLog = new OPC_OrderSplitLog
                    {
                        OrderNo    = orderNo,
                        Reason     = reason,
                        Status     = status,
                        CreateDate = DateTime.Now
                    };
                    db.OPC_OrderSplitLog.Add(opc_OrderSplitLog);
                }

                else
                {
                    log.CreateDate = DateTime.Now;
                }

                db.SaveChanges();
            }
            return(true);
        }
Beispiel #16
0
 /// <summary>
 ///     Gets the by sale no.
 /// </summary>
 /// <param name="saleNo">The sale no.</param>
 /// <returns>OPC_Sale.</returns>
 public OPC_Sale GetBySaleNo(string saleNo)
 {
     using (var db = new YintaiHZhouContext())
     {
         return(db.OPC_Sales.FirstOrDefault(t => t.SaleOrderNo == saleNo));
     }
 }
Beispiel #17
0
        public PageResult <OrderItemDto> GetOrderItemsAutoBack(string orderNo, int pageIndex, int pageSize)
        {
            using (var db = new YintaiHZhouContext())
            {
                IQueryable <OrderItem> query = db.OrderItems.Where(t => t.OrderNo == orderNo);

                var filter = from q in query
                             join b in db.Brands on q.BrandId equals b.Id into cs
                             select new { Order = q, Brand = cs.FirstOrDefault() };
                filter = filter.OrderByDescending(t => t.Order.CreateDate);
                var list = filter.ToPageResult(pageIndex, pageSize);
                IList <OrderItemDto> lstDtos = new List <OrderItemDto>();
                foreach (var t in list.Result)
                {
                    OrderItemDto o = Mapper.Map <OrderItem, OrderItemDto>(t.Order);
                    o.BrandName = t.Brand == null ? "" : t.Brand.Name;

                    o.NeedReturnCount = t.Order.Quantity;
                    o.ReturnCount     = t.Order.Quantity;

                    lstDtos.Add(o);
                }
                return(new PageResult <OrderItemDto>(lstDtos, list.TotalCount));
            }
        }
Beispiel #18
0
        public bool FinishPrintSale(string orderNo, int userId)
        {
            //return UpdateSatus(orderNo, userId, EnumSaleOrderStatus.PrintSale);
            using (var db = new YintaiHZhouContext())
            {
                var saleOrder = db.OPC_Sales.FirstOrDefault(x => x.SaleOrderNo == orderNo);
                if (saleOrder == null)
                {
                    throw new OpcException(string.Format("无效的销售单号:{0}", orderNo));
                }

                var order = db.Orders.FirstOrDefault(x => x.OrderNo == saleOrder.OrderNo);
                if (order == null)
                {
                    throw new OpcException(string.Format("数据异常,根据销售单号({0})无法找到订单", orderNo));
                }

                if (order.OrderProductType == (int)OrderType.SystemProduct ||
                    order.OrderProductType == (int)OrderType.None)
                {
                    if (string.IsNullOrEmpty(saleOrder.CashNum) || saleOrder.CashStatus != (int)EnumCashStatus.CashOver)
                    {
                        throw new OpcException(string.Format("系统商品订单必须完成收银后才能打印"));
                    }
                }

                saleOrder.Status      = (int)EnumSaleOrderStatus.PrintSale;
                saleOrder.UpdatedDate = DateTime.Now;
                saleOrder.UpdatedUser = userId;
                db.SaveChanges();
            }
            return(true);
        }
Beispiel #19
0
        /// <summary>
        /// 物流入库
        /// </summary>
        /// <param name="rmaNo"></param>
        public void SetRmaShipInStorage(string rmaNo)
        {
            using (var db = new YintaiHZhouContext())
            {
                var opcRma = db.OPC_RMAs.FirstOrDefault(x => x.RMANo == rmaNo);
                if (opcRma == null)
                {
                    throw new RmaException(string.Format("无效的退货单号{0}", rmaNo));
                }
                opcRma.Status          = EnumRMAStatus.ShipInStorage.AsId();
                opcRma.UpdatedDate     = DateTime.Now;
                opcRma.UpdatedUser     = -1;
                opcRma.BackDate        = DateTime.Now;
                db.Entry(opcRma).State = EntityState.Modified;
                var rmaEntity = db.RMAs.FirstOrDefault(x => x.RMANo == rmaNo);
                if (rmaEntity != null)
                {
                    rmaEntity.Status          = 12;//退货已签收
                    rmaEntity.UpdateDate      = DateTime.Now;
                    rmaEntity.UpdateUser      = -1;
                    db.Entry(rmaEntity).State = EntityState.Modified;
                }

                db.SaveChanges();
            }
        }
        private IMS_Associate CreateAssociate(IMS_InviteCodeRequest request)
        {
            using (var db = new YintaiHZhouContext())
            {
                var section =
                    db.Set <Section>()
                    .FirstOrDefault(x => x.SectionCode == request.SectionCode && x.StoreId == request.StoreId);
                if (section == null)
                {
                    return(null);
                }

                var associate = new IMS_Associate()
                {
                    CreateDate   = DateTime.Now,
                    CreateUser   = request.UserId,
                    OperateRight = request.RequestType == 2 ? 7 : 3,
                    SectionId    = section.Id,
                    Status       = 1,
                    StoreId      = request.StoreId,
                    UserId       = request.UserId,
                    TemplateId   = int.Parse(ConfigurationManager.AppSettings["IMS_Default_Template"]),
                    OperatorCode = request.OperatorCode,
                };

                associate = db.Set <IMS_Associate>().Add(associate);
                db.SaveChanges();
                return(associate);
            }
        }
 public IList <OPC_SaleComment> GetSaleComments(string saleOrderNo)
 {
     using (var db = new YintaiHZhouContext())
     {
         return(db.OPC_SaleComments.Where(x => x.SaleOrderNo == saleOrderNo).ToList());
     }
 }
 public IList <SaleDetailDto> GetSaleDetails(string saleOrderNo)
 {
     using (var db = new YintaiHZhouContext())
     {
         return
             (db.OPC_SaleDetails.Where(o => o.SaleOrderNo == saleOrderNo)
              .Join(db.OrderItems, d => d.OrderItemId, i => i.Id, (o, i) => new { o, i })
              .GroupJoin(db.Brands.Where(b => b.Status == 1), o => o.i.BrandId, b => b.Id, (o, b) => new
         {
             detail = o.o,
             item = o.i,
             brand = b.OrderByDescending(x => x.Status).FirstOrDefault()
         })
              .Join(db.Products, o => o.item.ProductId, p => p.Id, (o, p) => new SaleDetailDto
         {
             Id = o.detail.Id,
             ProductNo = o.detail.ProdSaleCode,
             SaleOrderNo = o.detail.SaleOrderNo,
             StyleNo = p.SkuCode,
             Size = o.item.SizeValueName,
             Color = o.item.ColorValueName,
             Brand = o.brand != null ? o.brand.Name : string.Empty,
             SellPrice = o.item.ItemPrice,
             Price = o.item.UnitPrice.HasValue ? o.item.UnitPrice.Value : (decimal)0.0,
             SalePrice = o.item.ItemPrice,
             SellCount = o.detail.SaleCount,
             ReturnCount = o.detail.BackNumber.HasValue ? o.detail.BackNumber.Value : 0,
             LabelPrice = o.item.UnitPrice.HasValue ? o.item.UnitPrice.Value : (decimal)0.0,
             Remark = o.detail.Remark,
             SectionCode = o.detail.SectionCode,
             ProductName = o.item.ProductName
         }).ToList());
     }
 }
Beispiel #23
0
        public PageResult <SaleRmaDto> GetAll(string orderNo, string payType, int?bandId, DateTime startTime, DateTime endTime, string telephone, int pageIndex, int pageSize)
        {
            using (var db = new YintaiHZhouContext())
            {
                var query = db.OPC_RMAs.Where(t => t.CreatedDate >= startTime && t.CreatedDate < endTime && CurrentUser.StoreIds.Contains(t.StoreId));

                var query2 = db.Orders.Where(t => t.CreateDate >= startTime && t.CreateDate < endTime).Join(db.OrderTransactions, o => o.OrderNo, t => t.OrderNo, (o, t) => new
                {
                    Order = o,
                    Trans = t
                });

                if (!string.IsNullOrWhiteSpace(orderNo))
                {
                    query  = query.Where(t => t.OrderNo == orderNo);
                    query2 = query2.Where(t => t.Order.OrderNo == orderNo);
                }

                if (!string.IsNullOrWhiteSpace(payType))
                {
                    query2 = query2.Where(t => t.Order.PaymentMethodCode == payType);
                }

                var q = from t in query2
                        join o in query on t.Order.OrderNo equals o.OrderNo into cs
                        select new { SaleRMA = cs.FirstOrDefault(), Orders = t };
                q = q.OrderByDescending(t => t.Orders.Order.OrderNo);
                var lst        = q.ToPageResult(pageIndex, pageSize);
                var lstSaleRma = lst.Result.Select(t => CreateSaleRmaDto(t.Orders.Order, t.Orders.Trans, t.SaleRMA)).ToList();
                return(new PageResult <SaleRmaDto>(lstSaleRma, lst.TotalCount));
            }
        }
Beispiel #24
0
        private void NotifyFailed(OPC_Sale saleOrder, SaleOrderNotificationStatus create, IEnumerable <string> errorList)
        {
            using (var db = new YintaiHZhouContext())
            {
                using (var scope = new TransactionScope())
                {
                    db.OPC_SaleOrderNotificationLog.Add(new OPC_SaleOrderNotificationLog
                    {
                        CreateDate  = DateTime.Now,
                        CreateUser  = JobUserId,
                        SaleOrderNo = saleOrder.SaleOrderNo,
                        Status      = (int)create,
                        Message     = string.Join(";", errorList)
                    });

                    var trade = db.OPC_Sale.FirstOrDefault(x => x.SaleOrderNo == saleOrder.SaleOrderNo);
                    if (trade != null)
                    {
                        trade.CashStatus      = (int)EnumCashStatus.CashingFailed;
                        trade.CashDate        = DateTime.Now;
                        trade.UpdatedDate     = DateTime.Now;
                        trade.UpdatedUser     = JobUserId;
                        db.Entry(trade).State = EntityState.Modified;
                    }
                    db.SaveChanges();
                    scope.Complete();
                }
            }
        }
Beispiel #25
0
 public OPC_AuthUser Get(string userName, string password)
 {
     using (var db = new YintaiHZhouContext())
     {
         return(db.OPC_AuthUsers.FirstOrDefault(t => t.LogonName == userName && t.Password == password));
     }
 }
Beispiel #26
0
        public OPC_SKU Sync(int productId, int colorValueId, int sizeValueId)
        {
            using (var db = new YintaiHZhouContext())
            {
                var skuExt = db.OPC_SKU.FirstOrDefault(p => p.ColorValueId == colorValueId &&
                                                       p.SizeValueId == sizeValueId &&
                                                       p.ProductId == productId);
                // 如果已经存在SKU记录直接返回
                if (skuExt != null)
                {
                    return(skuExt);
                }

                // 创建新的Sku并返回
                var newSku = new OPC_SKU()
                {
                    ProductId    = productId,
                    ColorValueId = colorValueId,
                    SizeValueId  = sizeValueId
                };

                db.OPC_SKU.Add(newSku);
                db.SaveChanges();

                return(newSku);
            }
        }
 /// <summary>
 /// 帮助方法
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="func"></param>
 /// <returns></returns>
 public T Func <T>(Func <DbContext, T> func)
 {
     using (var c = new YintaiHZhouContext())
     {
         return(func(c));
     }
 }
Beispiel #28
0
 public OPC_ShippingSale GetByRmaNo(string rmaNo)
 {
     using (var db = new YintaiHZhouContext())
     {
         return(db.OPC_ShippingSales.FirstOrDefault(t => t.RmaNo == rmaNo));
     }
 }
        /// <summary>
        ///     Creates the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        public bool Create(T entity)
        {
            using (var db = new YintaiHZhouContext())
            {
                if (entity != null)
                {
                    IDbSet <T> set = db.Set <T>();

                    var errors = db.Entry(entity).GetValidationResult();
                    if (!errors.IsValid)
                    {
                        StringBuilder strb = new StringBuilder();
                        foreach (var err in errors.ValidationErrors)
                        {
                            strb.AppendLine(string.Format("property:{0} Error:{1}", err.PropertyName, err.ErrorMessage));
                        }
                        throw new Exception(strb.ToString());
                    }
                    set.Add(entity);
                    db.SaveChanges();
                    return(true);
                }
                return(false);
            }
        }
Beispiel #30
0
 public void Process(StockModel stock)
 {
     using (var db = new YintaiHZhouContext())
     {
         var sku       = db.OPC_SKU.FirstOrDefault(x => x.Id == stock.SkuId);
         var inventory = db.Inventories.FirstOrDefault(x => x.ProductId == sku.ProductId && x.PColorId == sku.ColorValueId && x.PSizeId == sku.SizeValueId);
         if (inventory == null)
         {
             db.Inventories.Add(new Inventory()
             {
                 ProductId          = sku.ProductId,
                 PColorId           = sku.ColorValueId,
                 PSizeId            = sku.SizeValueId,
                 UpdateDate         = DateTime.Now,
                 UpdateUser         = SystemDefine.SystemUser,
                 ChannelInventoryId = 0,
                 Amount             = stock.Count
             });
         }
         else
         {
             inventory.UpdateDate = DateTime.Now;
             inventory.UpdateUser = SystemDefine.SystemUser;
             inventory.Amount     = stock.Count;
         }
         db.SaveChanges();
     }
 }