public ActionResult Edit(int id, AuthorEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.AuthorId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateAuthorService(); if (service.UpdateAuthor(model)) { TempData["SaveResult"] = "The author was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "The author could not be updated."); return(View(model)); }
public async Task SaveAsync(AuthorEdit authorEdit) { Author author = authorEdit.Id == null ? new Author() : await authorRepository.GetEntityAsync(authorEdit.Id.Value, true); mapper.Map(authorEdit, author); if (authorEdit.Id == null) { await authorRepository.AddAsync(author); } await authorRepository.SaveChangesAsync(); }
public ActionResult Edit(int id) { AuthorDetail detail = AuthorDetailService(id); var model = new AuthorEdit { AuthorId = detail.AuthorId, Name = detail.Name, CountryName = detail.CountryName }; return(View(model)); }
public ActionResult Edit(int id) { var service = CreateAuthorService(); var detail = service.GetAuthorById(id); var model = new AuthorEdit { AuthorId = detail.AuthorId, AuthorName = detail.AuthorName, Age = detail.Age, }; return(View(model)); }
public bool UpdateAuthor(AuthorEdit model) { using (var ctx = new ApplicationDbContext()) { var authorToUpdate = ctx .Authors .Single(e => e.AuthorId == model.AuthorId); authorToUpdate.Name = model.Name; authorToUpdate.CountryName = model.CountryName; return(ctx.SaveChanges() == 1); } }
public bool UpdateAuthor(AuthorEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Authors .FirstOrDefault(a => a.AuthorId == model.AuthorId); entity.FirstName = model.FirstName; entity.LastName = model.LastName; entity.Description = model.Description; return(ctx.SaveChanges() > 0); } }
public IHttpActionResult UpdateAuthor(AuthorEdit model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } AuthorServices service = CreateAuthorService(); if (!service.UpdateAuthor(model)) { return(InternalServerError()); } return(Ok()); }
public bool UpdateAuthor(AuthorEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Authors .SingleOrDefault(e => e.AuthorId == model.AuthorId); entity.AuthorId = model.AuthorId; entity.Name = model.Name; entity.BirthDate = model.BirthDate; return(ctx.SaveChanges() == 1); } }
public bool UpdateAuthor(AuthorEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Authors .Single(e => e.AuthorId == model.AuthorId && e.CreatorId == _userId); entity.AuthorName = model.AuthorName; entity.Age = model.Age; entity.Gender = model.Gender; entity.ModifiedUtc = DateTimeOffset.UtcNow; return(ctx.SaveChanges() == 1); } }
public IHttpActionResult Put(AuthorEdit author) { if (author == null) { return(BadRequest("Received model was null.")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateAuthorService(); if (!service.UpdateAuthor(author)) { return(InternalServerError()); } return(Ok()); }
public async Task <IActionResult> Create([FromBody] AuthorEdit authorEdit) { try { if ((authorEdit == null) || !ModelState.IsValid) { return(BadRequest(ModelState.Values.SelectMany(v => v.Errors))); } await authorService.SaveAsync(authorEdit); } catch (Exception e) { logger.LogError(e, $"{nameof(AuthorController)}.{nameof(Create)} ({JsonSerializer.Serialize(authorEdit)})"); return(BadRequest("Cannot create")); } return(Ok()); }
public ActionResult Edit(int id) { var service = CreateAuthorService(); var detail = service.GetAuthorById(id); var model = new AuthorEdit { AuthorId = detail.AuthorId, LastName = detail.LastName, FirstName = detail.FirstName, Patreon = detail.Patreon, OfficialWebsite = detail.OfficialWebsite, AmazonPage = detail.AmazonPage, GoodreadsPage = detail.GoodreadsPage, TwitterHandle = detail.TwitterHandle }; return(View(model)); }
public bool UpdateAuthor(AuthorEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Authors .Single(e => e.AuthorId == model.AuthorId); entity.LastName = model.LastName; entity.FirstName = model.FirstName; entity.Patreon = model.Patreon; entity.OfficialWebsite = model.OfficialWebsite; entity.AmazonPage = model.AmazonPage; entity.GoodreadsPage = model.GoodreadsPage; entity.TwitterHandle = model.TwitterHandle; return(ctx.SaveChanges() == 1); } }
private void authorEditBtn_Click(object sender, EventArgs e) { var authorForm = new AuthorEdit(); Nav(authorForm, contentPanel); }