public ActionResult Edit(AuthorEditModel model) { try { if (model.NewPhoto != null) { string filepath = Server.MapPath("~/App_Data/Uploads/Covers/Authors/" + FilePathGenerator.GenerateFileName(model.NewPhoto.FileName)); if (!string.IsNullOrEmpty(model.PhotoPath) && System.IO.File.Exists(model.PhotoPath)) { System.IO.File.Delete(model.PhotoPath); } model.NewPhoto.SaveAs(filepath); model.PhotoPath = filepath; } var author = model.ToServiceAuthor(); service.UpdateAuthor(author); return(RedirectToAction("Index")); } catch (Exception ex) { logger.Error(ex); return(View("Error")); } }
public async Task <IActionResult> Create([FromBody] AuthorEditModel author) { if (ModelState.IsValid) { AuthorResultModel response = await this.authorService.UpdateAuthor(author.Id, author.Name, author.ImageUrl, author.Website, author.Description, author.Books); if (!response.Success) { FailedResponseModel badResponse = new FailedResponseModel() { Errors = response.Errors }; return(BadRequest(badResponse)); } AuthorSuccessResponseModel successResponse = new AuthorSuccessResponseModel() { Name = response.Name }; return(Ok(successResponse)); } return(BadRequest(new FailedResponseModel { Errors = ModelState.Values.SelectMany(x => x.Errors.Select(y => y.ErrorMessage)) })); }
public ActionResult Edit(AuthorEditModel model) { if (ModelState.IsValid) { var authors = db.Authors.Where(m => m.Id == model.Id) .FirstOrDefault(); if (authors != null) { authors.Name = model.Name; } else { authors = new Author { Name = model.Name }; db.Authors.Add(authors); } db.SaveChanges(); return(RedirectToAction("Index")); } return(View(model)); }
public IActionResult Edit(Guid id, [Bind("Name, Description")] AuthorEditModel authorEditModel) { var authorToBeEdited = _repository.GetAuthorById(id); if (authorToBeEdited == null) { return(NotFound()); } if (!ModelState.IsValid) { return(View(authorEditModel)); } authorToBeEdited.Name = authorEditModel.Name; authorToBeEdited.Description = authorEditModel.Description; try { _repository.EditAuthor(authorToBeEdited); } catch (DbUpdateConcurrencyException) { if (!AuthorExists(_repository.GetAuthorById(id).Id)) { return(NotFound()); } throw; } return(RedirectToAction(nameof(Index))); }
public void UpdateAuthor(AuthorEditModel model) { _authorRepository.Update(new DbAuthor { Id = model.Id, BookId = model.BookId, FirstName = model.AuthorFirstName, LastName = model.AuthorLastName }); }
public IHttpActionResult Put(AuthorEditModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _bookStoreManager.UpdateAuthor(model); return(Ok()); }
public AuthorEditModel GetAuthorEditModel(int authorId) { var _dbModel = dataManager.Authors.GetAuthorById(authorId); var _editModel = new AuthorEditModel() { Id = _dbModel.Id, name = _dbModel.Name, surname = _dbModel.Surname }; return(_editModel); }
public static ServiceAuthor ToServiceAuthor(this AuthorEditModel author) { return(new ServiceAuthor() { ID = author.ID, Name = author.Name, BirthDate = author.BirthDate, DeathDate = author.DeathDate, Biography = author.Biography, Photo = author.PhotoPath }); }
public async Task <IActionResult> Edit(AuthorEditModel collection) { if (ModelState.IsValid) { await m_authorService.Update(collection); return(RedirectToAction(nameof(Index))); } else { return(View(collection)); } }
public IActionResult upDate(int id) { var author = _repositoryAuthor.GetAuthorById(id); if (author == null) { return(RedirectToAction(nameof(Index))); } var authorViewModel = new AuthorEditModel(); authorViewModel.Name = author.Name; authorViewModel.Age = author.Age; return(View(authorViewModel)); }
public IActionResult upDate(int id, AuthorEditModel model) { if (ModelState.IsValid) { var author = _repositoryAuthor.GetAuthorById(id); if (author == null) { return(RedirectToAction(nameof(Index))); } author.Name = model.Name; author.Age = model.Age; author = _repositoryAuthor.upDate(author); return(RedirectToAction(nameof(details), new { author.id })); } return(RedirectToAction(nameof(Index))); }
public IActionResult create(AuthorEditModel model) {//validação do servidor if (ModelState.IsValid) { var newAuthor = new Author(); newAuthor.Name = model.Name; newAuthor.Age = model.Age; newAuthor = _repositoryAuthor.add(newAuthor); //forma errada pois quando atualizava a tela salva novamente return View("details", newAuthor); return(RedirectToAction(nameof(details), new { id = newAuthor.id }));//é preciso um objeto } else { return(View()); } }
public ActionResult Edit(int id) { var model = new AuthorEditModel(); if (id > 0) { var author = db.Authors.Where(m => m.Id == id) .FirstOrDefault(); if (author != null) { model.Id = author.Id; model.Name = author.Name; } } return(View(model)); }
public AuthorViewModel SaveAuthorEditModelToDb(AuthorEditModel editModel) { Author author; if (editModel.Id != 0) { author = dataManager.Authors.GetAuthorById(editModel.Id); } else { author = new Author(); } author.Id = editModel.Id; author.Name = editModel.name; author.Surname = editModel.surname; dataManager.Authors.SaveAuthor(author); return(AuthorDBModelToViewById(author.Id)); }
// GET: Authors/Edit/5 public IActionResult Edit(Guid?id) { if (id == null) { return(NotFound()); } var author = _repository.GetAuthorById(id.Value); if (author == null) { return(NotFound()); } var authorEditModel = new AuthorEditModel( author.Name, author.Description ); return(View(authorEditModel)); }
public async Task <HttpResponseMessage> Edit([FromBody] AuthorEditModel model) { HttpResponseMessage returnMessage = new HttpResponseMessage(); var role = mapper.Map <AuthorDto>(model); var result = await service.EditAsync(role); if (result.IsSuccess) { string message = ($"Student Created - {result.Entity.Id}"); returnMessage = new HttpResponseMessage(HttpStatusCode.Created); returnMessage.RequestMessage = new HttpRequestMessage(HttpMethod.Post, message); } else { returnMessage = new HttpResponseMessage(HttpStatusCode.ExpectationFailed); returnMessage.RequestMessage = new HttpRequestMessage(HttpMethod.Post, result.GetErrorString()); } return(returnMessage); }
public async Task Update(AuthorEditModel model) { await m_repository.Update(m_automapper.Map <Author>(model)); }
public IActionResult AuthorCreate2(AuthorEditModel _editModel) { _servicesManager.Authors.SaveAuthorEditModelToDb(_editModel); return(View("AuthorCreate", _editModel)); }
public IActionResult AuthorCreate() { AuthorEditModel _editModel = _servicesManager.Authors.CreateNewAuthorEditModel(); return(View(_editModel)); }
public IActionResult AuthorEdit2(AuthorEditModel _author) { _servicesManager.Authors.SaveAuthorEditModelToDb(_author); return(View("AuthorEdit", _author)); }
public IActionResult AuthorEdit(int Id) { AuthorEditModel _editModel = _servicesManager.Authors.GetAuthorEditModel(Id); return(View(_editModel)); }