Ejemplo n.º 1
0
        public async Task UpdateAsync(int id, AuthorInputModel authorInputModel)
        {
            var author = mapper.Map <Author>(authorInputModel);

            author.AuthorId = id;
            await repository.UpdateAsync(author);
        }
        public AuthorDto CreateAuthor(AuthorInputModel author)
        {
            int nextInt = 0;

            if (AuthorDataProvider.Authors.Count == 0)
            {
                nextInt = 1;
            }
            else
            {
                nextInt = AuthorDataProvider.Authors.OrderByDescending(a => a.Id).FirstOrDefault().Id + 1;
            }
            var entity = new Author
            {
                Id               = nextInt,
                Name             = author.Name,
                ProfileImgSource = author.ProfileImgSource,
                Bio              = author.Bio,
                ModifiedBy       = "Admin",
                CreatedDate      = DateTime.Now,
                ModifiedDate     = DateTime.Now
            };

            AuthorDataProvider.Authors.Add(entity);
            return(new AuthorDto
            {
                Id = entity.Id,
                Name = entity.Name
            });
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Edit(int id, AuthorInputModel authorModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(authorModel));
            }

            var result = await this.authorService.EditAsync(
                id,
                authorModel.FirstName,
                authorModel.LastName);

            if (result == false)
            {
                this.TempData.AddErrorMessage(WebAdminConstants.AuthorNotEdited);
                return(RedirectToAction(nameof(Index)));
            }

            this.TempData.AddSuccessMessage(string.Format(
                                                WebAdminConstants.AuthorUpdated,
                                                authorModel.FirstName,
                                                authorModel.LastName));

            return(this.RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 4
0
        public int CreateNewAuthor(AuthorInputModel author)
        {
            var entity = ToAuthor(author);

            _dataContext.getAuthors.Add(entity);
            return(entity.Id);
        }
Ejemplo n.º 5
0
        // PUT: api/Authors/5
        /// <summary>
        /// Funkcja do edycji autora o podanym ID
        /// </summary>
        /// <param name="id"></param>
        /// <param name="inputModel"></param>
        /// <returns></returns>
        public async Task <IHttpActionResult> PutAuthor(int id, AuthorInputModel inputModel)
        {
            if (inputModel == null)
            {
                return(BadRequest(message: "empty"));
            }

            if (id != inputModel.ID)
            {
                return(BadRequest());
            }

            var author = await _authorRepository.GetByIdAsync(id);

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

            author.FirstName = inputModel.FirstName;
            author.LastName  = inputModel.LastName;

            var result = await _authorRepository.SaveAsync(author);

            if (!result)
            {
                return(InternalServerError());
            }
            return(Ok());
        }
Ejemplo n.º 6
0
        /* From teacher:
         * "Betri leið væri að sækja stærsta Id
         * og incrementa það þegar verið er að vinna með lista." */
        private Author ToAuthor(AuthorInputModel author)
        {
            var entity = Mapper.Map <Author>(author);

            entity.Id = _dataContext.getAuthors.Max(a => a.Id) + 1;
            return(entity);
        }
        public AuthorDto CreateAuthor(AuthorInputModel author)
        {
            var nextId = DataProvider.Authors.Count() + 1;
            var entity = ToAuthor(author, nextId);

            DataProvider.Authors.Add(entity);
            return(ToAuthorDto(entity));
        }
Ejemplo n.º 8
0
        public void UpdateAuthorById(AuthorInputModel author, int authorId)
        {
            var updateAuthor = _dataContext.getAuthors.FirstOrDefault(a => a.Id == authorId);

            updateAuthor.Name             = author.Name;
            updateAuthor.Bio              = author.Bio;
            updateAuthor.ProfileImgSource = author.ProfileImgSource;
        }
Ejemplo n.º 9
0
 public void updateAuthor(int authorId, [FromBody] AuthorInputModel inputModel)
 {
     if (!ModelState.IsValid)
     {
         throw new ModelFormatException();
     }
     _authorService.updateAuthorById(inputModel, authorId);
 }
 public IActionResult ChangeAuthor(AuthorInputModel author)
 {
     if (ModelState.IsValid)
     {
         _authorService.UpdateAuthor(author);
     }
     return(RedirectToAction("ChangeAuthor"));
 }
Ejemplo n.º 11
0
        public async Task <AuthorViewModel> AddAsync(AuthorInputModel authorInputModel)
        {
            var author = mapper.Map <Author>(authorInputModel);
            var result = await repository.AddAsync(author);

            var authorViewModel = mapper.Map <AuthorViewModel>(result);

            return(authorViewModel);
        }
 public IActionResult CreateAuthor([FromBody] AuthorInputModel author)
 {
     if (ModelState.IsValid)
     {
         int id = _authorService.CreateAuthor(author);
         return(CreatedAtRoute("GetAuthorById", new { id }, null));
     }
     return(StatusCode(412, author));
 }
 public IActionResult UpdateAuthor([FromBody] AuthorInputModel body, int authorId)
 {
     if (!ModelState.IsValid)
     {
         throw new ModelFormatException("Model not properly formatted");
     }
     _authorsService.UpdateAuthor(body, authorId);
     return(NoContent());
 }
Ejemplo n.º 14
0
        public AuthorDto CreateAuthor(AuthorInputModel body)
        {
            var entity = _mapper.Map <Author>(body);
            var nextId = AuthorDataProvider.Authors.Last().Id + 1;

            entity.Id = nextId;
            AuthorDataProvider.Authors.Add(entity);
            return(_mapper.Map <AuthorDto>(entity));
        }
Ejemplo n.º 15
0
        public AuthorViewModel Post(AuthorInputModel authorInputModel)
        {
            var author = _mapper.Map <Author>(authorInputModel);

            _uow.AuthorRepository.Add(author);
            _uow.Commit();

            return(_mapper.Map <AuthorViewModel>(author));
        }
Ejemplo n.º 16
0
 public IActionResult AddAuthor(AuthorInputModel model)
 {
     if (ModelState.IsValid)
     {
         _bookService.AddAuthor(model);
         return(Ok());
     }
     return(BadRequest());
 }
Ejemplo n.º 17
0
 public IActionResult EditAuthor(int id, [FromBody] AuthorInputModel author)
 {
     if (!ModelState.IsValid)
     {
         throw new InputFormatException("Author input model was not properly formatted.");
     }
     _authorService.UpdateAuthorById(author, id);
     return(NoContent());
 }
Ejemplo n.º 18
0
        public AuthorViewModel Put(int id, AuthorInputModel authorInputModel)
        {
            var author = _mapper.Map <Author>(authorInputModel);

            _uow.AuthorRepository.Update(author);
            _uow.Commit();

            return(_mapper.Map <AuthorViewModel>(author));
        }
Ejemplo n.º 19
0
 public IActionResult UpdateAuthorById([FromBody] AuthorInputModel author, int authorId)
 {
     if (!ModelState.IsValid)
     {
         throw new ModelFormatException("Author was not properly formatted");
     }
     _authorService.UpdateAuthorById(author, authorId);
     return(NoContent());
 }
        public AuthorDto CreateNewAuthor(AuthorInputModel author)
        {
            var nextId = DataProvider.Authors.OrderByDescending(r => r.Id).FirstOrDefault().Id + 1;
            var entity = _mapper.Map <Author>(author);

            entity.Id = nextId;
            DataProvider.Authors.Add(entity);
            return(_mapper.Map <AuthorDto>(entity));
        }
Ejemplo n.º 21
0
        public int CreateAuthor(AuthorInputModel author)
        {
            var nextId = DataProvider.Authors.Count() + 1;
            var entity = Mapper.Map <Author>(author);

            entity.Id = nextId;
            DataProvider.Authors.Add(entity);
            return(nextId);
        }
 public Boolean UpdateAuthorById(int id, AuthorInputModel category, string urlStr)
 {
     if (_authorRepository.GetAuthorDetailById(id, urlStr) == null)
     {
         return(false);
     }
     _authorRepository.UpdateAuthorById(id, category);
     return(true);
 }
Ejemplo n.º 23
0
        public int CreateAuthor(AuthorInputModel author)
        {
            int    nextId      = DataContext.Authors.Max(x => x.Id) + 1;
            Author authorToAdd = Mapper.Map <Author>(author);

            authorToAdd.Id = nextId;
            DataContext.Authors.Add(authorToAdd);
            return(nextId);
        }
        public IActionResult AddAuthor(AuthorInputModel author)
        {
            if (ModelState.IsValid)
            {
                _authorService.AddAuthor(author);
            }

            return(RedirectToAction("AddAuthor"));
        }
Ejemplo n.º 25
0
        public void AddAuthor(AuthorInputModel author)
        {
            var authorEntity = new Author
            {
                Name = author.Name
            };

            _bookRepo.AddAuthor(authorEntity);
        }
Ejemplo n.º 26
0
        public ActionResult Put(int id, [FromBody] AuthorInputModel author)
        {
            if (id != author.Id)
            {
                return(BadRequest());
            }
            var result = _authorService.Put(id, author);

            return(new CreatedAtRouteResult("GetAuthorsDetails", new { id = result.Id }, result));
        }
Ejemplo n.º 27
0
        public IActionResult AddAuthor(AuthorInputModel input)
        {
            if (!input.IsValid())
            {
                return(BadRequest(input.ValidationMessage));
            }
            var author = _authorAppService.Add(input);

            return(Created(new Uri($"{Request.Path}/{author.Id}", UriKind.Relative), author));
        }