当前位置: 首页>>代码示例>>C#>>正文


C# UnitOfWork.Add方法代码示例

本文整理汇总了C#中UnitOfWork.Add方法的典型用法代码示例。如果您正苦于以下问题:C# UnitOfWork.Add方法的具体用法?C# UnitOfWork.Add怎么用?C# UnitOfWork.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnitOfWork的用法示例。


在下文中一共展示了UnitOfWork.Add方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Add_ValidEntity_EntityAddedToDbContext

        public void Add_ValidEntity_EntityAddedToDbContext()
        {
            FakeSet<User> setStub = new FakeSet<User>();
            Mock<DbContext> contextStub = new Mock<DbContext>();
            contextStub.Setup(c => c.Set<User>()).Returns(setStub);

            IInterceptorsResolver interceptorsResolver =  new Mock<IInterceptorsResolver>().Object;
            UnitOfWork uof = new UnitOfWork(contextStub.BuildFactoryStub(), interceptorsResolver);

            User u = new User();
            uof.Add(u);

            Assert.IsTrue(setStub.Values.Contains(u));
        }
开发者ID:popcatalin81,项目名称:DataAccess,代码行数:14,代码来源:UnitOfWork.AddTests.cs

示例2: AddServer

        public ServerModel AddServer(ServerModel model)
        {
            if (model == null)
                throw new ArgumentNullException("model");

            Server appToReturn;

            using (var unitOfWork = new UnitOfWork(_connectionString))
            {
                bool userAuthorised = UserAuthorizedToAccessSuite(unitOfWork, model.UserId, model.SuiteId,
                    new[] {RoleType.Admin});
                if (!userAuthorised)
                    throw new UnauthorizedUserException(
                        "User does not have access or sufficient privileges for this action to suite: " + model.SuiteId);

                appToReturn = model.ToNewDbObject();
                unitOfWork.Add(appToReturn);
            }

            if (appToReturn != null)
                return appToReturn.ToModel();
            return null;
        }
开发者ID:punitganshani,项目名称:KonfDB,代码行数:23,代码来源:ConfigurationDataStore.cs

示例3: AddSuite

        public SuiteModel AddSuite(SuiteCreateModel suiteModel)
        {
            Suite suiteReturn;
            using (var unitOfWork = new UnitOfWork(_connectionString))
            {
                if (unitOfWork.Context.Suites.Any(x => x.SuiteName == suiteModel.SuiteName))
                    throw new InvalidOperationException("Suite already exists with name:" + suiteModel.SuiteName);

                var suiteDB = suiteModel.ToNewDbObject();
                unitOfWork.Add(suiteDB);

                suiteReturn = suiteDB;

                //if (unitOfWork.Context.SuiteUsers.Any(x => x.UserId == suiteModel.UserId && x.SuiteId == suiteDB.SuiteId)) return;

                //var userMapping = new SuiteUser()
                //{
                //    SuiteId = suiteDB.SuiteId,
                //    UserId = suiteModel.UserId
                //};

                //unitOfWork.Add(userMapping);

                foreach (var environment in suiteModel.Environments)
                {
                    environment.SuiteId = suiteDB.SuiteId;
                    environment.IsActive = true;

                    unitOfWork.Add(environment.ToNewDbObject());
                }

                foreach (var application in suiteModel.Applications)
                {
                    application.SuiteId = suiteDB.SuiteId;
                    application.IsActive = true;

                    unitOfWork.Add(application.ToNewDbObject());
                }

                foreach (var region in suiteModel.Regions)
                {
                    region.SuiteId = suiteDB.SuiteId;
                    region.IsActive = true;

                    unitOfWork.Add(region.ToNewDbObject());
                }

                foreach (var server in suiteModel.Servers)
                {
                    server.SuiteId = suiteDB.SuiteId;
                    server.IsActive = true;

                    unitOfWork.Add(server.ToNewDbObject());
                }

                unitOfWork.Add(new SuiteUser
                {
                    SuiteId = suiteReturn.SuiteId,
                    UserId = (int) suiteModel.UserId,
                    RoleId = (int) RoleType.Admin
                });
            }

            return GetSuite(suiteModel.UserId, suiteReturn.SuiteId);
        }
