public async Task <IActionResult> Delete(string moniker, int speakerId, int id)
        {
            try
            {
                var talk = _repo.GetTalk(id);
                if (talk == null)
                {
                    return(NotFound());
                }

                if (Request.Headers.ContainsKey("If-Match"))
                {
                    var etag = Request.Headers["If-Match"].First();

                    if (etag != Convert.ToBase64String(talk.RowVersion))
                    {
                        return(StatusCode((int)HttpStatusCode.PreconditionFailed));
                    }
                }

                _repo.Delete(talk);

                if (await _repo.SaveAllAsync())
                {
                    return(Ok());
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failed to delete talk: {ex}");
            }

            return(BadRequest("Failed to delete talk"));
        }
Exemple #2
0
        //http://localhost:6600/api/camps/Neza2020
        public async Task <ActionResult <ModeloCampamento> > EliminarCampamento(string moniker)
        {
            try
            {
                var campamentoViejo = await campamentoRepositorio.GetCampAsync(moniker);

                if (campamentoViejo == null)
                {
                    return(NotFound("No se encontro el campo con es apodo "));
                }

                campamentoRepositorio.Delete(campamentoViejo);

                if (await campamentoRepositorio.SaveChangesAsync())
                {
                    return(Ok());
                }
                else
                {
                    return(BadRequest("Error al eliminar el campamento"));
                }
            }
            catch (Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Falla en la BD"));
            }
        }
        public async Task <IActionResult> DeleteCamp(string moniker)
        {
            try
            {
                var camp = await campRepository.GetCampAsync(moniker);

                if (camp == null)
                {
                    return(NotFound());
                }

                campRepository.Delete(camp);

                if (await campRepository.SaveChangesAsync())
                {
                    return(Ok());
                }

                return(BadRequest());
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "DeleteCamp - " + e.ToString()));
            }
        }
        public async Task <ActionResult <CampModel> > Delete(string moniker, int id)
        {
            try
            {
                var talk = await _repository.GetTalkByMonikerAsync(moniker, id);

                if (talk == null)
                {
                    return(NotFound("Couldn't find the talk."));
                }

                _repository.Delete(talk);

                if (await _repository.SaveChangesAsync())
                {
                    return(Ok());
                }
            }
            catch (Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure"));
            }

            return(BadRequest("Failed to delete the talk!"));
        }
        public async Task <IActionResult> Delete(string moniker, int id)
        {
            try
            {
                var speaker = _repository.GetSpeaker(id);
                if (speaker == null)
                {
                    return(NotFound());
                }
                if (speaker.Camp.Moniker != moniker)
                {
                    return(BadRequest("Speaker and Camp do not match"));
                }

                _repository.Delete(speaker);

                if (await _repository.SaveAllAsync())
                {
                    return(Ok());
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Exception thrown while deleting speaker: {ex}");
            }

            return(BadRequest("Could not delete speaker"));
        }
Exemple #6
0
        public async Task <IActionResult> Delete(int id)
        {
            try
            {
                var speaker = await _repository.GetSpeakerAsync(id);

                if (speaker == null)
                {
                    return(NotFound());
                }

                _repository.Delete(speaker);

                if (await _repository.SaveChangesAsync())
                {
                    return(Ok());
                }
                else
                {
                    return(BadRequest("Failed to delete the speaker."));
                }
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Database Failure"));

                throw;
            }
        }
Exemple #7
0
        public async Task <IActionResult> Delete(string moniker)
        {
            //try
            //{
            var oldCamp = await _repository.GetCampAsync(moniker);

            if (oldCamp == null)
            {
                return(NotFound());
            }

            _repository.Delete(oldCamp);

            if (await _repository.SaveChangesAsync())
            {
                return(Ok());
            }
            //}
            //catch (Exception ex)
            //{
            //   return this.StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
            //}

            return(BadRequest());
        }
Exemple #8
0
        public async Task <IActionResult> Delete(string moniker)
        {
            try
            {
                var oldCamp = await repository.GetCampAsync(moniker);

                if (oldCamp == null)
                {
                    return(NotFound($"Could not find camp with moniker of {moniker}"));
                }

                repository.Delete(oldCamp);

                if (await repository.SaveChangesAsync())
                {
                    return(Ok());
                }
            }
            catch (Exception e)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure"));
            }

            return(BadRequest());
        }
        public async Task <IActionResult> Delete(string moniker, int id)
        {
            try
            {
                var talk = await _repository.GetTalkByMonikerAsync(moniker, id);

                if (talk == null)
                {
                    return(NotFound("Failed to find the talk to delete"));
                }

                _repository.Delete(talk);
                if (await _repository.SaveChangesAsync())
                {
                    return(Ok());
                }
                else
                {
                    return(BadRequest("Failed to delete talk"));
                }
            }
            catch (Exception e)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Database Failure: {e.Message}"));
            }
        }
        public async Task <IActionResult> Delete(string moniker)
        {
            try
            {
                var campToDelete = await _repository.GetCampAsync(moniker);

                if (campToDelete == null)
                {
                    return(NotFound($"Could not found camp with moniker: {moniker}"));
                }

                _repository.Delete(campToDelete);

                if (await _repository.SaveChangesAsync())
                {
                    return(Ok());
                }
                else
                {
                    return(BadRequest("Could not delete camp"));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, $"Database Failure {ex}"));
            }
        }
        public async Task <IActionResult> Delete(string moniker)
        {
            try
            {
                var camp = _repo.GetCampByMoniker(moniker);
                if (camp == null)
                {
                    return(NotFound($"Could not find Camp with Moniker: {moniker}"));
                }

                _repo.Delete(camp);

                if (await _repo.SaveAllAsync())
                {
                    return(Ok());
                }
                else
                {
                    _logger.LogWarning("could not delete camp");
                }
            }
            catch (Exception)
            {
            }
            return(BadRequest("Couldnt delete Camp"));
        }
