Esempio n. 1
0
        public void ToEntity()
        {
            var model = new ColumnViewModel()
            {
                Default     = "Test",
                Description = "Test",
                Id          = 1,
                IsIdentity  = "N",
                IsNull      = "Y",
                Length      = 1,
                Name        = "Test",
                Number      = 1,
                TableName   = "Test",
                Type        = "Test"
            };

            var result = model.Validate();

            Assert.False(result.Any());

            var entity = model.GetEntity();

            Assert.Equal(model.Default, entity.Default);
            Assert.Equal(model.Description, entity.Description);
            Assert.Equal(model.Id, entity.Id);
            Assert.Equal(model.IsIdentity.First(), entity.IsIdentity);
            Assert.Equal(model.IsNull.First(), entity.IsNull);
            Assert.Equal(model.Length, entity.Length);
            Assert.Equal(model.Name.ToUpper(CultureInfo.InvariantCulture), entity.Name);
            Assert.Equal(model.Number, entity.Number);
            Assert.Equal(model.TableName.ToUpper(CultureInfo.InvariantCulture), entity.TableName);
            Assert.Equal(model.Type, entity.Type);
        }
Esempio n. 2
0
 public IActionResult Create([Bind("Id,TableName,Name,Number,Type,Length,Default,IsNull,IsIdentity,Description")] ColumnViewModel viewModel)
 {
     try
     {
         if (ModelState.IsValid && viewModel != null)
         {
             _columnRepository.Insert(viewModel.GetEntity()).Wait();
             return(RedirectToAction(nameof(Index), new { tablename = viewModel.TableName }));
         }
         return(View(viewModel));
     }
     catch (ExternalException e)
     {
         _notification.AddNotification(e.StackTrace, e.Message, LogLevel.Error);
         return(RedirectToAction(nameof(Index), "Home"));
     }
 }