public ColumnEntity(ColumnDescViewModel viewModel) : base() { if (viewModel != null) { Id = viewModel.Id; Description = viewModel.Description; } }
public void Required() { var model = new ColumnDescViewModel(); var result = model.Validate(); Assert.True(result.Any()); Assert.Equal("Description", result.ElementAtOrDefault(0).MemberNames.FirstOrDefault()); Assert.Equal("The Description field is required.", result.ElementAtOrDefault(0).ErrorMessage); }
public void Valid() { var model = new ColumnDescViewModel() { Description = "Test" }; var result = model.Validate(); Assert.False(result.Any()); }
public void RangeOrLength() { var model = new ColumnDescViewModel() { Description = "Test", Id = -1 }; var result = model.Validate(); Assert.True(result.Any()); Assert.Equal("Id", result.ElementAtOrDefault(0).MemberNames.FirstOrDefault()); Assert.Equal("The field Id must be between 0 and 9,223372036854776E+18.", result.ElementAtOrDefault(0).ErrorMessage); }
public void FromEntity() { var entity = new ColumnEntity() { Description = "Test", Id = 1 }; var model = new ColumnDescViewModel(entity); var result = model.Validate(); Assert.False(result.Any()); Assert.Equal(entity.Description, model.Description); Assert.Equal(entity.Id, model.Id); }
public IActionResult Edit(string tableName, [Bind("Id,Description")] ColumnDescViewModel viewModel) { if (ModelState.IsValid && viewModel != null) { try { _columnRepository.Update(viewModel.GetEntity()).Wait(); } catch (Exception) { if (_columnRepository.Exists(viewModel.Id).Result) { throw; } } return(RedirectToAction(nameof(Index), new { tablename = tableName })); } return(View(viewModel)); }