Exemple #12
0
        public async Task <IActionResult> Delete(string moniker)
        {
            try
            {
                var oldCamp = _repo.GetCampByMonikerWithSpeakers(moniker);

                if (oldCamp == null)
                {
                    return(NotFound($"Could not find camp with moniker of {moniker}"));
                }

                _repo.Delete(oldCamp);

                if (await _repo.SaveAllAsync())
                {
                    return(Ok());
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Threw exception while deleting camp: {ex}");
            }

            return(BadRequest("Could not delete camp"));
        }
        public async Task <IActionResult> Delete(string moniker)
        {
            try
            {
                var oldCamp = await _repository.GetCampAsync(moniker);

                if (oldCamp == null)
                {
                    return(NotFound());
                }

                _repository.Delete(oldCamp);

                if (await _repository.SaveChangesAsync())
                {
                    return(Ok());
                }
            }
            catch (Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure"));
            }

            return(BadRequest("Failed to delete the camp"));
        }
Exemple #14
0
        public async Task <IActionResult> Delete(string moniker)
        {
            try
            {
                var camp = await _repository.GetCampAsync(moniker);

                if (camp == null)
                {
                    return(BadRequest(new { message = "Camp with that moniker not exists." }));
                }


                _repository.Delete(camp);

                if (await _repository.SaveChangesAsync())
                {
                    return(Ok(new { message = $"Camp with {moniker} was successfully deleted." }));
                }
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Database Failure"));
            }

            return(StatusCode(StatusCodes.Status500InternalServerError, "Something goes wrong"));
        }
Exemple #15
0
        public async Task <IActionResult> Delete(string moniker, int id)
        {
            try
            {
                var talk = await _campRepository.GetTalkByMonikerAsync(moniker, id);

                if (talk == null)
                {
                    return(NotFound());
                }

                _campRepository.Delete(talk);

                if (await _campRepository.SaveChangesAsync())
                {
                    return(Ok());
                }
                else
                {
                    return(BadRequest("Failed to delete"));
                }
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to get talks"));
            }
        }
Exemple #16
0
        public async Task <IActionResult> Delete(string moniker, int id)
        {
            try {
                var talk = await campRepository.GetTalkByMonikerAsync(moniker, id);

                if (talk == null)
                {
                    return(NotFound($"Talk {id} not found"));
                }

                campRepository.Delete(talk);

                if (await campRepository.SaveChangesAsync())
                {
                    return(Ok());
                }
                else
                {
                    return(BadRequest($"Could not delete talk {id}"));
                }
            }
            catch (Exception) {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Exemple #17
0
        public async Task <IActionResult> DeleteCamp(string moniker)
        {
            try
            {
                var oldCamp = await _campRepository.GetCampAsync(moniker, true);

                if (oldCamp == null)
                {
                    return(NotFound($"Camp with moniker: {moniker} does not exist"));
                }

                foreach (var talk in oldCamp.Talks)
                {
                    //_campRepository.Delete(talk.Speaker);
                    if (talk != null)
                    {
                        if (talk.Speaker != null)
                        {
                            _campRepository.Delete(talk.Speaker);
                        }
                        _campRepository.Delete(talk);
                    }
                }
                _campRepository.Delete(oldCamp);


                if (await _campRepository.SaveChangesAsync())
                {
                    return(Ok());
                }
            }
            catch (Exception e)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database failure"));
            }

            return(BadRequest());
        }
Exemple #18
0
        public async Task <IActionResult> Delete(int id)
        {
            var oldCamp = _campRepository.GetCamp(id);

            if (oldCamp == null)
            {
                return(NotFound($"Camp with id {id} not found"));
            }

            // business rule validation here

            _campRepository.Delete(oldCamp);

            await _campRepository.SaveAllAsync();

            return(Ok());
        }
Exemple #19
0
        public async Task <IActionResult> Delete(string moniker)
        {
            try
            {
                var camp = _repository.GetCampByMoniker(moniker);
                _repository.Delete(camp);
                if (await _repository.SaveAllAsync())
                {
                    return(Ok());
                }
            }
            catch (Exception)
            {
            }

            return(BadRequest());
        }
Exemple #20
0
        public async Task <IHttpActionResult> Delete(string moniker, int talkid)
        {
            var talk = await _iCampRepository.GetTalkByMonikerAsync(moniker, talkid);

            if (talk == null)
            {
                return(NotFound());
            }
            _iCampRepository.Delete(talk);
            if (await _iCampRepository.SaveChangesAsync())
            {
                return(Ok());
            }
            else
            {
                return(InternalServerError());
            }
        }
        public async Task <IActionResult> Delete(string moniker)
        {
            try
            {
                var oldCamp = await _campRepository.GetCampAsync(moniker);

                if (oldCamp == null)
                {
                    return(NotFound($"Couldn't find camp with moniker {moniker}"));
                }
                _campRepository.Delete(oldCamp);

                return(await _campRepository.SaveChangesAsync() ? Ok() : (ActionResult)BadRequest());
            }
            catch (Exception ex)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Database Failure{ex.Message}"));
            }
        }
        [HttpDelete("{moniker}")]  public async Task <IActionResult> Delete(string moniker)
        {
            try
            {
                var oldcamp = await _repository.GetCampAsync(moniker);

                if (oldcamp == null)
                {
                    return(NotFound("could not locate provided moniker"));
                }

                _repository.Delete(oldcamp);
                await _repository.SaveChangesAsync();

                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest(e));
            }
        }
 public async Task <IActionResult> Delete(string moniker)
 {
     try
     {
         var oldCamp = _repo.GetCampByMoniker(moniker);
         if (oldCamp == null)
         {
             return(NotFound($"Could not find a camp with moniker {moniker}"));
         }
         _repo.Delete(oldCamp);
         if (await _repo.SaveAllAsync())
         {
             return(Ok());
         }
     }
     catch (Exception ex)
     {
         _logger.LogError($"Error {ex}");
     }
     return(BadRequest("Couldn't delete Camp"));
 }
