public async Task <IActionResult> Post([FromBody] kc_store value)
 {
     value.CreatedAt = DateTime.Now;
     value.UpdatedAt = DateTime.Now;
     value.IsValid   = true;
     if (User.Identity is ClaimsIdentity identity)
     {
         value.CreatedBy = identity.Name ?? "test";
     }
     _kcStoreRpt.Add(value);
     _kcStoreRpt.Commit();
     return(new OkObjectResult(value));
 }
示例#2
0
        public async Task <IActionResult> Cancel(int id)
        {
            var single = _kcStoreinRpt.GetSingle(id);

            single.Status    = "作废";
            single.UpdatedAt = DateTime.Now;
            if (User.Identity is ClaimsIdentity identity)
            {
                single.CreatedBy = identity.Name ?? "admin";
            }
            using (var tran = _context.Database.BeginTransaction())
            {
                try
                {
                    var storeList = _kcStoreinlistRpt.FindBy(f => f.orderno == single.OrderNo);
                    foreach (var store in storeList)
                    {
                        var kucun = _kcStoreRpt.GetSingle(f =>
                                                          f.GoodsId == store.GoodsId && f.StoreId == single.StoreId);
                        if (kucun != null)
                        {
                            kucun.Amount = kucun.Amount - store.amount;
                            kucun.Number = kucun.Number - store.number;
                        }
                    }
                    _kcStoreRpt.Commit();
                    _kcStoreinRpt.Commit();
                    tran.Commit();
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    return(BadRequest(ex.Message));
                }
            }
            return(new OkObjectResult(single));
        }