public OrderDto Add(OrderDto orderDto) { orderDto.RegisterdAt = DateTime.Now; var orderEntity = orderFactory.CreateEntity(orderDto); var orderDetailsPrice = centerProductService.GetPrice( orderEntity.OrderDetails.Select(x => x.CenterProductId)); long totlaPrice = 0; foreach (var orderDetail in orderEntity.OrderDetails) { var unitPrice = orderDetailsPrice .FirstOrDefault(x => x.Key == orderDetail.CenterProductId).Value; totlaPrice += (orderDetail.Count) * unitPrice; orderDetail.UnitPrice = unitPrice; } orderEntity.RegisterdBy = userService.GetCurrentUserId().ToGuid(); orderEntity.TotalPrice = totlaPrice; orderEntity.OrderStaus = OrderStaus.NoState; if (orderEntity.TargetAddressIsUserProfileAddress) { orderEntity.Address = userService.GetProfile(userService.GetCurrentUserId()).Address; } unitOfWork.OrderRepository.Add(orderEntity); unitOfWork.SaveChanges(); var addedDto = orderFactory.CreateDto(orderEntity); return(addedDto); }