public ActionResult Update([FromBody] VisitorViewModel vm) { var currentResult = _bo.Read(vm.Id); if (!currentResult.Success) { return(new ObjectResult(HttpStatusCode.InternalServerError)); } var current = currentResult.Result; if (current == null) { return(NotFound()); } if (current.FirstName == vm.FirstName && current.LastName == vm.LastName && current.BirthDate == vm.BirthDate && current.Gender == vm.Gender && current.ProfileId == vm.ProfileId && current.CountryId == vm.CountryId ) { return(new ObjectResult(HttpStatusCode.NotModified)); } if (current.FirstName != vm.FirstName) { current.FirstName = vm.FirstName; } if (current.LastName != vm.LastName) { current.LastName = vm.LastName; } if (current.BirthDate != vm.BirthDate) { current.BirthDate = vm.BirthDate; } if (current.Gender != vm.Gender) { current.Gender = vm.Gender; } if (current.ProfileId != vm.ProfileId) { current.ProfileId = vm.ProfileId; } if (current.CountryId != vm.CountryId) { current.CountryId = vm.CountryId; } var updateResult = _bo.Update(current); if (!updateResult.Success) { return(new ObjectResult(HttpStatusCode.InternalServerError)); } return(Ok()); }
public void TestUpdateVisitor() { 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.Update(item); resList = vbo.List(); 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); }