public async Task <IHttpActionResult> Delete(string moniker, CampModel model)
        {
            try
            {
                var camp = await _repository.GetCampAsync(moniker);

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

                _mapper.Map(model, camp);

                _repository.DeleteCamp(camp);

                if (await _repository.SaveChangesAsync())
                {
                    return(Ok("Camp Deleted"));
                }
                else
                {
                    return(InternalServerError());
                }
            }
            catch
            {
                return(InternalServerError());
            }
        }
예제 #2
0
        public async Task <IHttpActionResult> Delete(string moniker)
        {
            try
            {
                var camp = await _repository.GetCampAsync(moniker);

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

                _repository.DeleteCamp(camp);

                if (await _repository.SaveChangesAsync())
                {
                    return(Ok());
                }
                else
                {
                    return(InternalServerError());
                }
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
예제 #3
0
        public async Task <IHttpActionResult> Delete(string moniker)
        {
            try
            {
                // check moniker in DB
                Camp camp = await _repository.GetCampAsync(moniker);

                // if it is not found, send 404
                if (camp == null)
                {
                    return(NotFound());
                }

                _repository.DeleteCamp(camp);

                if (await _repository.SaveChangesAsync())
                {
                    return(Ok());
                }
                else
                {
                    return(InternalServerError());
                }
            }
            catch (Exception ex)
            {
                // TODO Add logging
                return(InternalServerError(ex));
            }
        }
        public async Task <IHttpActionResult> DeleteCamp(string moniker)              // we don't need the [HttpDelete] here, because the name of our action starts with 'Delete'...
        {
            try
            {
                Camp camp = await _repository.GetCampAsync(moniker);

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

                _repository.DeleteCamp(camp);

                if (await _repository.SaveChangesAsync())
                {
                    return(StatusCode(HttpStatusCode.NoContent));
                    //return Ok();
                }
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }

            return(InternalServerError());                                           // if SaveChangesAsync() fails, without an exception...
        }
예제 #5
0
        public async Task <IActionResult> Delete(string moniker)
        {
            try
            {
                var camp = await _campRepository.GetCampAsync(moniker);

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

                _campRepository.DeleteCamp(camp);

                var saved = await _campRepository.SaveChangesAsync();

                if (saved)
                {
                    return(Ok());
                }

                return(StatusCode(500));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
        }
예제 #6
0
        public async Task <ActionResult <Camp> > DeleteEmployee(int id, Camp camp)
        {
            try
            {
                if (id != camp.Id)
                {
                    return(BadRequest("Id Mismatch"));
                }

                var campDelete = await _campRepository.GetCamp(id);

                if (campDelete == null)
                {
                    return(NotFound($"Department Id = {id} Not Found"));
                }

                return(await _campRepository.DeleteCamp(id));
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Error in Retrieving Data from  Database"));
            }
        }
        public async Task <IHttpActionResult> Delete(string moniker)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var camp = await cr.GetCampAsync(moniker);

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

                    cr.DeleteCamp(camp);
                    return(Ok("Deleted"));
                }
            }
            catch (Exception e)
            {
                return(InternalServerError(e));
            }
            return(BadRequest(ModelState));
        }