public void EditPollShoudEditTitleInPoll() { var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase("Database_For_Tests").Options; var dbContext = new ApplicationDbContext(options); var service = new PollsService(dbContext); var model = new UpdateDeletePollViewModel { Title = "Edited" }; var poll = new Poll { Title = "New" }; dbContext.Polls.Add(poll); dbContext.SaveChanges(); var pollToEdit = dbContext.Polls.First(); service.EditPoll(pollToEdit, model); Assert.Equal("Edited", pollToEdit.Title); }
public IActionResult Edit(int id) { var poll = this.pollService.GetPoll(id); if (poll == null) { return(this.Redirect("/")); } var model = new UpdateDeletePollViewModel { Id = poll.Id, Title = poll.Title, }; return(this.View(model)); }
public IActionResult Edit(UpdateDeletePollViewModel model) { if (!ModelState.IsValid) { return(this.View(model)); } var poll = this.pollService.GetPoll(model.Id); if (poll == null) { return(this.Redirect("/")); } this.pollService.EditPoll(poll, model); return(this.Redirect("/Polls/All")); }
public IActionResult Delete(int id) { var poll = this.pollService.GetPoll(id); var pollAnswers = this.pollService.GetPollsAnswers(id); if (poll == null) { return(this.Redirect("/")); } var model = new UpdateDeletePollViewModel { Id = poll.Id, Title = poll.Title, DisabledValue = "disabled", }; return(this.View(model)); }
public void EditPoll(Poll poll, UpdateDeletePollViewModel model) { poll.Title = model.Title; this.context.SaveChanges(); }