public async Task <IActionResult> Edit(Guid id, [Bind("Id, FirstName, LastName, BirthDate, Gender, ProfileId, CountryId")] VisitorViewModel vm) { if (ModelState.IsValid) { var getOperation = await _bo.ReadAsync((Guid)id); if (!getOperation.Success) { return(OperationErrorBackToIndex(getOperation.Exception)); } if (getOperation.Result == null) { return(RecordNotFound()); } var result = getOperation.Result; result.FirstName = vm.FirstName; result.LastName = vm.LastName; result.BirthDate = vm.BirthDate; result.Gender = vm.Gender; result.ProfileId = vm.ProfileId; result.CountryId = vm.CountryId; var updateOperation = await _bo.UpdateAsync(result); if (!updateOperation.Success) { TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, updateOperation.Exception); return(View(vm)); } else { return(OperationSuccess("The record was successfuly updated")); } } return(RedirectToAction(nameof(Index))); }
public void TestUpdateVisitorAsync() { BoraNowSeeder.Seed(); var vbo = new VisitorBusinessObject(); var resList = vbo.List(); var item = resList.Result.FirstOrDefault(); var countrybo = new CountryBusinessObject(); var pbo = new ProfileBusinessObject(); var companybo = new CompanyBusinessObject(); var country = new Country("Holanda"); var profile = new Profile("a", "b"); var company = new Company("a", "b", "c", "d", profile.Id); countrybo.Create(country); pbo.Create(profile); companybo.Create(company); var visitor = new Visitor("R", "f", DateTime.Now.AddYears(-24), "F", profile.Id, country.Id); item.FirstName = visitor.FirstName; item.LastName = visitor.LastName; item.BirthDate = visitor.BirthDate; item.Gender = visitor.Gender; item.ProfileId = visitor.ProfileId; item.CountryId = visitor.CountryId; var resUpdate = vbo.UpdateAsync(item).Result; resList = vbo.ListAsync().Result; Assert.IsTrue(resUpdate.Success && resList.Success && resList.Result.First().FirstName == visitor.FirstName && resList.Result.First().LastName == visitor.LastName && resList.Result.First().BirthDate == visitor.BirthDate && resList.Result.First().Gender == visitor.Gender && resList.Result.First().ProfileId == visitor.ProfileId && resList.Result.First().CountryId == visitor.CountryId); }