コード例 #1
0
 public ColumnEntity(ColumnDescViewModel viewModel) : base()
 {
     if (viewModel != null)
     {
         Id          = viewModel.Id;
         Description = viewModel.Description;
     }
 }
コード例 #2
0
        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);
        }
コード例 #3
0
        public void Valid()
        {
            var model = new ColumnDescViewModel()
            {
                Description = "Test"
            };

            var result = model.Validate();

            Assert.False(result.Any());
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
 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));
 }