示例#1
0
        public async Task <AuthorModel> UpdateAuthorAsync(AuthorItemModel model)
        {
            var author = await _authorRepository.GetAuthorByNameAsync(model.Name, model.Id);

            if (author is null)
            {
                var authorToUpdate = _mapper.Map <AuthorItemModel, Author>(model);
                var authorUpdated  = await _authorRepository.UpdateAuthorAsync(authorToUpdate);

                if (model.PrintingEditions.Count == 0)
                {
                    await _authorInPeRepository.RemoveInPrintingEditionByAuthorsAsync(authorUpdated.Id);
                }

                var authorInPrintingEdition =
                    AuthorInPrintingEditionProvider.GetAuthorInPrintingEditionList(authorUpdated.Id,
                                                                                   model.PrintingEditions);
                await _authorInPeRepository.UpdateInPrintingEditionByAuthorsAsync(authorInPrintingEdition,
                                                                                  authorUpdated.Id);

                author = await _authorRepository.GetAuthorByIdAsync(model.Id.ToString());

                var authorModel = _mapper.Map <Author, AuthorModel>(author);

                return(authorModel);
            }

            throw new ServerException(Constants.Errors.AUTHOR_ALREADY_EXIST, Enums.Errors.BadRequest);
        }
示例#2
0
        public AuthorEditorWindow(
            AuthorItemModel authorModel
            )
        {
            InitializeComponent();

            ViewModel = new AuthorEditorWindowViewModel(authorModel);
        }
        public async Task <IActionResult> UpdateAuthor([FromBody] AuthorItemModel model)
        {
            if (ModelState.IsValid)
            {
                return(Ok(await _authorService.UpdateAuthorAsync(model)));
            }

            return(BadRequest());
        }
示例#4
0
        public async Task <AuthorModel> CreateAuthorAsync(AuthorItemModel model)
        {
            var author = await _authorRepository.GetAuthorByNameAsync(model.Name);

            if (author is null)
            {
                var authorToAdd = _mapper.Map <AuthorItemModel, Author>(model);
                var authorModel = _mapper.Map <Author, AuthorModel>(await _authorRepository.CreateAuthorAsync(authorToAdd));

                return(authorModel);
            }

            throw new ServerException(Constants.Errors.AUTHOR_ALREADY_EXIST, Enums.Errors.BadRequest);
        }
示例#5
0
        private BaseItemModel GetNewItemByType(ItemTypeEnum itemType)
        {
            BaseItemModel result = null;

            switch (itemType)
            {
            case ItemTypeEnum.Author:
                result = new AuthorItemModel();
                break;

            case ItemTypeEnum.Book:
                result = new BookItemModel();
                break;

            case ItemTypeEnum.Serie:
                result = new SerieItemModel();
                break;

            case ItemTypeEnum.Review:
                result = new ReviewItemModel();
                break;
            }
            return(result);
        }