开发者ID:punitganshani,项目名称:KonfDB,代码行数:65,代码来源:ConfigurationDataStore.cs

示例4: AddEnvironment

        public EnvironmentModel AddEnvironment(EnvironmentModel model)
        {
            if (model == null)
                throw new ArgumentNullException("model");

            Environment environmentToReturn = null;

            using (var unitOfWork = new UnitOfWork(_connectionString))
            {
                bool userAuthorised = UserAuthorizedToAccessSuite(unitOfWork, model.UserId, model.SuiteId,
                    new[] {RoleType.Admin});
                if (!userAuthorised)
                    throw new UnauthorizedUserException(
                        "User does not have access or sufficient privileges for this action to suite: " + model.SuiteId);

                environmentToReturn = model.ToNewDbObject();
                unitOfWork.Add(environmentToReturn);
            }

            return environmentToReturn.ToModel();
        }
开发者ID:punitganshani,项目名称:KonfDB,代码行数:21,代码来源:ConfigurationDataStore.cs

示例5: AddAuditRecord

 public void AddAuditRecord(AuditRecordModel auditRecord)
 {
     using (var unitOfWork = new UnitOfWork(_connectionString))
     {
         unitOfWork.Add(auditRecord.ToNewDbObject());
     }
 }
开发者ID:punitganshani,项目名称:KonfDB,代码行数:7,代码来源:ConfigurationDataStore.cs

示例6: AddMapping

        public MappingModel AddMapping(MappingModel model)
        {
            if (model == null)
                throw new ArgumentNullException("model");

            Mapping mapToReturn;

            using (var unitOfWork = new UnitOfWork(_connectionString))
            {
                bool userAuthorised = UserAuthorizedToAccessSuite(unitOfWork, model.UserId, model.SuiteId,
                    new[] {RoleType.Admin});
                if (!userAuthorised)
                    throw new UnauthorizedUserException(
                        "User does not have access or sufficient privileges for this action to suite: " + model.SuiteId);

                if (
                    !unitOfWork.Context.Parameters.Any(
                        x => x.ParameterId == model.ParameterId && x.SuiteId == model.SuiteId))
                    throw new InvalidOperationException(
                        "Mismatch between parameter id and suite id. Can not add mapping!");

                if (!unitOfWork.Context.Servers.Any(x => x.ServerId == model.ServerId && x.SuiteId == model.SuiteId))
                    throw new InvalidOperationException("Mismatch between server id and suite id. Can not add mapping!");

                if (!unitOfWork.Context.Regions.Any(x => x.RegionId == model.RegionId && x.SuiteId == model.SuiteId))
                    throw new InvalidOperationException("Mismatch between region id and suite id. Can not add mapping!");

                if (
                    !unitOfWork.Context.Environments.Any(
                        x => x.EnvironmentId == model.EnvironmentId && x.SuiteId == model.SuiteId))
                    throw new InvalidOperationException(
                        "Mismatch between environment id and suite id. Can not add mapping!");

                if (
                    !unitOfWork.Context.Applications.Any(
                        x => x.ApplicationId == model.ApplicationId && x.SuiteId == model.SuiteId))
                    throw new InvalidOperationException(
                        "Mismatch between application id and suite id. Can not add mapping!");

                mapToReturn = model.ToNewDbObject();
                unitOfWork.Add(mapToReturn);
            }

            if (mapToReturn != null)
                return mapToReturn.ToModel();
            return null;
        }
开发者ID:punitganshani,项目名称:KonfDB,代码行数:47,代码来源:ConfigurationDataStore.cs


注:本文中的UnitOfWork.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。