public async Task <IHttpActionResult> Deliver(DeliverViewModel viewModel) { try { Package package = Db.Packages.FirstOrDefault(p => p.Id == viewModel.Id); Validator validator = PackageValidator.Deliver(package); if (!validator.Success) { return(BadRequest(validator.ErrorMessage)); } package.Status = viewModel.Success ? Status.Delivered : Status.Returning; await Db.SaveChangesAsync(); return(Ok("Attempting delivery")); } catch { return(BadRequest("An error has occurred")); } }