Exemple #24
0
        public async Task <IActionResult> Delete(string moniker)
        {
            try
            {
                var oldCamp = _repo.GetCampByMoniker(moniker);
                if (oldCamp == null)
                {
                    return(NotFound($"Couldn't find Camp with ID of {moniker}"));
                }
                _repo.Delete(oldCamp);
                if (await _repo.SaveAllAsync())
                {
                    return(Ok());
                }
            }
            catch (Exception e)
            {
            }

            return(BadRequest("Couldn't delete Camp"));
        }
        public async Task<IActionResult> Delete(string moniker) //IActionResult when only newed to return status code
        {
            try
            {
                var oldCamp = await _repository.GetcampAsync(moniker);
                if (oldCamp == null) return NotFound();

                _repository.Delete(oldCamp);

                if(await _repository.SavechangesAsync())
                {
                    return Ok();
                }
            }
            catch (Exception)
            {
                return this.StatusCode(StatusCodes.Status500InternalServerError, "Database failure");
            }

            return BadRequest("Failed to delete the camp");
        }
Exemple #26
0
 public async Task <IActionResult> Delete(int id)
 {
     try
     {
         var deleteCamp = _reposetory.GetCamp(id);
         if (deleteCamp == null)
         {
             return(NotFound($"camp with {id} Not found "));
         }
         _reposetory.Delete(deleteCamp);
         if (await _reposetory.SaveAllAsync())
         {
             return(Ok());
         }
     }
     catch (Exception e)
     {
         _logger.LogError("camp can't delete ");
     }
     return(BadRequest());
 }
