public async Task <ResponseLogic> RemoveWithObjectAsync(LocationDTO loc) { var foundLocation = await _repository.FindAsync(loc.Id); if (foundLocation is null) { return(ResponseLogic.NOT_FOUND); } var users = await _userRepository.ReadAsync(); var projects = await _projectRepository.ReadAsync(); var occurrences = 0; foreach (var user in users) { if (user.Location == loc) { occurrences++; } } foreach (var project in projects) { if (project.LocationId == loc.Id) { occurrences++; } } if (occurrences > 1) { return(ResponseLogic.SUCCESS); } var success = await _repository.DeleteAsync(loc.Id); if (success) { return(ResponseLogic.SUCCESS); } else { return(ResponseLogic.ERROR_DELETING); } }
public async Task <IHttpActionResult> Delete([FromODataUri] System.Guid key) { logger.Trace("Call LocationController Delete"); await locationRepository.DeleteAsync(key); return(Ok()); }
public async Task <IActionResult> Delete([FromRoute] int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var location = _locationRepository.DeleteAsync(id); return(Ok(location.Result)); }
public async Task <object> Delete([FromRoute] string id) { _logger.LogInformation($"delete.location {id}"); await _repository.DeleteAsync(id); _logger.LogInformation($"deleted.location {id}"); return(new { Message = "Deleted Location" }); }
public async Task <StatusCodeResult> Delete(int id) { if (await _service.DeleteAsync(id) == 1) { return(StatusCode((int)HttpStatusCode.OK)); } else { return(StatusCode((int)HttpStatusCode.ExpectationFailed)); } }
public async Task <BaseResponse> DeleteAsync(UserUIDAndUIDRequest request) { BaseResponse _Response = new BaseResponse(); if (request.UID == Guid.Empty || !await __LocationRepository.DeleteAsync(request.UID, request.UserUID)) { _Response.Success = false; _Response.ErrorMessage = $"{GlobalConstants.ERROR_ACTION_PREFIX} delete {ENTITY_NAME}."; } return(_Response); }
public async Task <DeleteResponse> DeleteAsync(int id) { var deleteResponse = new DeleteResponse(); try { deleteResponse = await _locationRepository.DeleteAsync(id); } catch (Exception ex) { Console.WriteLine(ex); deleteResponse.AddError(ex); _logManager.LogError(ex, "Unable to delete location"); } return(deleteResponse); }
/// <summary> /// Delete location. /// </summary> /// <param name="id">Location id.</param> /// <param name="userEmail">Current user email.</param> /// <returns></returns> public async Task <bool> DeleteLocationAsync(Guid id, string userEmail) { // Get current user id var user = await _accountManager.GetAccountInfoAsync(userEmail); if (user == null) { return(false); } // Get location to edit and check user rights var currentLocation = await _locationRepository.GetLocationAsync(id, false); if (currentLocation == null || currentLocation.OwnerId != user.Id) { return(false); } await _locationRepository.DeleteAsync(currentLocation); return(true); }
public async Task <IActionResult> Delete(int id) { var actionName = "Locations - Delete:"; try { if (id < 1) { _logger.LogWarning($"{actionName} Bad Request - Invalid Id: {id}"); return(RedirectToPage("/BadRequest")); } var item = await _repo.FindByIdAsync(id); if (item is null) { _logger.LogWarning($"{actionName} Item Not Found - Id: {id}"); return(RedirectToPage("/NotFound")); } var success = await _repo.DeleteAsync(item); if (!success) { _logger.LogError($"{actionName} Failed - Id: {id}"); return(RedirectToPage("/InternalServerError")); } return(RedirectToAction(nameof(Index))); } catch (Exception ex) { _logger.LogError($"{actionName} Failed - {ex}"); return(RedirectToPage("/InternalServerError")); } }