Пример #1
0
        public string ReadShippingLotCsvFile()
        {
            try
            {
                List <ShippingLot> result  = new List <ShippingLot>();
                StreamReader       sr      = new StreamReader(@"Assets/ShippingLots.csv");
                string             strLine = string.Empty;
                string[]           value   = null;
                int x = 0;
                while (!sr.EndOfStream)
                {
                    x++;
                    strLine = sr.ReadLine();
                    value   = strLine.Split(',');
                    if (x > 1 && value.Length == 3)
                    {
                        try
                        {
                            var shippinglot = new ShippingLot();
                            shippinglot.Id         = Int32.Parse(value[0]);
                            shippinglot.LotNumber  = value[1];
                            shippinglot.CreateTime = DateTime.Parse(value[2]);

                            result.Add(shippinglot);
                        }
                        catch (Exception ex)
                        {
                            string msg = ex.Message;
                        }
                    }
                }

                _db.ShippingLots.AddRange(result);
                _db.SaveChanges();

                GC.Collect();


                int counter = _db.ShippingLots.Count();
                if (counter < 10)
                {
                    return("Process error less than 10 records");
                }

                return("Completed");
            }
            catch (DbUpdateException efex)
            {
                efex.Message.FirstOrDefault();
                return("Not pass because db");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
        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."));
        }
Пример #3
0
 public void CreateShippingLot(ShippingLot lot)
 {
     _context.ShippingLots.Add(lot);
 }