Example #1
0
        public GetConfigAppViewModel Add(AddConfigAppViewModel model, int userID)
        {
            if (_dbContext.ConfigApp.Any(ca => ca.Name == model.Name && !ca.IsDeleted))
            {
                throw new AException(ErrorCode.NameExist);
            }

            var entity = new MapperWrapper <AddConfigAppViewModel, ConfigApp>().GetEntity(model);

            using (var transaction = _dbContext.Database.BeginTransaction())
            {
                try
                {
                    _dbContext.Add <ConfigApp, int>(entity, userID);

                    _dbContext.AddRange <ConfigAppEnvironment, int>(model.AppEnvironmentList.Select(eid => new ConfigAppEnvironment()
                    {
                        ConfigAppID         = entity.ID,
                        ConfigEnvironmentID = eid
                    }).ToList(), userID);

                    transaction.Commit();
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    throw;
                }
            }

            return(new MapperWrapper <GetConfigAppViewModel, ConfigApp>().GetModel(entity));
        }
Example #2
0
        public void Test()
        {
            var addConfigApp = new AddConfigAppViewModel()
            {
                Name = $"{DateTime.Now.Ticks}"
            };

            var newConfigApp = _biz.Add(addConfigApp, 0);

            Assert.IsTrue(newConfigApp.ID > 0);

            try
            {
                var temp = _biz.Add(addConfigApp, 0);

                _biz.Delete(newConfigApp.ID, 0);
                _biz.Delete(temp.ID, 0);
                Assert.Fail("check app name failed.");
            }
            catch (AException aex)
            {
                Assert.AreEqual((int)ErrorCode.NameExist, aex.ErrorCode);
            }

            var updateConfigApp = new MapperWrapper <UpdateConfigAppViewModel, GetConfigAppViewModel>().GetModel(newConfigApp);

            updateConfigApp.Name += "_D";
            _biz.Update(updateConfigApp, 0);

            Assert.AreEqual(updateConfigApp.Name, _biz.Get(newConfigApp.ID).Name);

            _biz.Delete(newConfigApp.ID, 0);
        }
Example #3
0
        public GetConfigAppViewModel Add(AddConfigAppViewModel model, int userID)
        {
            if (_dbContext.ConfigApp.Any(ca => ca.Name == model.Name && !ca.IsDeleted))
            {
                throw new AException(ErrorCode.NameExist);
            }

            var entity = new MapperWrapper <AddConfigAppViewModel, ConfigApp>().GetEntity(model);

            _dbContext.Add <ConfigApp, int>(entity, userID);

            return(new MapperWrapper <GetConfigAppViewModel, ConfigApp>().GetModel(entity));
        }
Example #4
0
        public void Test()
        {
            var addConfigApp = new AddConfigAppViewModel()
            {
                Name = $"{DateTime.Now.Ticks}",
                AppEnvironmentList = new List <int>()
                {
                    1, 2
                }
            };

            var newConfigApp = _biz.Add(addConfigApp, 0);

            Assert.IsTrue(newConfigApp.ID > 0);

            try
            {
                var temp = _biz.Add(addConfigApp, 0);

                _biz.Delete(newConfigApp.ID, 0);
                _biz.Delete(temp.ID, 0);
                Assert.Fail("check app name failed.");
            }
            catch (AException aex)
            {
                Assert.AreEqual((int)ErrorCode.NameExist, aex.ErrorCode);
            }

            var updateConfigApp = new MapperWrapper <UpdateConfigAppViewModel, GetConfigAppViewModel>().GetModel(newConfigApp);

            updateConfigApp.Name += "_D";
            updateConfigApp.AppEnvironmentList = new List <int>()
            {
                2, 3
            };

            // refresh dbcontext change tracker
            _biz = _services.BuildServiceProvider().GetService <ConfigAppBiz>();
            _biz.Update(updateConfigApp, 0);

            Assert.AreEqual(updateConfigApp.Name, _biz.Get(newConfigApp.ID).Name);

            var updatedConfigApp = _biz.Get(updateConfigApp.ID);

            Assert.IsTrue(updatedConfigApp.AppEnvironmentList.Intersect(new List <int>()
            {
                2, 3
            }).Count() == 2);

            _biz.Delete(newConfigApp.ID, 0);
        }
Example #5
0
 public GetConfigAppViewModel Post(AddConfigAppViewModel model)
 {
     return(_biz.Add(model, User.GetUserID()));
 }