public ActionResult DeleteConfirmed(int id)
        {
            Genre genre = _genreRepository.GetEntity(id).FirstOrDefault();

            _genreRepository.Delete(genre);
            return(RedirectToAction("Index"));
        }
Пример #2
0
        /// <summary>
        /// Handling delete request and response
        /// </summary>
        /// <param name="request">Messaging.Genres.DeleteGenreRequest</param>
        /// <returns>Messaging.Genres.DeleteGenreResponse</returns>
        public DeleteGenreResponse DeleteGenre(DeleteGenreRequest request)
        {
            var response = new DeleteGenreResponse()
            {
                Request       = request,
                ResponseToken = Guid.NewGuid()
            };

            try
            {
                _repository.Delete(
                    new Genre()
                {
                    Id               = request.Id,
                    LastModified     = DateTimeOffset.Now,
                    UserLastModified = new Model.Users.UserInfo()
                    {
                        Id = request.UserId
                    }
                }
                    );
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                response.Success = false;
            }

            return(response);
        }
        public async Task <IActionResult> Delete(int genreId)
        {
            try
            {
                var oldGenre = await _repository.GetGenreAsync(genreId);

                if (oldGenre == null)
                {
                    return(NotFound($"Could not find genre with id of {genreId}"));
                }

                _repository.Delete(oldGenre);

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

            return(BadRequest());
        }
Пример #4
0
        public IActionResult DeleteGenre(string genreId)
        {
            Genre genre = genreRepository.GetAll().FirstOrDefault(g => g.Id == genreId);

            genreRepository.Delete(genre);
            return(Ok("success"));
        }
Пример #5
0
        public bool Delete(int id)
        {
            var genre = _repository.FindById(id);

            _repository.Delete(genre);
            return(_repository.SaveChanges());
        }
Пример #6
0
        public ActionResult DeleteConfirmed(int id)
        {
            genreRepository.Delete(id);
            genreRepository.Save();

            return(RedirectToAction("Index"));
        }
Пример #7
0
        public void DeleteGenre(long id)
        {
            var genre = _genreRepository.GetById(id);

            _genreRepository.Delete(genre);
            _unitOfWork.Commit();
        }
Пример #8
0
 public IActionResult Delete(int id)
 {
     if (genreRepository.Delete(id))
     {
         return(RedirectToAction("Index"));
     }
     return(View());
 }
        public void Should_Delete_An_Author()
        {
            _repository.Delete(2);
            var obj = _repository.ById(2);

            Assert.Null(obj);
            Assert.Equal(_repository.FindAll().Count(), 3);
        }
Пример #10
0
        public IActionResult Delete(int id)
        {
            Genre genre = _genrerepo.FindById(id);

            _genrerepo.Delete(genre);

            return(RedirectToAction(nameof(Index)));
        }
Пример #11
0
        public async Task Delete(int id)
        {
            var genre = await _genreRepository.GetById(id);

            if (genre == null)
            {
                throw new GenreNotFound();
            }

            await _genreRepository.Delete(genre);
        }
Пример #12
0
 public void Delete(int GenreID)
 {
     try
     {
         _genreRepository.Delete(GenreID);
         _logger.LogInformation(LoggerMessageDisplay.GenreDeleted);
     }
     catch (Exception ex)
     {
         _logger.LogInformation(LoggerMessageDisplay.GenreDeletedError, ex);
     }
 }
Пример #13
0
 public ActionResult Delete(Genre genre)
 {
     try
     {
         genreRepo.Delete(genre.GenreId);
         return(RedirectToAction("Index"));
     }
     catch (Exception e)
     {
         Console.WriteLine(e.StackTrace);
         return(RedirectToAction("Index"));
     }
 }
Пример #14
0
        public async Task <ServiceResult> Delete(string id)
        {
            var serviceResult = new ServiceResult();
            var result        = await _genreRepository.Delete(id);

            serviceResult.Success = result.Success;
            if (!result.Success)
            {
                serviceResult.Error.Code        = ErrorStatusCode.BudRequest;
                serviceResult.Error.Description = result.Message;
            }
            return(serviceResult);
        }
Пример #15
0
        public ActionResult Delete(string genre, bool foo)
        {
            try
            {
                _repository.Delete(genre);

                return(RedirectToAction("index"));
            }
            catch (KeyNotFoundException e)
            {
                return(NotFound());
            }
        }
        public IActionResult DeleteGenre(int id)
        {
            Genre genre = _genreRepository.GetById(id);

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

            _genreRepository.Delete(genre);
            _genreRepository.Save();

            return(Ok(genre));
        }
Пример #17
0
        public async Task Delete(string genreId)
        {
            if (genreId.IsNullOrEmpty())
            {
                throw new CustomException("genreId = null");
            }
            var result = await _genreRepository.GetById(genreId);

            if (result == null)
            {
                throw new CustomException("Жанра с таким id нет");
            }
            await _genreRepository.Delete(result);
        }
        public ActionResult <Genre> DeleteGenre(int id)
        {
            Genre genre = _genreRepository.GetById(id);

            if (genre == null)
            {
                return(NotFound());
            }
            else
            {
                _genreRepository.Delete(genre);
                _genreRepository.SaveChanges();
                return(Ok(genre));
            }
        }
Пример #19
0
        public void Delete(int id)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            var genre = _genreRepository.GetById(id);

            if (genre is null)
            {
                throw new Exception("Genre not found");
            }

            _genreRepository.Delete(genre);
        }
