public IHttpActionResult Release(ScanPackageViewModel viewModel) { Package package = Db.Packages.FirstOrDefault(p => p.Id == viewModel.PackageId); Checkpoint checkpoint = Db.Checkpoints.FirstOrDefault(p => p.Id == viewModel.CheckpointId); if (package == null || checkpoint == null) { return(BadRequest("Invalid data")); } if (package.LastCheckpointChecked != checkpoint.Id) { return(BadRequest("Package is not on this checkpoint")); } if (package.Status != Status.StoppedByLegal) { return(BadRequest("Package is not in a checkpoint")); } if (package.IsStoppedInCustoms) { package.IsStoppedInCustoms = false; } package.Status = Status.InTransit; return(Ok("Package was released from checkpoint")); }
public async Task <IHttpActionResult> Scan(ScanPackageViewModel viewModel) { Package package = Db.Packages.FirstOrDefault(p => p.Id == viewModel.PackageId); Checkpoint checkpoint = Db.Checkpoints.FirstOrDefault(p => p.Id == viewModel.CheckpointId); if (package == null || checkpoint == null) { return(BadRequest("Invalid data")); } if (package.Status != Status.InTransit) { return(BadRequest("Package status invalid, must be in transit")); } package.LastCheckpointChecked = checkpoint.Id; package.Status = Status.StoppedByLegal; if (checkpoint.PlaceType == PlaceType.CustomsFacility) { package.IsStoppedInCustoms = true; } await Db.SaveChangesAsync(); return(Ok("Package is now being scanned in checkpoint")); }