Exemplo n.º 1
0
        public AuthorModelItem EntityToModelItem(Author author)
        {
            var authorModel = new AuthorModelItem();

            authorModel.Name = author.Name;
            return(authorModel);
        }
Exemplo n.º 2
0
        public static PrintingEditionModelItem MapToModel(this DataAccess.Entities.PrintingEdition entity)
        {
            var model = new PrintingEditionModelItem();

            model.Id          = entity.Id;
            model.Title       = entity.Title;
            model.Description = entity.Description;
            model.Price       = entity.Price;
            model.Currency    = entity.Currency;
            model.Type        = entity.Type;
            model.Image       = string.IsNullOrWhiteSpace(entity.Image)
                ? Constants.Constants.Images.DefaultPrintingEditionTitle
                : entity.Image;

            foreach (var item in entity.AuthorInPrintingEditions)
            {
                if (item == null)
                {
                    continue;
                }
                var author = new AuthorModelItem();
                author.Id   = item.AuthorId;
                author.Name = item.Author.Name;

                model.Authors.Add(author);
            }

            return(model);
        }
Exemplo n.º 3
0
        public async Task <AuthorModel> UpdateAuthorAsync(AuthorModelItem authorModelItem)
        {
            var responseModel = new AuthorModel();

            if (authorModelItem == null || string.IsNullOrWhiteSpace(authorModelItem.Name))
            {
                responseModel.Errors.Add(Constants.Errors.InvalidData);
                return(responseModel);
            }

            var author = await _authorRepository.GetByIdAsync(authorModelItem.Id);

            if (author == null)
            {
                responseModel.Errors.Add(Constants.Errors.InvalidData);
                return(responseModel);
            }
            author.Name = authorModelItem.Name;

            var updateResult = await _authorRepository.UpdateAsync(author);

            if (updateResult.Equals(0))
            {
                responseModel.Errors.Add(Constants.Errors.FailedUpdate);
            }

            return(responseModel);
        }
Exemplo n.º 4
0
        public async Task <AuthorModelItem> FindByIdAsync(int id)
        {
            var authorModel = new AuthorModelItem();
            var author      = await _authorRepository.FindByIdAsync(id);

            if (author == null)
            {
                authorModel.Errors.Add(Constants.Errors.NotFoundAuthorError);
                return(authorModel);
            }

            authorModel = author.MapToModel();
            return(authorModel);
        }
Exemplo n.º 5
0
        public async Task <BaseModel> CreateAsync(AuthorModelItem authorModel)
        {
            var author = new Author();

            author = authorModel.MapToEntity(author);

            var authorId = await _authorRepository.CreateAsync(author);

            if (authorId == 0)
            {
                authorModel.Errors.Add(Constants.Errors.CreateAuthorError);
            }

            return(authorModel);
        }
Exemplo n.º 6
0
        public async Task <BaseModel> UpdateAsync(AuthorModelItem authorModel)
        {
            var author = await _authorRepository.FindByIdAsync(authorModel.Id);

            if (author == null)
            {
                authorModel.Errors.Add(Constants.Errors.NotFoundAuthorError);
                return(authorModel);
            }

            author = authorModel.MapToEntity(author);
            var result = await _authorRepository.UpdateAsync(author);

            if (!result)
            {
                authorModel.Errors.Add(Constants.Errors.UpdateAuthorError);
            }

            return(authorModel);
        }
Exemplo n.º 7
0
        public static AuthorModelItem MapToModel(this DataAccess.Entities.Author entity)
        {
            var model = new AuthorModelItem();

            model.Id   = entity.Id;
            model.Name = entity.Name;

            foreach (var item in entity.AuthorInPrintingEdition)
            {
                if (item == null)
                {
                    continue;
                }
                var printingEdition = new PrintingEditionModelItem();
                printingEdition.Id    = item.PrintingEditionId;
                printingEdition.Title = item.PrintingEdition.Title;
                model.PrintingEditions.Add(printingEdition);
            }

            return(model);
        }
Exemplo n.º 8
0
        public async Task <AuthorModel> CreateAuthorAsync(AuthorModelItem authorModelItem)
        {
            var responseModel = new AuthorModel();

            if (authorModelItem == null || string.IsNullOrWhiteSpace(authorModelItem.Name))
            {
                responseModel.Errors.Add(Constants.Errors.InvalidData);
                return(responseModel);
            }
            var author = new Author()
            {
                Name = authorModelItem.Name
            };
            var createResult = await _authorRepository.CreateAsync(author);

            if (createResult.Equals(0))
            {
                responseModel.Errors.Add(Constants.Errors.FailedCreate);
            }
            return(responseModel);
        }
Exemplo n.º 9
0
        public async Task <AuthorModel> GetAllAsync(AuthorFilterModel authorFilterModel)
        {
            var authorModel = new AuthorModel();
            var filterModel = authorFilterModel.MapToEFFilterModel();

            var listOfAuthors = await _authorRepository.GetAllAuthors(filterModel);

            if (listOfAuthors.Items == null)
            {
                authorModel.Errors.Add(Constants.Errors.NotFoundAuthorsError);
                return(authorModel);
            }

            authorModel.Counter = listOfAuthors.Counter;
            foreach (var author in listOfAuthors.Items)
            {
                var authorModelItem = new AuthorModelItem();
                authorModel.Items.Add(author.MapToModel());
            }

            return(authorModel);
        }
Exemplo n.º 10
0
        public async Task <BaseModel> DeleteAsync(int id)
        {
            var authorModel = new AuthorModelItem();

            var author = await _authorRepository.FindByIdAsync(id);

            if (author == null)
            {
                authorModel.Errors.Add(Constants.Errors.NotFoundAuthorError);
                return(authorModel);
            }

            author.isRemoved = true;

            var result = await _authorRepository.UpdateAsync(author);

            if (!result)
            {
                authorModel.Errors.Add(Constants.Errors.DeleteAuthorError);
            }

            return(authorModel);
        }
Exemplo n.º 11
0
        public async Task <IActionResult> Update([FromBody] AuthorModelItem authorItem)
        {
            var authorModel = await _authorService.UpdateAsync(authorItem);

            return(Ok(authorModel));
        }
Exemplo n.º 12
0
 public static DataAccess.Entities.Author MapToEntity(this AuthorModelItem model, DataAccess.Entities.Author entity)
 {
     entity.Name = model.Name;
     return(entity);
 }
Exemplo n.º 13
0
        public async Task <IActionResult> CreateAuthorAsync([FromBody] AuthorModelItem authorModel)
        {
            var responseModel = await _authorService.CreateAuthorAsync(authorModel);

            return(Ok(responseModel));
        }