Пример #20
0
        public HttpResponseMessage Delete(int id)
        {
            HttpResponseMessage result;

            try
            {
                _genreRepo.Delete(id);
                _genreRepo.SaveChanges();
                result = Request.CreateResponse(HttpStatusCode.Accepted);
            }
            catch (Exception ex)
            {
                result = Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, ex);
            }
            return(result);
        }
Пример #21
0
        public DeleteGenreResponse DeleteGenre(DeleteGenreRequest request)
        {
            DeleteGenreResponse response = new DeleteGenreResponse();

            try
            {
                _genreRepository.Delete(request.GenreId);
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }
            return(response);
        }
Пример #22
0
        public async Task<ActionResult> DeleteGenreById(int id)
        {
            try
            {
                var genre = await _repository.Get<Genre>(id);
                if (genre == null)
                {
                    return BadRequest($"Could not delete genre. Genre with Id {id} was not found.");
                }
                await _repository.Delete<Genre>(id);

                return NoContent();
            }
            catch (Exception e)
            {
                var result = new { Status = StatusCodes.Status500InternalServerError, Data = $"Failed to delete the genre. Exception thrown when attempting to delete data from the database: {e.Message}"};
                return this.StatusCode(StatusCodes.Status500InternalServerError,result);
            }
        }
Пример #23
0
        public IActionResult DeleteConfirmed(int id)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _genreRepository.Delete(id);
                    _logger.LogInformation(LoggerMessageDisplay.GenreDeleted);
                }
            }
            catch (DbUpdateException ex)
            {
                _logger.LogError(LoggerMessageDisplay.GenreDeletedError + "--->" + ex);
                ViewBag.ErrorTitle   = "Genre is in use";
                ViewBag.ErrorMessage = " Genre cannot be deleted as there are games using this genre. If you want to delete this genre, please remove the games using this genre";
                return(View("Error"));
            }

            return(RedirectToAction(nameof(Index)));
        }
Пример #24
0
        public async Task <GenreResponse> DeleteAsync(int id)
        {
            var existingUser = await genreRepository.FindById(id);

            if (existingUser == null)
            {
                return(new GenreResponse("User not found"));
            }
            try
            {
                genreRepository.Delete(existingUser);
                await unitOfWork.CompleteAsync();

                return(new GenreResponse(existingUser));
            }
            catch (Exception ex)
            {
                return(new GenreResponse($"Error when deleting user: {ex.Message}"));
            }
        }
Пример #25
0
        public async Task <IActionResult> Delete(int id)
        {
            try
            {
                _logger.LogInfo("Delete started");
                if (id < 1)
                {
                    _logger.LogWarn("Empty request");
                    return(BadRequest());
                }
                var isExists = await _genreRepository.IsExists(id);

                if (!isExists)
                {
                    _logger.LogWarn("Genre does not exists");
                    return(BadRequest());
                }
                var genre = await _genreRepository.FindById(id);

                if (genre == null)
                {
                    _logger.LogWarn("Genre not found");
                    return(NotFound());
                }
                var isSuccess = await _genreRepository.Delete(genre);

                if (!isSuccess)
                {
                    return(InternalError("Genre deletion failed"));
                }
                _logger.LogInfo("Genre deleted");
                return(NoContent());
            }
            catch (Exception ex)
            {
                return(InternalError($"Something went wrong: {ex.Message}"));
            }
        }
        public async Task <ActionResult> DeleteGenre(int genreid)
        {
            try
            {
                var oldGenre = await _genreRepository.GetGenreById(genreid);

                if (oldGenre == null)
                {
                    return(NotFound($"Could not find any genre with id: {genreid}"));
                }

                _genreRepository.Delete(oldGenre);

                if (await _genreRepository.Save())
                {
                    return(NoContent());
                }
            }
            catch (Exception e)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Database failure, could not delete item. {e.Message}"));
            }
            return(BadRequest());
        }
Пример #27
0
 public void DeleteGenre(int id)
 {
     _genreRepository.Delete(id);
 }
Пример #28
0
 public void Delete(int id)
 {
     db.Delete(id);
 }
Пример #29
0
 public void DeleteGenre(Genre delGenre)
 {
     _genreRepository.Delete(delGenre);
     Genres.Remove(delGenre);
 }
Пример #30
0
 protected override async Task Handle(DeleteGenreCommand request, CancellationToken cancellationToken)
 {
     await _genreRepository.Delete(request.Genre, cancellationToken);
 }