Exemplo n.º 1
0
        public async Task <ResponseMessage <long> > GetAddGoods(string goodsName, int number)
        {
            WareHouse goods = await _wareHouseService.Query(x => x.Goods.Equals(goodsName) && !x.IsRemove);

            string jti = HttpContext.User.FindFirst(x => x.Type == JwtRegisteredClaimNames.Jti).Value;

            if (goods == null)
            {
                long id = await _wareHouseService.Add(new WareHouse()
                {
                    Goods  = goodsName,
                    Number = number
                });

                await _userWareHouseService.Add(new UserWareHouse()
                {
                    Purchase = number,
                    Goods    = goodsName,
                    GoodsId  = id,
                    UserId   = Convert.ToInt64(jti)
                });

                return(new ResponseMessage <long>()
                {
                    Msg = "新增商品成功",
                    Status = 200,
                    Success = true,
                    ResponseInfo = id
                });
            }
            else
            {
                goods.Number += number;
                bool update = await _wareHouseService.Update(goods);

                await _userWareHouseService.Add(new UserWareHouse()
                {
                    Purchase = number,
                    GoodsId  = goods.Id,
                    Goods    = goods.Goods,
                    UserId   = Convert.ToInt64(jti)
                });

                return(update?new ResponseMessage <long>()
                {
                    Msg = "添加商品成功",
                    Status = 200,
                    Success = true
                }: new ResponseMessage <long>()
                {
                    Msg = "添加商品失败",
                    Success = false
                });
            }
        }
Exemplo n.º 2
0
        public IActionResult Add(WareHouse wareHouse)
        {
            string name = wareHouse.Name.ToString();

            if (_wareHouseService.GetCountByName(name))
            {
                return(View(wareHouse));
            }
            else
            {
                _wareHouseService.Add(wareHouse);
                return(RedirectToAction("Index"));
            }
        }
Exemplo n.º 3
0
        public IActionResult Add(WareHouse wareHouse)
        {
            if (!_permissionService.Authorize("AddWareHouse"))
            {
                return(View("_AccessDeniedView"));
            }
            string name = wareHouse.Name.Trim();
            string code = wareHouse.Code.Trim();

            if (_wareHouseService.GetCountByName(name, code))
            {
                return(Error("已有仓库名或仓库代码!"));
            }
            else
            {
                _wareHouseService.Add(wareHouse);
                return(Success());
            }
        }