Esempio n. 1
0
        public async Task <IActionResult> CreateShippingOrder(string orderId, ShippingOrderDto shippingOrderDto)
        {
            var accountId = User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier).Value;
            var result    = await _orderService.CreateShippingOrder(orderId, shippingOrderDto, accountId);

            return(StatusCode((int)result.Code, result));
        }
Esempio n. 2
0
        public async Task <ApiResult <string> > CreateShippingOrder(string orderId, ShippingOrderDto shippingOrderDto, string accountId)
        {
            var checkEmployee =
                await _context.Employees.Where(x => x.AppuserId.ToString() == accountId).SingleOrDefaultAsync();

            if (checkEmployee == null)
            {
                return(new ApiResult <string>(HttpStatusCode.NotFound, $"Lỗi tài khoản đăng nhập"));
            }
            var checkOrder = await _context.Orders.Where(x => x.Id == orderId).SingleOrDefaultAsync();

            if (checkOrder == null)
            {
                return(new ApiResult <string>(HttpStatusCode.NotFound, $"Không tìm thấy đơn hàng có mã: {orderId}"));
            }
            if (checkOrder.TransactionStatusId == GlobalProperties.CancelTransactionId || checkOrder.TransactionStatusId == GlobalProperties.FinishedTransactionId)
            {
                return(new ApiResult <string>(HttpStatusCode.BadRequest, $"Không thể tạo phiếu vận chuyển cho đơn hàng bị hủy/ hoàn thành"));
            }
            if (checkOrder.TransactionStatusId == GlobalProperties.InventoryTransactionId)
            {
                var checkCustomer =
                    await _context.Customers.Where(x => x.Id == checkOrder.CustomerId).SingleOrDefaultAsync();

                var shippingId = new Guid().ToString("D");
                var shipping   = new Shipping()
                {
                    Id            = shippingId,
                    TransporterId = shippingOrderDto.TransporterId,
                    Description   = shippingOrderDto.Description,
                    CustomerId    = string.IsNullOrEmpty(checkOrder.CustomerId) ? null : checkOrder.CustomerId,
                    CustomerName  = checkCustomer == null ? shippingOrderDto.CustomerName : checkCustomer.Name ?? "",
                    Address       = checkCustomer == null ? shippingOrderDto.CustomerAddress : checkCustomer.Address ?? "",
                    PhoneNumber   = checkCustomer == null
                        ? shippingOrderDto.CustomerPhone
                        : checkCustomer.PhoneNumber ?? "",
                    OrderId          = checkOrder.Id,
                    DateCreated      = DateTime.Now,
                    Fee              = shippingOrderDto.Fee,
                    ShippingStatusId = GlobalProperties.WaitingToShippingId,
                    EmployeeId       = checkEmployee.Id
                };
                await _context.ShippingOrders.AddAsync(shipping);

                await _context.SaveChangesAsync();

                return(new ApiResult <string>(HttpStatusCode.OK)
                {
                    ResultObj = shippingId,
                    Message = "Tạo phiếu vận chuyển thành công"
                });
            }
            return(new ApiResult <string>(HttpStatusCode.BadRequest, $"Chỉ được tạo phiếu vận chuyển cho đơn hàng chưa được xuất kho"));
        }