Example #1
0
        public async Task <PrintingEditionModel> DeletePrintingEditionAsync(long printingEditionId)
        {
            var responseModel = new PrintingEditionModel();

            var printingEdition = await _printingEditionRepository.GetByIdAsync(printingEditionId);

            if (printingEdition == null)
            {
                responseModel.Errors.Add(Constants.Errors.InvalidData);
                return(responseModel);
            }

            var deleteResult = await _printingEditionRepository.DeleteAsync(printingEdition);

            if (deleteResult.Equals(0))
            {
                responseModel.Errors.Add(Constants.Errors.FailedDelete);
            }

            var deleteAuthorsInPrintingEdition = await _authorInPrintingEditionRepository.DeletePrintingEditionsById(printingEditionId);

            if (deleteAuthorsInPrintingEdition.Equals(0))
            {
                responseModel.Errors.Add(Constants.Errors.FailedDelete);
            }

            return(responseModel);
        }
Example #2
0
        public async Task <BaseModel> UpdateAsync(PrintingEditionsModelItem model)
        {
            var response = new BaseModel();

            if (model == null)
            {
                response.Errors.Add(ErrorConstants.ModelIsNull);
            }
            var existingProduct = await _printingEditionRepository.GetByIdAsync(model.Id);

            if (existingProduct == null)
            {
                response.Errors.Add(ErrorConstants.ImpossibleToFindProduct);
                return(response);
            }
            var product = PrintingEditionMapper.UpdateEntityWithModel(existingProduct, model);
            var result  = await _printingEditionRepository.UpdateAsync(product);

            if (!result)
            {
                response.Errors.Add(ErrorConstants.ImpossibleToUpdateProduct);
            }
            response = await UpdateAuthorInProductAsync(product, model.Authors);

            return(response);
        }
Example #3
0
        public async Task <PrintingEditionModel> GetByIdAsync(long id)
        {
            var edition = await _printingEditionRepository.GetByIdAsync(edition => edition.Id == id);

            if (edition is null)
            {
                throw new CustomExeption(Constants.Error.NO_EDITION_ID_IN_DB,
                                         StatusCodes.Status400BadRequest);
            }
            var editionModel = _mapper.Map <PrintingEditionModel>(edition);

            return(editionModel);
        }
Example #4
0
        public async Task DeletePrintingEditionAsync(long id)
        {
            var printingEdition = await _printingEditionRepository.GetByIdAsync(id);

            if (printingEdition is null)
            {
                throw new ServerException(Constants.Errors.PRINTING_EDITION_NOT_FOUND);
            }
            await _printingEditionRepository.DeleteAsync(printingEdition);
        }