/// <summary> /// 新增 /// </summary> /// <param name="orderInfoRequestDto"></param> /// <returns></returns> public async Task <JsonResponse> Create(OrderInfoRequestDto orderInfoRequestDto) { orderInfoRequestDto.ToLoginUser(); List <GoodsQueryDto> goodsQuerys = await GetGoodsAsync(orderInfoRequestDto); List <OrderDetailRequestDto> orderDetailRequestDtos = new List <OrderDetailRequestDto>(); orderInfoRequestDto.Id = Guid.NewGuid().ToString(); foreach (var item in goodsQuerys) { var good = orderInfoRequestDto.GoodsRequests.Where(g => g.GoodsId == item.Id).SingleOrDefault(); orderDetailRequestDtos.Add(new OrderDetailRequestDto() { Id = Guid.NewGuid().ToString(), GoodsId = item.Id, OrderId = orderInfoRequestDto.Id, Count = good.Count, Price = item.Price, Money = good.Count * item.Price }); } orderInfoRequestDto.OrderNumber = DateTime.Now.ToString(); orderInfoRequestDto.TotalMoney = orderDetailRequestDtos.Select(d => d.Money).Sum(); orderInfoRequestDto.ExpireTime = DateTime.Now.AddDays(14); var resJson = await new ApplicationEnginee().TryTransactionAsync(async() => { await _orderAppService.CreateAsync(orderInfoRequestDto); await _orderDetailAppService.BatchCreateAsync(orderDetailRequestDtos); }); return(resJson); }
/// <summary> /// 修改 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <JsonResponse> Modify(OrderInfoRequestDto input) { input.InitModifyRequest(); var resJson = await _applicationEnginee.TryTransactionAsync(async() => { await _orderInfoAppService.ModifyAsync(input); }); return(resJson); }
/// <summary> /// 新增 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <JsonResponse> Create(OrderInfoRequestDto input) { input.InitCreateRequest(); input.UserId = input.CreateUserId; List <GoodsRequestDto> goodsQuerys = await RpcService.GetGoodsAsync(input); List <OrderDetailRequestDto> orderDetailRequestDtos = ToDetails(input, goodsQuerys); input.OrderNumber = DateTime.Now.ToString(); input.TotalMoney = orderDetailRequestDtos.Select(d => d.Money).Sum(); input.ExpireTime = DateTime.Now.AddDays(14); var resJson = await new ApplicationEnginee().TryTransactionAsync(async() => { await _orderInfoAppService.CreateAsync(input); await _orderDetailAppService.BatchCreateAsync(orderDetailRequestDtos); }); return(resJson); }
private static List <OrderDetailRequestDto> ToDetails(OrderInfoRequestDto input, List <GoodsRequestDto> goodsQuerys) { List <OrderDetailRequestDto> orderDetailRequestDtos = new List <OrderDetailRequestDto>(); input.Id = Guid.NewGuid().ToString(); foreach (var item in goodsQuerys) { var good = input.GoodsRequestDtos.Where(g => g.Id == item.Id).FirstOrDefault(); var orderDetailRequest = new OrderDetailRequestDto() { Id = Guid.NewGuid().ToString(), GoodsId = item.Id, OrderId = input.Id, Count = good.Count, Price = item.Price, Money = good.Count * item.Price }; orderDetailRequest.InitCreateRequest(input.Payload); orderDetailRequestDtos.Add(orderDetailRequest); } return(orderDetailRequestDtos); }
public void OrderInfo() { // Arrange var sut = new OrderInfoRequestDto() { Header = new WideWorldImporters.Common.Lib.Dto.Base.RequestBaseHeaderDto { RequestedAt = DateTime.Now, RequestedBy = "Ro", RequestId = Guid.NewGuid().ToString() }, Body = new OrderInfoRequestBodyDto { RequestType = OrderInfoRequestType.REQUEST_BY_ID, RequestQuery = "1" } }; // Act var json = JsonConvert.SerializeObject(sut); // Assert Assert.IsFalse(string.IsNullOrWhiteSpace(json)); }
public static OrderInfoResponseDto ToDto(this OrderInfoRequestDto request, OrderDto responseDto, string responderIdentity) { var response = new OrderInfoResponseDto() { Header = new Common.Lib.Dto.Base.ResponseBaseHeaderDto { Request = request.Header, RespondedAt = DateTime.Now, RespondedBy = responderIdentity, ResponsetId = Guid.NewGuid().ToString(), StatusCode = System.Net.HttpStatusCode.OK }, Body = new OrderInfoResponseBodyDto { Orders = new List <OrderDto>() { responseDto } } }; return(response); }
/// <summary> /// 修改 /// </summary> /// <param name="orderInfoRequestDto"></param> /// <returns></returns> public async Task <JsonResponse> Modify(OrderInfoRequestDto orderInfoRequestDto) { orderInfoRequestDto.ToLoginUser(); return(await _orderAppService.ModifyAsync(orderInfoRequestDto)); }