Example #1
0
 /// <summary>
 /// 增加商品缓存
 /// </summary>
 /// <param name="item"></param>
 public static void AddAppCommondityDTOCache(CommodityDTO item)
 {
     if (item != null && !item.IsDel && item.State < 2)
     {
         //   GlobalCacheWrapper.Add("G_Commodity:" + item.AppId, item.Id.ToString(), item, CacheTypeEnum.redisSS, "BTPCache");
         GlobalCacheWrapper.Add("G_CommodityDetail", item.Id.ToString(), item, CacheTypeEnum.redisSS, "BTPCache");
     }
 }
Example #2
0
        /// <summary>
        /// 添加商品
        /// </summary>
        /// <param name="sellerID">卖家ID</param>
        /// <returns></returns>
        public void SaveCommodity(CommodityDTO commodityDTO)
        {
            Commodity      commodity      = new Commodity().FromEntityData(commodityDTO);
            ContextSession contextSession = ContextFactory.CurrentThreadContext;

            commodity.EntityState = System.Data.EntityState.Added;
            contextSession.SaveObject(commodity);
            contextSession.SaveChanges();
            RefreshCache(EntityState.Added);
        }
Example #3
0
        /// <summary>
        /// 获得商品原价
        /// </summary>
        /// <param name="com"></param>
        /// <param name="stock"></param>
        /// <returns></returns>
        private decimal getOriPrice(CommodityDTO com, Deploy.CommodityStockDTO stock)
        {
            decimal result = 0.0m;

            if (stock != null)
            {
                result = stock.Price;
            }
            else
            {
                result = com.Price;
            }
            return(result);
        }
Example #4
0
        /// <summary>
        /// 修改商品
        /// </summary>
        /// <param name="userId">用户ID</param>
        /// <param name="reviewId">评价ID</param>
        /// <param name="name">属性名称</param>
        /// <returns></returns>
        public void UpdateCommodity(System.Guid appId, CommodityDTO commodityDTO)
        {
            Commodity      commodity      = Commodity.ObjectSet().Where(n => n.Id == commodityDTO.Id && n.AppId == appId && n.CommodityType == 0).FirstOrDefault();
            ContextSession contextSession = ContextFactory.CurrentThreadContext;

            commodity.EntityState  = System.Data.EntityState.Modified;
            commodity.Price        = commodityDTO.Price;
            commodity.Stock        = commodityDTO.Stock;
            commodity.Name         = commodityDTO.Name;
            commodity.PicturesPath = commodityDTO.PicturesPath;
            commodity.Description  = commodityDTO.Description;
            commodity.IsDel        = false;
            commodity.AppId        = commodityDTO.AppId;
            commodity.No_Code      = commodityDTO.No_Code;
            contextSession.SaveObject(commodity);
            contextSession.SaveChanges();
            RefreshCache(EntityState.Modified);
        }
Example #5
0
        public JsonResult GetCommoditiesByCode(string code, string name, string originalName, int commodityTypeID, int commodityCategoryID)
        {
            try
            {
                var commodityResult = new { CommodityID = 0, Code = "", Name = "", VATPercent = new decimal(0) };

                var result = commodityRepository.SearchCommoditiesByName(code, null).Select(s => new { s.CommodityID, s.Code, s.Name, s.CommodityCategory.VATPercent });
                if (result.Count() > 0)
                {
                    commodityResult = new { CommodityID = result.First().CommodityID, Code = result.First().Code, Name = result.First().Name, VATPercent = result.First().VATPercent }
                }
                ;
                else
                {
                    CommodityDTO commodityDTO = new CommodityDTO();
                    commodityDTO.Code                = code;
                    commodityDTO.Name                = name;
                    commodityDTO.OfficialName        = name;
                    commodityDTO.OriginalName        = originalName;
                    commodityDTO.CommodityTypeID     = commodityTypeID;
                    commodityDTO.CommodityCategoryID = commodityCategoryID;

                    CommodityService commodityService = new CommodityService(this.commodityRepository);
                    commodityService.UserID = 2; //Ai cung co quyen add Commodity, boi viec add can cu theo UserID = 2: [email protected]

                    if (commodityService.Save(commodityDTO))
                    {
                        commodityResult = new { CommodityID = commodityDTO.CommodityID, Code = commodityDTO.Code, Name = commodityDTO.Name, VATPercent = new decimal(10) }
                    }
                    ;
                }

                return(Json(commodityResult, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { CommodityID = 0, Code = ex.Message, Name = ex.Message, VATPercent = new decimal(10) }, JsonRequestBehavior.AllowGet));
            }
        }
        public IList<CommodityDTO> GetCommodities(Guid storeId)
        {
            var commodityList = new List<CommodityDTO>();

            var commodityTrasferList = _commodityTransferRepository.GetAll();
            var commodityTransfer = commodityTrasferList.Where(n => n.DocumentIssuerCostCentre.Id.Equals(storeId)).ToList();
            foreach (CommodityTransferNote sourcingDocument in commodityTransfer)
            {
                if (sourcingDocument.Status != DocumentSourcingStatus.Approved) continue;
                foreach (var source in sourcingDocument.LineItems.Where(k => k.LineItemStatus == SourcingLineItemStatus.New).Select(l => l.Commodity.Id).Distinct())
                {
                    var commodities = _commodityRepository.GetById(source);
                    if(commodityList.Select(l=>l.Id).Distinct().Contains(commodities.Id)) continue;
                    var commodity = new CommodityDTO()
                    {
                        Id = commodities.Id,
                        Name = commodities.Name
                    };
                    commodityList.Add(commodity);
                }
            }
            return commodityList;
        }
 public IList<LineItemDTO> GetLineItems(Guid storeId, Guid commodityId, Guid gradeID)
 {
     var lineItemList = new List<LineItemDTO>();
     var commodityTransfer = _commodityTransferRepository.GetAll();
     foreach (CommodityTransferNote sourcingDocument in commodityTransfer.Where(n => n.DocumentIssuerCostCentre.Id.Equals(storeId)))
     {
         if (sourcingDocument.Status != DocumentSourcingStatus.Approved) continue;
         foreach (var items in sourcingDocument.LineItems)
         {
             if (items.Commodity.Id.Equals(commodityId) && items.CommodityGrade.Id.Equals(gradeID) && items.LineItemStatus == SourcingLineItemStatus.New)
             {
                 var store = _storeRepository.GetById(storeId);
                 var itemStore = new StoreDTO()
                 {
                     Id = store.Id,
                     Name = store.Name
                 };
                 var commodity = new CommodityDTO()
                 {
                     Id = items.Commodity.Id,
                     Name = items.Commodity.Name
                 };
                 var grade = new GradeDTO()
                 {
                     Id = items.CommodityGrade.Id,
                     Name = items.CommodityGrade.Name
                 };
                 var item = new LineItemDTO()
                 {
                     BatchNo = items.ContainerNo,
                     Store = itemStore,
                     Commodity = commodity,
                     Grade = grade,
                     IsSelected = false,
                     Id = items.Id,
                     Weight = items.Weight
                 };
                 lineItemList.Add(item);
             }
         }
     }
     return lineItemList;
 }
Example #8
0
 public Commodity Map(CommodityDTO dto)
 {
     if (dto == null) return null;
     var commodity = Mapper.Map<CommodityDTO, Commodity>(dto);
     commodity.CommodityType = _commodityTypeRepository.GetById(dto.CommodityTypeId);
     commodity.CommodityGrades = dto.CommodityGrades.Select(n => Map(n, dto.MasterId)).ToList();
     return commodity;
 }