public void CanValidateId() { //Arrange IValidator <UpdateCountry> validator = GetValidator(); UpdateCountry updateCountry = new UpdateCountry { Id = serviceMockFactory.CountryMock.ValidId, Name = "Test Name", Abbreviation = "Test Abbreviation" }; //Act ValidationResult result = validator.Validate(updateCountry); //Assert Assert.True(result.IsValid); //Arrange updateCountry.Id = Guid.NewGuid(); //Act result = validator.Validate(updateCountry); //Assert Assert.False(result.IsValid); }
public int UpdateCountry(UpdateCountry updateCountry) { int result = 0; using (TestingSample1Entities testingSample1Entities = new TestingSample1Entities()) { ObjectParameter opResult = new ObjectParameter("Result", typeof(int)); testingSample1Entities.CountryUpdate(updateCountry.CountryId, updateCountry.CountryName, updateCountry.ModifiedBy, opResult); result = Convert.ToInt32(opResult.Value); } return(result); }
public void CanValidateUpdateCountry(string name, string abbreviation, bool expected) { //Arrange IValidator <UpdateCountry> validator = GetValidator(); UpdateCountry addCountry = new UpdateCountry { Id = serviceMockFactory.CountryMock.ValidId, Name = name, Abbreviation = abbreviation }; //Act ValidationResult result = validator.Validate(addCountry); //Assert Assert.Equal(result.IsValid, expected); }
public async Task <ActionResult <UpdateCountryResponse> > Put( [FromRoute] Guid id, [FromBody] CountryForm Country, CancellationToken cancellationToken ) { var request = new UpdateCountry() { RequestId = this.GetRequestId(), Id = id, Country = Country, }; var response = await _mediator.Send(request, cancellationToken); return(Ok(response)); }
public ActionResult Update_Post(UpdateCountry updateCountry) { if (!ModelState.IsValid) { return(View()); } int result = iCountry.UpdateCountry(updateCountry); if (result > 0) { return(RedirectToAction("Index")); } else { return(View()); } }
public IApiResult Update(UpdateCountry operation) { var result = operation.ExecuteAsync().Result; if (result is ValidationsOutput) { return(new ApiResult <List <ValidationItem> >() { Data = ((ValidationsOutput)result).Errors }); } else { return(new ApiResult <object>() { Status = ApiResult <object> .ApiStatus.Success }); } }
public async Task <UpdateCountryResponse> Handle(UpdateCountry request, CancellationToken cancellationToken) { var response = new UpdateCountryResponse() { RequestId = request.RequestId, }; if (response.FromResult(await _updateCountryValidator.ValidateAsync(request, cancellationToken))) { var country = await _bookShelfContext.Countries .FindAsync(new object[] { request.Id }, cancellationToken); country.Name = request.Country.Name; await _bookShelfContext.SaveChangesAsync(cancellationToken); } return(response); }
public ActionResult Update_Get(int id) { try { var country = iCountry.GetCountry(new Country() { CountryId = id }).FirstOrDefault(); if (country == null) { return(RedirectToAction("Index")); } UpdateCountry updateCountry = new UpdateCountry(); updateCountry.CountryId = Convert.ToInt32(country.CountryId); updateCountry.CountryName = country.CountryName; return(View(updateCountry)); } catch (Exception ex) { throw ex; } }
public async Task <IActionResult> Put(Guid id, UpdateCountry command) => await SendAsync(command.Bind(c => c.Id, id), resourceId : command.Id, resource : "countries");