コード例 #1
0
        public async Task <ActionResult <ShippingDto> > CreateShipping(ShippingDto shippingDto)
        {
            var po = await _erpRepository.GetReceivingByPO(shippingDto.PONumber.ToUpper());

            if (po.VendorNo != shippingDto.VenderNo)
            {
                return(BadRequest("Invalid PO or Vender Number."));
            }

            var shipping = _mapper.Map <Shipping>(shippingDto);

            shipping.Vender = await _venderRepository.GetVenderByNumber(shippingDto.VenderNo.ToUpper());

            shipping.User = await _userManager.FindByEmailAsync(shippingDto.UserEmail);

            shipping.ShippingNumber = "SN" + _shippingRepository.LotCountAsync().ToString().PadLeft(7, '0');
            shipping.ShippingMethod = await _venderRepository.GetShippingMethodbyName(shippingDto.LogisticName.ToUpper());

            var lot = new ShippingLot
            {
                LotNumber = "LOT" + shippingDto.ArrivalDate.ToString("MMddyyyy") + shipping.ShippingNumber,

                CreateTime = shippingDto.ArrivalDate
            };

            _shippingRepository.CreateShippingLot(lot);

            shipping.ShippingLot = lot;

            _shippingRepository.AddShippingAsync(shipping);

            if (await _shippingRepository.SaveAllAsync())
            {
                return(Ok(shipping));
            }

            return(BadRequest("Failed to add shipping."));
        }