public IActionResult UpdateCv(UpdateCvViewModel model, string id) { if (ModelState.IsValid) { this._cvService.EditedModel(model, id); return(this.Redirect("../../Cv/CreateCv")); } return(this.View()); }
public void EditedModel(UpdateCvViewModel model, string id) { var currentCv = this.context.Cvs.Find(id); currentCv.Description = model.Description; currentCv.ImageUrl = model.ImageUrl; this.context.SaveChanges(); }
public UpdateCvViewModel Update(string id) { var currentCv = this.context.Cvs.Find(id); var model = new UpdateCvViewModel() { Description = currentCv.Description, ImageUrl = currentCv.ImageUrl }; return(model); }
public void TestEditModel_ShouldEditCorrectCv() { var cvId = Guid.NewGuid().ToString(); var cv = new Cv() { Description = "a", Id = cvId, ImageUrl = "aa" }; this._context.Cvs.Add(cv); this._context.SaveChanges(); var expected = this._context.Cvs.Find(cvId); Assert.Equal(expected, cv); var update = new UpdateCvViewModel() { Description = "da", ImageUrl = "a", }; this._cvService.EditedModel(update, cvId); this._context.SaveChanges(); var mappedModel = new Cv() { Description = update.Description, ImageUrl = update.ImageUrl, }; var editedCv = this._context.Cvs.Find(cvId); Assert.Equal(mappedModel.Description, editedCv.Description); Assert.Equal(mappedModel.ImageUrl, editedCv.ImageUrl); }