Exemple #27
0
        public async Task <IActionResult> Delete(int id)
        {
            try
            {
                var oldCamp = _repo.GetCamp(id);
                if (oldCamp == null)
                {
                    return(NotFound($"Could not found camp with id {id}"));
                }

                _repo.Delete(oldCamp);
                if (await _repo.SaveAllAsync())
                {
                    return(Ok(oldCamp));
                }
            }
            catch (Exception ex)
            {
            }
            return(BadRequest("Could not delete Camps"));
        }
Exemple #28
0
        public async Task <IActionResult> Delete(int id)
        {
            try
            {
                var oldCamp = _repo.GetCamp(id);
                if (oldCamp == null)
                {
                    return(NotFound($"Could not find a camp with ID: {id}"));
                }

                _repo.Delete(oldCamp);

                if (await _repo.SaveAllAsync())
                {
                    return(Ok(oldCamp));
                }
            }
            catch
            {
            }
            return(BadRequest());
        }
Exemple #29
0
        public async Task <IActionResult> Delete(string moniker)
        {
            try
            {
                var camp = await _repository.GetCampAsync(moniker);

                if (camp == null)
                {
                    return(NotFound("Couldn't find the camp with the corresponding moniker."));
                }
                _repository.Delete(camp);
                if (await _repository.SaveChangesAsync())
                {
                    return(Ok());
                }
                return(BadRequest("Something went wrong deleting the camp."));
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Unable to delete camp."));
            }
        }
Exemple #30
0
        public async Task <ActionResult> Delete(string moniker)
        {
            try
            {
                var CampToDelete = await campRepository.GetCampAsync(moniker);

                if (CampToDelete.Equals(null))
                {
                    return(NotFound("the camp you want to delete wasnot found"));
                }
                campRepository.Delete(CampToDelete);
                if (await campRepository.SaveChangesAsync())
                {
                    return(Ok());
                }
                return(BadRequest("the server couldn't save the changes"));
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "something went wrong"));
            }
        }