public async Task <IActionResult> Post([FromBody] cw_cusaccount value) { value.CreatedAt = DateTime.Now; value.IsValid = true; if (User.Identity is ClaimsIdentity identity) { value.CreatedBy = identity.Name ?? "admin"; } _cwCusaccountRpt.Add(value); _cwCusaccountRpt.Commit(); return(new OkObjectResult(value)); }
public async Task <IActionResult> Post([FromBody] cw_cusaccount value) { value.CreatedAt = DateTime.Now; value.IsValid = true; string createBy = string.Empty; if (User.Identity is ClaimsIdentity identity) { createBy = identity.Name ?? "test"; } value.CreatedBy = createBy; using (var tran = _context.Database.BeginTransaction()) { try { _cwCusaccountRpt.Add(value); _cwCusaccountRpt.Commit(); var orderDetail = _yxOrderlistRpt.FindBy(f => f.HouseCode == value.HouseCode && f.IsValid).OrderByDescending(f => f.Id) .First(); //更改订单状态 var order = _yxOrderRpt.GetSingle(f => f.Id == orderDetail.OrderId); order.Status = "已结算"; order.UpdatedAt = DateTime.Now; _yxOrderRpt.Commit(); var orderDetailList = _yxOrderlistRpt.FindBy(f => f.OrderId == order.Id); foreach (var ordd in orderDetailList) { //更新房态 var house = _fwHouseinfoRpt.GetSingle(f => f.Code == ordd.HouseCode); house.State = 1002;//空脏 _fwHouseinfoRpt.Commit(); //新增房态日志 _fwStatelogRepository.Add(new fw_statelog() { HouseCode = orderDetail.HouseCode, OldState = house.State, NewState = 1002, OrderNo = order.OrderNo, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now, IsValid = true, CreatedBy = createBy }); _fwStatelogRepository.Commit(); } tran.Commit(); } catch (Exception e) { return(BadRequest(e.Message)); } } return(new OkObjectResult(value)); }