public LogisticPacket Add(LogisticPacket logisticPacket) { _context.LogisticPacketItems.Add(logisticPacket); _context.SaveChanges(); return(logisticPacket); }
public LogisticPacket Update(LogisticPacket logisticPacketChanges) { _context.Entry(logisticPacketChanges).State = EntityState.Modified; _context.SaveChanges(); return(logisticPacketChanges); }
public LogisticPacket Delete(int id) { LogisticPacket logisticPacket = _context.LogisticPacketItems.Find(id); if (logisticPacket != null) { _context.LogisticPacketItems.Remove(logisticPacket); _context.SaveChanges(); } return(logisticPacket); }
public ActionResult <LogisticPacket> Add(LogisticPacket logisticPacket) { return(_logisticPacketRepo.Update( UpdateCreatedDate( GenerateAWB( _logisticPacketRepo.Add( UpdateCostBasedOnMargin( UpdateCostBasedOnRO(logisticPacket) ) ) ) ) )); }
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); }
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)); }
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); }
private LogisticPacket UpdateCreatedDate(LogisticPacket logisticPacket) { logisticPacket.DateCreated = DateTime.Now; return(logisticPacket); }
private LogisticPacket UpdateCostBasedOnMargin(LogisticPacket logisticPacket) { logisticPacket.CurrentNominal = logisticPacket.CurrentNominal + _logisticServiceRepo.Get(logisticPacket.LogisticServiceId).ROMargin; return(logisticPacket); }