public AuthorModelItem EntityToModelItem(Author author) { var authorModel = new AuthorModelItem(); authorModel.Name = author.Name; return(authorModel); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
public async Task <IActionResult> Update([FromBody] AuthorModelItem authorItem) { var authorModel = await _authorService.UpdateAsync(authorItem); return(Ok(authorModel)); }
public static DataAccess.Entities.Author MapToEntity(this AuthorModelItem model, DataAccess.Entities.Author entity) { entity.Name = model.Name; return(entity); }
public async Task <IActionResult> CreateAuthorAsync([FromBody] AuthorModelItem authorModel) { var responseModel = await _authorService.CreateAuthorAsync(authorModel); return(Ok(responseModel)); }