public async Task <IActionResult> Post([FromBody] yx_book value) { value.CreatedAt = DateTime.Now; value.UpdatedAt = DateTime.Now; value.IsValid = true; if (User.Identity is ClaimsIdentity identity) { value.CreatedBy = identity.Name ?? "test"; } _yxBookRpt.Add(value); _yxBookRpt.Commit(); return(new OkObjectResult(value)); }
public async Task <IActionResult> Post([FromBody] NewBooking value) { yx_book book = value.Booking; book.Status = "未完成"; book.OrderNo = GetOrderNo(); book.CreatedAt = DateTime.Now; book.UpdatedAt = DateTime.Now; book.BookTime = DateTime.Now; book.IsValid = true; if (User.Identity is ClaimsIdentity identity) { book.CreatedBy = identity.Name ?? "test"; } using (var tran = _context.Database.BeginTransaction()) { try { _yxBookRpt.Add(book); _yxBookRpt.Commit(); //保存预约服务项目 if (value.Bookservices != null) { foreach (var ser in value.Bookservices) { ser.Id = 0; ser.OrderNo = book.OrderNo; _yxBookserviceRepository.Add(ser); } } _yxBookserviceRepository.Commit(); tran.Commit(); } catch (Exception ex) { tran.Rollback(); return(new BadRequestResult()); } } return(new OkObjectResult(value)); }