public async Task<IHttpActionResult> getCowForEdit(string CowID) { var processingResult = new ServiceProcessingResult<Cow> { IsSuccessful = true }; var cowDataService = new CowDataService(); var cowResult = await cowDataService.getCowForEdit(CowID); if (!cowResult.IsSuccessful) { processingResult.IsSuccessful = false; processingResult.Error = new ProcessingError("Unable to retrieve cow data for edit.", "Unable to retrieve cow data for edit.", true, false); return Ok(processingResult); } processingResult.Data = cowResult.Data; return Ok(processingResult); }
public async Task<IHttpActionResult> GetCowsTotal() { var result = new ServiceProcessingResult<List<Cow>>(); var cowService = new CowDataService(); var cowResult = await cowService.getActiveCows(LoggedInUser.ClientID); if (!cowResult.IsSuccessful) { result.Error = new ProcessingError("An error occurred while getting total cows.","Could not retrieve total cows, please try again. If the problem persists contact support.", true); result.IsSuccessful = false; return Ok(result); } result.IsSuccessful = true; result.Data = cowResult.Data; return Ok(result); }
public async Task<IHttpActionResult> GetActiveCows() { var cowService = new CowDataService(); try { var processingResult = await cowService.getActiveCows(LoggedInUser.ClientID); if (!processingResult.IsSuccessful) { processingResult.Error = new ProcessingError("An error occurred while getting all available Cows.", "Could not retrieve Cows, please try again. If the problem persists contact support.", true); return Ok(processingResult); } processingResult.Data = processingResult.Data.OrderBy(c => c.TagNumber).ToList(); return Ok(processingResult); } catch (Exception ex) { var processingResult = new ServiceProcessingResult(); ExceptionlessClient.Default.ProcessQueue(); ex.ToExceptionless().Submit(); return Ok(processingResult); } }
public async Task<IHttpActionResult> EditCow(CowsUpdateBindingModel model) { var processingResult = new ServiceProcessingResult<Cow>() { IsSuccessful = true }; if (!ModelState.IsValid) { var userHelp = GetModelStateErrorsAsString(ModelState); processingResult.IsSuccessful = false; processingResult.Error = new ProcessingError("Cow validation failed", "Cow validation failed", false, true); return Ok(processingResult); } var cowService = new CowDataService(); var updatedCow = model.ToCow(LoggedInUser.ClientID); processingResult = await cowService.UpdateCow(updatedCow); if (!processingResult.IsSuccessful) { var logMessage = String.Format("A error occurred while editing cow with Id: {0}."); Logger.Fatal(logMessage); return Ok(processingResult); } return Ok(processingResult); }