コード例 #1
0
        /// <summary>
        /// 创建或更新物资
        /// </summary>
        /// <param name="shopId"></param>
        /// <param name="req"></param>
        /// <returns></returns>
        public bool CreateOrUpdate(long shopId, MaterialReq req)
        {
            using (var db = DBFactory.nCoVMS())
            {
                bool shopEnable = shopService.IsShopEnable(shopId);
                if (!shopEnable)
                {
                    throw new Exception("店铺未启用");
                }

                var ext = db.Tmaterial.FirstOrDefault(a => a.Id == req.Id);
                if (ext == null)
                {
                    db.Tmaterial.Add(new Tmaterial
                    {
                        CreateTime    = DateTime.Now,
                        FullName      = req.FullName ?? req.Name,
                        MaxOrderNum   = req.MaxOrderNum,
                        IpmaxOrderNum = req.IpmaxOrderNum,
                        Name          = req.Name,
                        Price         = req.Price,
                        ShopId        = shopId,
                        TotalCount    = req.TotalCount
                    });
                }
                else
                {
                    ext.FullName      = req.FullName ?? req.Name;
                    ext.MaxOrderNum   = req.MaxOrderNum;
                    ext.IpmaxOrderNum = req.IpmaxOrderNum;
                    ext.Name          = req.Name;
                    ext.Price         = req.Price;
                    ext.TotalCount    = req.TotalCount;
                    db.Tmaterial.Update(ext);
                }
                db.SaveChanges();
                return(true);
            }
        }
コード例 #2
0
        public bool CreateOrUpdate([FromBody] MaterialReq req)
        {
            long shopId = HttpContext.User.Identity.ShopId();

            return(materialService.CreateOrUpdate(shopId, req));
        }