public IActionResult PostIndent([FromBody] IndentDto indentDto)
        {
            if (indentDto == null)
            {
                return(BadRequest());
            }
            Indent model = new Indent();

            model.Account      = indentDto.Account;
            model.Amount       = indentDto.Amount;
            model.CreatTIme    = System.DateTime.Now;
            model.Count        = indentDto.Count;
            model.Price        = _productRepository.GetSeed(indentDto.SeedID).Price;
            model.FinishedTime = System.DateTime.Now;
            model.SeedID       = _productRepository.GetSeed(indentDto.SeedID).SeedID;
            model.Status       = IndentStatus.创建;

            { var InventoryModel = _productRepository.GetInventory(model.SellerID, model.SeedID);
              if (InventoryModel.Count - model.Count < 0)
              {
                  return(BadRequest("库存不足"));
              }
            }


            _productRepository.AddIndent(model);
            if (!_productRepository.Save())
            {
                return(BadRequest("错误"));
            }
            return(Ok());
        }
Esempio n. 2
0
        /// <summary>
        ///订单显示
        /// </summary>
        /// <param name="orderSite"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public List <IndentDto> GetIndentPageList(int userId, int OrderSite)
        {
            using (MySqlConnection conn = new MySqlConnection(connStr))
            {
                string           sql1      = string.Format("select orders.*,address.detailaddress,address.AddressPerson from address join orders on address.Id = orders.addressId  where orders.usersId = {0} and orders.OrderSite={1}", userId, OrderSite);
                var              orderlist = conn.Query <IndentDto>(sql1).ToList();
                string           sql2      = string.Format("select goods.goodsimg as img,goods.GoodsName,ordergoods.ordersid  from ordergoods join goods on ordergoods.GoodsId=goods.Id   where UsersId={0}", userId);
                var              goodslist = conn.Query <orderImg>(sql2).ToList();
                List <IndentDto> indent    = new List <IndentDto>();
                foreach (var item in orderlist)
                {
                    IndentDto indentDto = new IndentDto();
                    indentDto.ApplyMethod    = item.ApplyMethod;
                    indentDto.Id             = item.Id;
                    indentDto.AddressPerson  = item.AddressPerson;
                    indentDto.PracticalMoney = item.PracticalMoney;
                    indentDto.OrderSite      = item.OrderSite;
                    List <string> imgs = new List <string>();
                    foreach (var item1 in goodslist.Where(a => a.ordersid == item.Id))
                    {
                        imgs.Add(item1.img);
                    }
                    indentDto.imgs = imgs;
                    indent.Add(indentDto);
                }

                return(indent);
            }
        }
 public async Task <JsonResult> AddIndent([FromBody] IndentDto IndentDto)
 {
     try
     {
         RepositoryWrapper.IndentDetails.AddIndent(IndentDto.IndentDetails, IndentDto.IndentProducts);
         return(await base.FinalizStatusCodeeMessage("Indent Created Successfully", 200));
     }
     catch (Exception ex)
     {
         return(await base.FinalizStatusCodeeMessage("Error: Failure in Indent Create : " + ex, 500));
     }
 }
        public IActionResult GetIndent(int indentid)
        {
            var model = _productRepository.GetIndentForId(indentid);

            if (model == null)
            {
                return(BadRequest());
            }
            IndentDto result = new IndentDto
            {
                Account      = model.Account,
                Amount       = model.Amount,
                CreatTIme    = model.CreatTIme,
                Count        = model.Count,
                Price        = model.Price,
                FinishedTime = model.FinishedTime,
                IndentID     = model.IndentID,
                SeedID       = model.SeedID,
                Status       = model.Status
            };

            return(Ok(result));
        }
        public IActionResult PatchIndent(int indentID, [FromBody] JsonPatchDocument <IndentDto> jsonPatch)
        {
            if (jsonPatch == null)
            {
                return(BadRequest());
            }
            var model = _productRepository.GetIndentForId(indentID);

            if (model == null)
            {
                return(NotFound());
            }
            IndentDto patch = new IndentDto
            {
                Account      = model.Account,
                Amount       = model.Amount,
                CreatTIme    = model.CreatTIme,
                Count        = model.Count,
                FinishedTime = System.DateTime.Now,
                Status       = model.Status,
                SeedID       = _productRepository.GetSeed(model.SeedID).SeedID,
                Price        = _productRepository.GetSeed(model.SeedID).Price
            };



            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            TryValidateModel(patch);
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            model.Account      = patch.Account;
            model.Amount       = patch.Amount;
            model.CreatTIme    = patch.CreatTIme;
            model.FinishedTime = patch.FinishedTime;
            model.SeedID       = patch.SeedID;
            model.Status       = patch.Status;

            if (!_productRepository.Save())
            {
                return(StatusCode(500, "更新出错"));
            }
            else
            if (model.Status != IndentStatus.异常)
            {
                _productRepository.AddSellInformation(new SellInformation
                {
                    Account   = model.Account,
                    IndentID  = model.IndentID,
                    SeedID    = model.SeedID,
                    SellCount = model.Count,
                    SellerID  = model.SellerID,
                    SellTime  = model.FinishedTime
                });
                _productRepository.GetInventory(model.SellerID, model.SeedID).Count -= model.Count;
                if (!_productRepository.Save())
                {
                    return(StatusCode(500, "更新出错在向库存更新数目时出错"));
                }
            }
            return(NoContent());
        }
        public IActionResult PutIndent(int indentid, [FromBody] IndentDto indentDto)
        {
            if (indentDto == null)
            {
                return(BadRequest());
            }
            Indent Put = new Indent
            {
                Account      = indentDto.Account,
                Amount       = indentDto.Amount,
                CreatTIme    = indentDto.CreatTIme,
                FinishedTime = indentDto.FinishedTime,
                Count        = indentDto.Count,
                Price        = _productRepository.GetSeed(indentDto.SeedID).Price,
                SeedID       = _productRepository.GetSeed(indentDto.SeedID).SeedID,
                Status       = indentDto.Status,
                SellerID     = _productRepository.GetSeller(indentDto.SellerID).SellerID,
            };
            var model = _productRepository.GetIndentForId(indentid);

            if (model == null)
            {
                return(NotFound());
            }


            var InventoryModel = _productRepository.GetInventory(Put.SellerID, Put.SeedID);

            if (InventoryModel == null)
            {
                return(BadRequest("无此库存"));
            }
            if (InventoryModel.Count - Put.Count < 0)
            {
                return(BadRequest("库存不足"));
            }
            model.Account      = Put.Account;
            model.Amount       = Put.Amount;
            model.CreatTIme    = Put.CreatTIme;
            model.FinishedTime = Put.FinishedTime;
            model.SeedID       = Put.SeedID;
            model.Status       = Put.Status;
            model.SellerID     = Put.SellerID;

            if (model.Status == IndentStatus.完成)
            {
                _productRepository.AddSellInformation(new SellInformation
                {
                    Account   = model.Account,
                    IndentID  = model.IndentID,
                    SeedID    = model.SeedID,
                    SellCount = model.Count,
                    SellerID  = model.SellerID,
                    SellTime  = model.FinishedTime
                });
            }


            if (!_productRepository.Save())
            {
                return(BadRequest());
            }

            return(NoContent());
        }