예제 #1
0
        public LogisticPacket Add(LogisticPacket logisticPacket)
        {
            _context.LogisticPacketItems.Add(logisticPacket);
            _context.SaveChanges();

            return(logisticPacket);
        }
예제 #2
0
        public LogisticPacket Update(LogisticPacket logisticPacketChanges)
        {
            _context.Entry(logisticPacketChanges).State = EntityState.Modified;
            _context.SaveChanges();

            return(logisticPacketChanges);
        }
예제 #3
0
        public LogisticPacket Delete(int id)
        {
            LogisticPacket logisticPacket = _context.LogisticPacketItems.Find(id);

            if (logisticPacket != null)
            {
                _context.LogisticPacketItems.Remove(logisticPacket);
                _context.SaveChanges();
            }

            return(logisticPacket);
        }
예제 #4
0
 public ActionResult <LogisticPacket> Add(LogisticPacket logisticPacket)
 {
     return(_logisticPacketRepo.Update(
                UpdateCreatedDate(
                    GenerateAWB(
                        _logisticPacketRepo.Add(
                            UpdateCostBasedOnMargin(
                                UpdateCostBasedOnRO(logisticPacket)
                                )
                            )
                        )
                    )
                ));
 }
예제 #5
0
        private LogisticPacket UpdateCostBasedOnRO(LogisticPacket logisticPacket)
        {
            var roCityFrom = _rajaOngkirCityRepository.Get().Where(c => c.RegencyId == logisticPacket.AddressFrom.RegencyId).FirstOrDefault();
            var roCityTo   = _rajaOngkirCityRepository.Get().Where(c => c.RegencyId == logisticPacket.AddressTo.RegencyId).FirstOrDefault();

            var roCostResp = _rajaOngkirClient.GetPrice(roCityFrom.ROCityId.ToString(), roCityTo.ROCityId.ToString(), logisticPacket.UnitNumber);

            bool found = false;

            foreach (JToken eachExp in roCostResp.SelectToken("rajaongkir.results"))
            {
                if ((string)eachExp["code"] == _rajaOngkirClient.DefaultCourier)
                {
                    foreach (JToken eachServ in eachExp.SelectToken("costs"))
                    {
                        if ((string)eachServ["service"] == _rajaOngkirClient.DefaultService)
                        {
                            foreach (JToken eachCost in eachServ.SelectToken("cost"))
                            {
                                try
                                {
                                    logisticPacket.CurrentNominal = (decimal)eachCost["value"];
                                    found = true;
                                    break;
                                } catch (Exception e) {}
                            }

                            if (found)
                            {
                                break;
                            }
                        }
                    }
                }

                if (found)
                {
                    break;
                }
            }

            if (!found)
            {
                throw new Exception("Could not fetct cost from Raja Ongkir");
            }

            return(logisticPacket);
        }
예제 #6
0
        public ActionResult <LogisticPacket> Update(int id, LogisticPacket logisticPacket)
        {
            if (id != logisticPacket.Id)
            {
                return(BadRequest());
            }

            var logisticPacketItem = _logisticPacketRepo.Get(id);

            if (logisticPacketItem == null)
            {
                return(NotFound());
            }

            return(_logisticPacketRepo.Update(logisticPacket));
        }
예제 #7
0
        private LogisticPacket GenerateAWB(LogisticPacket logisticPacket)
        {
            int    reserved = 0;
            string generatedCode;

            do
            {
                reserved++;

                if (reserved > 999)
                {
                    throw new Exception("Out of reserved int");
                }

                generatedCode = AirwayBill.GenerateCode(logisticPacket.AddressFrom.RegencyId, logisticPacket.Id, 1, reserved);
            } while (_logisticPacketRepo.Get().Where(p => p.AirWayBill == generatedCode).ToList().Count() > 0);

            logisticPacket.AirWayBill = generatedCode;

            return(logisticPacket);
        }
예제 #8
0
        private LogisticPacket UpdateCreatedDate(LogisticPacket logisticPacket)
        {
            logisticPacket.DateCreated = DateTime.Now;

            return(logisticPacket);
        }
예제 #9
0
 private LogisticPacket UpdateCostBasedOnMargin(LogisticPacket logisticPacket)
 {
     logisticPacket.CurrentNominal = logisticPacket.CurrentNominal + _logisticServiceRepo.Get(logisticPacket.LogisticServiceId).ROMargin;
     return(logisticPacket);
 }