Example #1
0
        public bool SaveComments(CommentOnTask entity)
        {
            var exist = Repository.GetById(entity.Id);

            if (exist != null)
            {
                entity.Id           = exist.Id;
                entity.TaskAssign   = exist.TaskAssign;
                entity.TaskAssignId = exist.TaskAssignId;
                entity.TaskComment  = exist.TaskComment;
                entity.Created      = exist.Created;
                entity.IsActive     = exist.IsActive;
                entity.Modified     = System.DateTime.Now;
                entity.ModifiedBy   = "Admin";
            }

            else
            {
                entity.Created    = System.DateTime.Now;
                entity.CreatedBy  = "Admin";
                entity.IsActive   = true;
                entity.Modified   = System.DateTime.Now;
                entity.ModifiedBy = "Admin";
            }

            Repository.SaveOrUpdate(entity);
            return(Repository.Done());
        }
        public override bool SaveOrUpdate(ChatMessage entity)
        {
            var exist = Repository.GetById(entity.Id);

            if (exist == null)
            {
                entity.CreatedBy  = "Admin";
                entity.Created    = System.DateTime.Now;
                entity.ModifiedBy = "Admin";
                entity.Modified   = System.DateTime.Now;
                entity.IsActive   = true;
            }
            else
            {
                entity.CreatedBy = exist.CreatedBy;

                entity.Created = exist.Created;

                entity.ModifiedBy = "Admin";

                entity.Modified = DateTime.Now;
                entity.IsActive = true;
            }


            Repository.SaveOrUpdate(entity);
            return(Repository.Done());
        }
Example #3
0
        public void PagingEntities()
        {
            Repository <Company> .DeleteAll();

            UnitOfWork.Current.TransactionalFlush();
            UnitOfWork.CurrentSession.Clear();


            var company = new Company("RW")
            {
                Name = "RealWeb"
            };

            Repository <Company> .SaveOrUpdate(company);

            for (int i = 0; i < 10; i++)
            {
                Repository <Company> .SaveOrUpdate(new Company("RW_" + i) { Name = "RealWeb_" + i });
            }

            UnitOfWork.Current.TransactionalFlush();
            UnitOfWork.CurrentSession.Clear();

            var savedCompany = Repository <Company> .FindAll(1, 5);

            savedCompany.Count.Should().Be(5);

            Repository <Company> .DeleteAll();

            UnitOfWork.Current.TransactionalFlush();
            UnitOfWork.CurrentSession.Clear();
        }
Example #4
0
        public override bool SaveOrUpdate(Group entity)
        {
            if (entity.Id == 0)
            {
                entity.CreatedBy  = "Admin";
                entity.Created    = System.DateTime.Now;
                entity.ModifiedBy = "Admin";
                entity.Modified   = System.DateTime.Now;
                entity.IsActive   = true;
                Repository.Save(entity);          // Db.SaveChanges() > 0;
            }
            else
            {
                var exist = Repository.GetById(entity.Id);
                entity.CreatedBy = exist.CreatedBy;

                entity.Created = exist.Created;

                entity.ModifiedBy = exist.ModifiedBy;

                entity.Modified = exist.Modified;
                entity.IsActive = true;
                Repository.SaveOrUpdate(entity);

                Repository.Done();
            }

            //Repository.SaveOrUpdate(entity);
            return(true);
        }
Example #5
0
        public void TestCreateMoreParty()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Post, Guid> postRepository = new Repository<Post, Guid>(store);
                IRepository<Employee, Guid> employeeRepository = new Repository<Employee, Guid>(store);
                IRepository<PartyHierarchy, Guid> partyHierarchyRepository = new Repository<PartyHierarchy, Guid>(store);
                Employee employee = new Employee()
                {
                    Name = "Bob",
                };

                Post post = new Post()
                {
                    Name = "總經理室副主管",
                };

                Post parentPost = postRepository.Query(q => q.Name == "總經理室主管").First();
                employeeRepository.SaveOrUpdate(employee);
                postRepository.SaveOrUpdate(post);

                PartyService partyService = new PartyService(partyHierarchyRepository);
                partyService.AddAccountability(parentPost, post);
                unitwork.SaveChanges();
                partyService.AddEmployeeToPost(post, employee);
                unitwork.SaveChanges();
            }
        }
Example #6
0
        public void SimpleEntity()
        {
            Repository <Company> .DeleteAll();

            UnitOfWork.Current.Flush();
            UnitOfWork.Current.Clear();

            var company = new Company("NSoft")
            {
                Name = "리얼웹"
            };

            Repository <Company> .SaveOrUpdate(company);

            UnitOfWork.Current.Flush();
            UnitOfWork.Current.Clear();

            var savedCompany = UnitOfWork.CurrentSession.Query <Company>().Where(c => c.Code == "NSoft").Single();

            Assert.AreEqual(company.Code, savedCompany.Code);
            Assert.AreEqual(company.Name, savedCompany.Name);

            Repository <Company> .DeleteAll();

            UnitOfWork.Current.Flush();
            UnitOfWork.Current.Clear();
        }
Example #7
0
        public void CreateTwo()
        {
            // Arrange
            var authToken1 = new AuthToken()
            {
                OwnerId = 88, Token = "CheeseSandwich"
            };
            var authToken2 = new AuthToken()
            {
                OwnerId = 77, Token = "ChocolateCake"
            };

            // Act
            Repository.SaveOrUpdate(authToken1);
            Repository.SaveOrUpdate(authToken2);

            // Assert
            var list = Repository.Select <AuthToken>();

            Assert.AreEqual(2, list.Count);
            Assert.AreEqual(88, list[0].OwnerId);
            Assert.AreEqual("CheeseSandwich", list[0].Token);
            Assert.AreEqual(77, list[1].OwnerId);
            Assert.AreEqual("ChocolateCake", list[1].Token);
        }
Example #8
0
    protected void uploadMiasta_Click(object sender, EventArgs e)
    {
        if(fileMiasta.HasFile)
        {
            MemoryStream stream = new MemoryStream(fileMiasta.FileBytes);
            XmlReaderSettings settings = new XmlReaderSettings();

            int i = 0;
            Repository<City, Guid> cityrep = new Repository<City, Guid>();
            using (XmlReader r = XmlReader.Create(stream, settings))
            {
                XPathDocument xpathDoc = new XPathDocument(r);
                XPathNavigator xpathNav = xpathDoc.CreateNavigator();

                string xpathQuery = "/teryt/catalog/row/col[attribute::name='NAZWA']";

                XPathExpression xpathExpr = xpathNav.Compile(xpathQuery);

                XPathNodeIterator xpathIter = xpathNav.Select(xpathExpr);

                while (xpathIter.MoveNext())
                {
                    City city = new City();
                    city.Name = xpathIter.Current.Value;

                    cityrep.SaveOrUpdate(city);
                    if (i % 500 == 0)
                        HBManager.Instance.GetSession().Flush();
                    i++;
                    //AddressManager.InsertCity(new City { Name = xpathIter.Current.Value });
                }
            }
            HBManager.Instance.GetSession().Flush();
        }
    }
Example #9
0
        public async Task <IActionResult> GetVideoDetails([Required] string videoIdOrUrl, CancellationToken ct = default(CancellationToken))
        {
            try {
                using (var api = new YoutubeApi(_settingsProvider.ApiKeys.Next())) {
                    var vidId = new VideoUrlParser().GetVideoId(videoIdOrUrl);
                    var vid   = await api.GetVideoDetails(vidId, ct);

                    var vids = vid.Items.Select(v => v.MapToDbEntity()).ToList();
                    if (!vids.Any())
                    {
                        return(NotFound(new ProblemDetails {
                            Status = StatusCodes.Status404NotFound,
                            Title = "Not Found",
                        }));
                    }
                    await _repository.SaveOrUpdate(vids);

                    return(Ok(vids));
                }
            }
            catch (Exception e) {
                return(BadRequest(new ProblemDetails {
                    Status = StatusCodes.Status400BadRequest,
                    Title = e.Message,
                    Type = e.GetType().FullName,
                }));
            }
        }
        public override bool SaveOrUpdate(EmployeeInfo entity)
        {
            if (entity.Id == 0)
            {
                entity.CreatedBy  = "Admin";
                entity.Created    = System.DateTime.Now;
                entity.ModifiedBy = "Admin";
                entity.Modified   = System.DateTime.Now;
                entity.IsActive   = true;
                Repository.SaveOrUpdate(entity);
            }
            else
            {
                var exist = Repository.GetById(entity.Id);
                entity.CreatedBy = exist.CreatedBy;

                entity.Created = exist.Created;

                entity.ModifiedBy = exist.ModifiedBy;

                entity.Modified = exist.Modified;
                entity.IsActive = true;
                Repository.SaveOrUpdate(entity);
                Repository.Done();
            }


            Repository.SaveOrUpdate(entity);
            return(Repository.Done());
        }
        public void can_handle_belgian_identifications()
        {
            // Arrange
            BelgianIdentifications subject =
                new BelgianIdentifications
            {
                BBAN                   = new BBAN("850-895676-978"),
                DMFA                   = new DMFA("DMFAP123456789A"),
                INSS                   = new INSS("55.25.02.008-01"),
                KBO                    = new KBO("0453.834.195"),
                RSZ                    = new RSZ("0133-296 720"),
                IBAN                   = new IBAN("AL472 1211 0090 0000 0023 5698 741"),
                BIC                    = new BIC("KREDBEBB"),
                TemporaryRSZ           = new TemporaryRSZ("5 105009119"),
                VAT                    = new VAT("0453.834.195"),
                CompanyLocalUnitNumber = new CompanyLocalUnitNumber("2.069.315153")
            };

            // Act
            RunInsideTransaction(
                () =>
            {
                Repository.SaveOrUpdate(subject);
                Assert.That(subject.IsTransient, Is.False);
            },
                true);

            BelgianIdentifications actual = Repository.GetById(subject.Id);

            // Assert
            Assert.That(BelgianIdentifications.Comparer.Equals(subject, actual), Is.True);
        }
Example #12
0
        public void TransactionFlushTest()
        {
            const int ItemCount = 100;

            for (var i = 0; i < ItemCount; i++)
            {
                Repository <DomainObjectFromDatabase1> .SaveOrUpdate(new DomainObjectFromDatabase1("database1_transactional_flush_" + i));

                Repository <DomainObjectFromDatabase2> .SaveOrUpdate(new DomainObjectFromDatabase2("database2_transactional_flush_" + i));
            }
            UnitOfWork.Current.TransactionalFlush();
            UnitOfWork.Current.Clear();

            Repository <DomainObjectFromDatabase1> .Count().Should().Be.GreaterThanOrEqualTo(ItemCount);

            Repository <DomainObjectFromDatabase2> .Count().Should().Be.GreaterThanOrEqualTo(ItemCount);

            Repository <DomainObjectFromDatabase1> .DeleteAll();

            Repository <DomainObjectFromDatabase2> .DeleteAll();

            UnitOfWork.Current.TransactionalFlush();
            UnitOfWork.Current.Clear();

            Repository <DomainObjectFromDatabase1> .Count().Should().Be(0);

            Repository <DomainObjectFromDatabase2> .Count().Should().Be(0);
        }
Example #13
0
        public void CanGetFutureEntities()
        {
            var parent = new Parent(Guid.NewGuid())
            {
                Name = "abc", Age = 123
            };
            var parentId = parent.Id;

            Repository <Parent> .SaveOrUpdate(parent);

            UnitOfWork.Current.Flush();

#pragma warning disable 0618

            var futureParent = Repository <Parent> .FutureGet(parentId);

            var futureChild = Repository <Child> .FutureGet(Guid.NewGuid());

#pragma warning restore 0618

            Assert.IsNull(futureChild.Value);

            Assert.IsNotNull(futureParent.Value);

            Console.WriteLine("Parent : " + futureParent.Value.ToString(true));
        }
Example #14
0
        public void TestCreateParty()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Party, Guid> partyRepository = new Repository<Party, Guid>(store);
                //用partyRepository也可以存進去,不知差別在哪
                IRepository<Employee, Guid> employeeRepository = new Repository<Employee, Guid>(store);
                IRepository<Post, Guid> postRepository = new Repository<Post, Guid>(store);
                IRepository<PartyHierarchy, Guid> partyHierarchyRepository = new Repository<PartyHierarchy, Guid>(store);
                Employee employee = new Employee()
                {
                    Name = "Allen"
                };

                Post post = new Post()
                {
                    Name = "總經理室主管"
                };

                employeeRepository.SaveOrUpdate(employee);
                postRepository.SaveOrUpdate(post);

                PartyService partyService = new PartyService(partyHierarchyRepository);
                partyService.AddEmployeeToPost(post,employee);

                unitwork.SaveChanges();
            }
        }
Example #15
0
        private const string ConnectionString = "server=localhost;user id=root;persistsecurityinfo=True;database=supervkappdb"; //

        #endregion Fields

        #region Methods

        static void Main(string[] args)
        {
            var nhibernatehelper = new NHibernateHelper(ConnectionString);
            var unitofwork = new UnitOfWork(nhibernatehelper.SessionFactory);

            //попробуем чонить добавить в бд

            var user = new UserDomain
            {
                //Id = "egorveidt", какого черта я сделал интовый айдишник, фаак !!! переделать
                FirstName = "Егор",
                LastName = "Пичугов",
                Age = 21,
                Male = true
            };
            var post = new PostDomain
            {
                Date = new DateTime(2016, 01, 07),
                Text = "test text exst",
            };

            post.AddSnapshot(new PostSnapshotDomain()
            {
                CountComments = 1,
                CountLikes = 10,
                CountReposts = 2,
                Date = new DateTime(2016, 01, 07)
            });

            user.AddPost(post);
            var userRepository = new Repository<UserDomain>(unitofwork.Session);
            userRepository.SaveOrUpdate(user);
            unitofwork.Commit();
        }
Example #16
0
        public override bool SaveOrUpdate(Department entity)
        {
            if (entity.Id == 0)
            {
                entity.CreatedBy  = "Admin";
                entity.Created    = System.DateTime.Now;
                entity.ModifiedBy = "Admin";
                entity.Modified   = System.DateTime.Now;
                entity.IsActive   = true;
                Repository.SaveOrUpdate(entity);
            }
            else
            {
                var exist = Repository.GetById(entity.Id);
                entity.CreatedBy = exist.CreatedBy;

                //DateTime createdOn = Convert.ToDateTime(System.DateTime.Now);
                //String createdOnText = createdOn.ToString("yyyy-MM-dd");
                //entity.Created = Convert.ToDateTime(createdOnText);
                entity.Created = exist.Created;

                entity.ModifiedBy = exist.ModifiedBy;

                //DateTime modifiedOn = Convert.ToDateTime(System.DateTime.Now);
                //String modifiedOnText = createdOn.ToString("yyyy-MM-dd");
                //entity.Modified = Convert.ToDateTime(modifiedOnText);

                entity.Modified = exist.Modified;
                entity.IsActive = true;
            }


            Repository.SaveOrUpdate(entity);
            return(Repository.Done());
        }
Example #17
0
        public void TestAddChild()
        {
            IStore store = new ThreadStaticStore();
            IDbContextFactory contextFactory = new DbContextFactory();

            using (UnitOfWork unitwork = new UnitOfWork(store, contextFactory))
            {
                IRepository<Demo, Guid> demoRepository = new Repository<Demo, Guid>(store);
                IRepository<DemoChild, Guid> demoChildRepository = new Repository<DemoChild, Guid>(store);
                IRepository<DemoBrother, Guid> demoBrotherRepository = new Repository<DemoBrother, Guid>(store);
                Demo demo = new Demo()
                {
                    Name = "C"
                };

                DemoChild child = new DemoChild();
                demo.Children.Add(child);

                DemoBrother brother = new DemoBrother();
                demo.Brothers.Add(brother);

                demoRepository.SaveOrUpdate(demo);
                demoChildRepository.SaveOrUpdate(child);
                demoBrotherRepository.SaveOrUpdate(brother);

                unitwork.SaveChanges();
            }
        }
        public override bool SaveOrUpdate(CompanyUser entity)
        {
            var exist = Repository.GetById(entity.Id);

            if (exist != null)
            {
                entity.Name           = exist.Name;
                entity.Address        = exist.Address;
                entity.Email          = exist.Email;
                entity.Phone          = exist.Phone;
                entity.ProfilePicture = exist.ProfilePicture;
                entity.CreatedOn      = exist.CreatedOn;
                entity.IsActive       = exist.IsActive;
                entity.UpdatedBy      = log.UserId.ToString();
                entity.UpdatedOn      = new LoginInfo().CurrentTime;
            }

            else
            {
                entity.CreatedOn = System.DateTime.Now;
                entity.IsActive  = true;
                entity.UpdatedBy = log.UserId.ToString();
                entity.UpdatedOn = new LoginInfo().CurrentTime;
            }

            Repository.SaveOrUpdate(entity);
            return(Repository.Done());
        }
Example #19
0
        public void CreateTwo()
        {
            // Arrange
            var login1 = new Login()
            {
                Username = "******", Password = "******"
            };
            var login2 = new Login()
            {
                Username = "******", Password = "******"
            };

            // Act
            Repository.SaveOrUpdate(login1);
            Repository.SaveOrUpdate(login2);

            // Assert
            var list = Repository.Select <Login>();

            Assert.AreEqual(2, list.Count);
            Assert.AreEqual("username", ((Login)list[0]).Username);
            Assert.AreEqual("password", ((Login)list[0]).Password);
            Assert.AreEqual("login1", ((Login)list[1]).Username);
            Assert.AreEqual("password2", ((Login)list[1]).Password);
        }
Example #20
0
        private const string ConnectionString = "server=localhost;user id=root;persistsecurityinfo=True;database=supervkappdb";         //
        static void Main(string[] args)
        {
            var nhibernatehelper = new NHibernateHelper(ConnectionString);
            var unitofwork       = new UnitOfWork(nhibernatehelper.SessionFactory);

            //попробуем чонить добавить в бд

            var user = new UserDomain
            {
                //Id = "egorveidt", какого черта я сделал интовый айдишник, фаак !!! переделать
                FirstName = "Егор",
                LastName  = "Пичугов",
                Age       = 21,
                Male      = true
            };
            var post = new PostDomain
            {
                Date = new DateTime(2016, 01, 07),
                Text = "test text exst",
            };

            post.AddSnapshot(new PostSnapshotDomain()
            {
                CountComments = 1,
                CountLikes    = 10,
                CountReposts  = 2,
                Date          = new DateTime(2016, 01, 07)
            });

            user.AddPost(post);
            var userRepository = new Repository <UserDomain>(unitofwork.Session);

            userRepository.SaveOrUpdate(user);
            unitofwork.Commit();
        }
Example #21
0
        private void Update_Click(object sender, EventArgs e)
        {
            if (!Validate())
            {
                return;
            }

            var DbUser = Repository.FindOne <User>(x => x.Email.Equals(Email));

            DbUser.FirstName   = FirstName.Text;
            DbUser.LastName    = LastName.Text;
            DbUser.About       = About.Text;
            DbUser.ImageSource = ImageSource;

            Repository.SaveOrUpdate(DbUser);
            AlertDialog.Builder dialog = new AlertDialog.Builder(this);
            AlertDialog         alert  = dialog.Create();

            alert.SetIcon(Resource.Drawable.sound);
            alert.SetTitle("Success");
            alert.SetMessage("User Updated succesfully \n do you want to Go back");
            alert.SetButton("ListView", (s, ev) =>
            {
                StartActivity(typeof(ListViewActivity));
            });

            alert.SetButton2("No", (s, ev) =>
            {
                return;
            });
            alert.Show();
        }
Example #22
0
        public void Update()
        {
            // Arrange
            var todo = new TodoEntry()
            {
                OwnerId = 23, IsCompleted = false, Description = "Make a nice cake.", LastUpdated = new DateTime(2012, 12, 12)
            };

            // Act
            Repository.SaveOrUpdate(todo);
            todo.OwnerId++;
            todo.IsCompleted = true;
            todo.Description = "Eat cake.";
            todo.LastUpdated = new DateTime(2010, 10, 10);
            Repository.SaveOrUpdate(todo);

            // Assert
            var list = Repository.Select <TodoEntry>();

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(1, list[0].Id);
            Assert.AreEqual(24, ((TodoEntry)list[0]).OwnerId);
            Assert.AreEqual("Eat cake.", ((TodoEntry)list[0]).Description);
            Assert.AreEqual(true, ((TodoEntry)list[0]).IsCompleted);
            Assert.AreEqual(new DateTime(2010, 10, 10), ((TodoEntry)list[0]).LastUpdated);
        }
Example #23
0
        /// <summary>
        /// Sync single user to server
        /// </summary>
        public async Task <bool> SyncTable <TEntity>(TEntity item) where TEntity : IEntity, IServerEntity
        {
            if (item.SyncStatus == (int)SyncStatus.Ok)
            {
                return(true);
            }
            try
            {
                IRestResult <int> response = await SendRequestAsync(item);

                if (!response.IsSuccess)
                {
                    return(false);
                }
                if (item.SyncStatus == (int)SyncStatus.Deleted)
                {
                    Repository.Delete <User>(x => x.DbId == item.DbId);
                    return(true);
                }
                if (response.Data > 0)
                {
                    item.ServerId   = response.Data;
                    item.SyncStatus = (int)SyncStatus.Ok;
                    Repository.SaveOrUpdate(item);
                    return(true);
                }
                return(false);
            }
            catch (Exception)
            {
                // LOG EXCEPTION
                return(false);
            }
        }
        public bool Delete(Int64 Id)
        {
            FloorRentInfoManager       floorInfoManager       = new FloorRentInfoManager();
            BillingReceivedInfoManager billingReceivedManager = new BillingReceivedInfoManager();
            BillingInfoPerMonthManager billingInfoManager     = new BillingInfoPerMonthManager();

            var exist = Repository.GetById(Id);

            exist.UpdatedBy = Log.UserId.ToString();
            exist.UpdatedOn = new LoginInfo().CurrentTime;
            exist.IsActive  = false;
            exist.IsCurrent = false;
            Repository.SaveOrUpdate(exist);


            var floorRentExist       = floorInfoManager.GetAll().Where(x => x.TenantInfoId == Id && x.IsActive).ToList();
            var billingReceivedExist = billingReceivedManager.GetAll().Where(x => x.TenantInfoId == Id && x.IsActive).ToList();
            var billingInfoExist     = billingInfoManager.GetAll().Where(x => x.TenantInfoId == Id && x.IsActive).ToList();

            foreach (var floors in floorRentExist)
            {
                var existFloor = floorInfoManager.GetById(floors.Id);
                floors.IsActive  = false;
                floors.IsCurrent = false;
                floors.UpdatedBy = Log.UserId.ToString();
                floors.UpdatedOn = new LoginInfo().CurrentTime;


                floorInfoManager.SaveOrUpdateDelete(existFloor);
            }

            foreach (var billingReceive in billingReceivedExist)
            {
                var existBillingReceive = billingReceivedManager.GetById(billingReceive.Id);

                billingReceive.IsActive  = false;
                billingReceive.UpdatedBy = Log.UserId.ToString();
                billingReceive.UpdatedOn = new LoginInfo().CurrentTime;


                billingReceivedManager.SaveOrUpdateDelete(existBillingReceive);
            }


            foreach (var billingInfo in billingInfoExist)
            {
                var existBillingInfo = billingInfoManager.GetById(billingInfo.Id);

                billingInfo.IsActive  = false;
                billingInfo.UpdatedBy = Log.UserId.ToString();
                billingInfo.UpdatedOn = new LoginInfo().CurrentTime;


                billingInfoManager.SaveOrUpdateDelete(existBillingInfo);
            }


            return(Repository.Done());
        }
Example #25
0
 private void EnsureName(ContentItem item)
 {
     if (string.IsNullOrEmpty(item.Name))
     {
         item.Name = item.ID.ToString();
         Repository.SaveOrUpdate(item);
     }
 }
        public bool Delete(Int64 Id)
        {
            var exist = Repository.GetById(Id);

            exist.ModifiedBy = exist.Id.ToString();
            exist.Modified   = System.DateTime.Now;
            exist.IsActive   = false;
            Repository.SaveOrUpdate(exist);
            return(Repository.Done());
        }
Example #27
0
        public bool Confrim(Int64 id)
        {
            var exist = Repository.GetById(id);

            exist.BillStatus = "Confirmed";

            Repository.SaveOrUpdate(exist);

            return(Repository.Done());
        }
 public virtual void Put([FromBody] TClass item)
 {
     try
     {
         repository.SaveOrUpdate(item);
     }
     catch (Exception exception)
     {
         throw new Exception($"{className} | Put | {item}", exception);
     }
 }
Example #29
0
        public ActionResult New([EntityBind(Fetch = false)] T item)
        {
            if (ModelState.IsValid)
            {
                Repository.SaveOrUpdate(item);
                TempData["message"] = "Item successfully added."; //Make use of the CopyMessageFromTempDataToViewData filter to show this in the view.
                return(RedirectToAction("Index"));                //can't use strongly typed redirect here or the wrong controller name will be picked up
            }

            return(View("Edit", BuildEditViewData().With(item)));
        }
            public override void Execute()
            {
                Repository.Save(new FakeEntity(Pleasure.Generator.TheSameString()));
                Repository.Save(new FakeEntity(Pleasure.Generator.String()));

                Repository.SaveOrUpdate(new FakeEntity(Pleasure.Generator.TheSameString()));
                Repository.SaveOrUpdate(new FakeEntity(Pleasure.Generator.String()));

                Repository.Delete <FakeEntity>(Pleasure.Generator.TheSameString());
                Repository.Delete <FakeEntity>(Pleasure.Generator.TheSameString());
            }
Example #31
0
        protected void InsertTestEntity(string name)
        {
            var testEntityRepository = new Repository <TestEntity>();
            var testEntity           = new TestEntity
            {
                Name = name
            };

            testEntityRepository.SaveOrUpdate(testEntity);
            NHibernateSession.Current.Evict(testEntity);
        }
Example #32
0
        public void TestData()
        {
            IStore store = new ThreadStaticStore();
            IDbContextFactory contextFactory = new DbContextFactory();

            using (UnitOfWork unitwork = new UnitOfWork(store, contextFactory))
            {
                IRepository<Demo,Guid> demoRepository = new Repository<Demo,Guid>(store);
                Demo demo = new Demo() { Name = "B"};
                demoRepository.SaveOrUpdate(demo);
                unitwork.SaveChanges();
            }
        }
Example #33
0
        public override bool SaveOrUpdate(Billed entity)
        {
            AdjustManager adjustManager = new AdjustManager();

            Adjust adjustInfo = new Adjust();

            adjustInfo.AdvanceId = entity.AdvanceId;

            var adjustExist = adjustManager.GetAll().Where(x => x.AdvanceId == adjustInfo.AdvanceId).LastOrDefault();



            var exist = Repository.GetById(entity.Id);


            if (exist != null)
            {
                entity.GrandTotal = exist.GrandTotal;
                entity.BillStatus = exist.BillStatus;
            }

            else
            {
                entity.BillStatus = "Not Confirmed";
            }


            Repository.SaveOrUpdate(entity);
            Repository.Done();

            if (adjustExist == null)
            {
                adjustInfo.AdvanceId = entity.AdvanceId;
                adjustInfo.BillingId = entity.Id;
                adjustInfo.BillTotal = entity.GrandTotal;
            }

            else
            {
                adjustInfo.Id        = adjustExist.Id;
                adjustInfo.AdvanceId = adjustExist.AdvanceId;
                adjustInfo.BillingId = adjustExist.BillingId;

                adjustInfo.BillTotal = adjustExist.BillTotal + entity.GrandTotal;
            }

            adjustManager.SaveOrUpdate(adjustInfo);
            Repository.Done();

            return(true);
        }
Example #34
0
        public CmsPageLockData lockPageForEditing(CmsPageLockData datatolock)
        {
            IRepository <CmsPageLockData> pagelockdatarepository = new Repository <CmsPageLockData>();
            CmsPageLockData insertedLockData = pagelockdatarepository.SaveOrUpdate(datatolock);

            if (insertedLockData.PageId > 0)
            {
                return(insertedLockData);
            }
            else
            {
                return(null);
            }
        }
        } // constructor

        public virtual bool SaveToDatabase()
        {
            IRepository <CmsPersistentVariable> repository = new Repository <CmsPersistentVariable>();
            CmsPersistentVariable returnPersistenVariable  = repository.SaveOrUpdate(this);

            if (returnPersistenVariable.Id > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        } // SaveToDatabase
        protected override void OnTestFixtureSetUp()
        {
            base.OnTestFixtureSetUp();

            foreach (CultureInfo culture in CultureInfo.GetCultures(CultureTypes.AllCultures))
            {
                if (culture.Name.IsNotWhiteSpace())
                {
                    Repository <Locale> .SaveOrUpdate(new Locale(culture));
                }
            }

            UnitOfWork.Current.TransactionalFlush();
        }
Example #37
0
        public void TestCreateEntity()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                Entity entity = new Entity()
                {
                    Name = "頁面"
                };

                Entity childEntity = new Entity()
                {
                    Name = "Section"
                };

                entity.ChildEntity.Add(childEntity);

                IRepository<Entity, Guid> repository = new Repository<Entity, Guid>(store);

                repository.SaveOrUpdate(entity);
                repository.SaveOrUpdate(childEntity);

                unitwork.SaveChanges();
            }
        }
     //   [TestMethod]
        public void TestAddRole()
        {
            

            // create the role

            _session.BeginTransaction();

            var roleRepo = new Repository<Role>(_session);

            var roleId = Guid.Parse("7C270960-0C16-4812-9CEF-275EA308A1AD");

            var role = new Role("TestRole " + roleId);

            role.Id = roleId;

            roleRepo.SaveOrUpdate(role);

            _session.Transaction.Commit();
          
          
        }
Example #39
0
        public void TestAddPartyToOrganization()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Organization, Guid> organRepository = new Repository<Organization, Guid>(store);
                IRepository<Party, Guid> partyRepository = new Repository<Party, Guid>(store);

                Organization org1 = new Organization()
                {
                    Name = "總經理室"
                };

                organRepository.SaveOrUpdate(org1);

                Party party1 = partyRepository.Query(q => q.Name == "總經理室主管").First();
                Party party2 = partyRepository.Query(q => q.Name == "總經理室副主管").First();
                org1.Parties.Add(party1);
                org1.Parties.Add(party2);

                unitwork.SaveChanges();

            }
        }
Example #40
0
        public void TestCreateParentOrgan()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Organization,Guid> organRepository = new Repository<Organization,Guid>(store);
                IRepository<OrganizationHierarchy,Guid> organHireRepository = new Repository<OrganizationHierarchy,Guid>(store);
                Organization organ1 = new Organization()
                {
                    Name = "總經理室"
                };

                Organization organ2 = new Organization()
                {
                    Name = "業務部"
                };

                Organization organ3 = new Organization()
                {
                    Name = "人資部"
                };

                Organization organ4 = new Organization()
                {
                    Name = "企畫課"
                };

                organRepository.SaveOrUpdate(organ1);
                organRepository.SaveOrUpdate(organ2);
                organRepository.SaveOrUpdate(organ3);
                organRepository.SaveOrUpdate(organ4);

                unitwork.SaveChanges();

                OrganizationService service = new OrganizationService(organHireRepository);
                service.AddOrganizationHierarchy(organ1, organ2, OrganizationHierarchyType.AM);
                unitwork.SaveChanges();
                service.AddOrganizationHierarchy(organ1, organ3, OrganizationHierarchyType.AM);
                unitwork.SaveChanges();
                service.AddOrganizationHierarchy(organ3, organ4,OrganizationHierarchyType.AM);
                unitwork.SaveChanges();

            }
        }
Example #41
0
        public void TestAddOperation()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Operation, Guid> operationRepository = new Repository<Operation, Guid>(store);
                Operation opr1 = new Operation() { Comment = "Full Control"};
                Operation opr2 = new Operation() { Comment = "Add" };
                Operation opr3 = new Operation() { Comment = "Update" };
                Operation opr4 = new Operation() { Comment = "Delete" };
                Operation opr5 = new Operation() { Comment = "Search" };
                Operation opr6 = new Operation() { Comment = "View" };

                operationRepository.SaveOrUpdate(opr1);
                operationRepository.SaveOrUpdate(opr2);
                operationRepository.SaveOrUpdate(opr3);
                operationRepository.SaveOrUpdate(opr4);
                operationRepository.SaveOrUpdate(opr5);
                operationRepository.SaveOrUpdate(opr6);

                opr1.Children.Add(opr2);
                opr1.Children.Add(opr3);
                opr1.Children.Add(opr4);
                opr1.Children.Add(opr5);
                opr1.Children.Add(opr6);

                unitwork.SaveChanges();
            }
        }
Example #42
0
        public void TestAddOrganization()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Organization, Guid> organRepository = new Repository<Organization, Guid>(store);
                IRepository<OrganizationHierarchy, Guid> organHireRepository = new Repository<OrganizationHierarchy, Guid>(store);

                Organization org1 = new Organization() { Name = "總經理室" };
                Organization org2 = new Organization() { Name = "人資部" };
                Organization org3 = new Organization() { Name = "業務部" };
                Organization org4 = new Organization() { Name = "企畫課" };
                Organization org5 = new Organization() { Name = "管理課" };
                Organization org6 = new Organization() { Name = "業務一課" };
                Organization org7 = new Organization() { Name = "業務二課" };
                Organization org8 = new Organization() { Name = "業務三課" };

                organRepository.SaveOrUpdate(org1);
                organRepository.SaveOrUpdate(org2);
                organRepository.SaveOrUpdate(org3);
                organRepository.SaveOrUpdate(org4);
                organRepository.SaveOrUpdate(org5);
                organRepository.SaveOrUpdate(org6);
                organRepository.SaveOrUpdate(org7);
                organRepository.SaveOrUpdate(org8);

                unitwork.SaveChanges();

                OrganizationService service = new OrganizationService(organHireRepository);
                service.AddOrganizationHierarchy(org1, org2, OrganizationHierarchyType.AM);
                unitwork.SaveChanges();
                service.AddOrganizationHierarchy(org1, org3, OrganizationHierarchyType.AM);
                unitwork.SaveChanges();
                service.AddOrganizationHierarchy(org2, org4, OrganizationHierarchyType.AM);
                unitwork.SaveChanges();
                service.AddOrganizationHierarchy(org2, org5, OrganizationHierarchyType.AM);
                unitwork.SaveChanges();
                service.AddOrganizationHierarchy(org3, org6, OrganizationHierarchyType.AM);
                unitwork.SaveChanges();
                service.AddOrganizationHierarchy(org3, org7, OrganizationHierarchyType.AM);
                unitwork.SaveChanges();
                service.AddOrganizationHierarchy(org3, org8, OrganizationHierarchyType.AM);
                unitwork.SaveChanges();
            }
        }
Example #43
0
        public void TestAddParty()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Post, Guid> postRepository = new Repository<Post, Guid>(store);
                IRepository<PartyHierarchy, Guid> partyHireRepository = new Repository<PartyHierarchy, Guid>(store);

                Post post1 = new Post() { Name = "總經理室主管" };
                Post post2 = new Post() { Name = "總經理室副主管" };
                Post post3 = new Post() { Name = "總經理室秘書" };
                Post post4 = new Post() { Name = "人資部主管" };
                Post post5 = new Post() { Name = "人資部副主管" };
                Post post6 = new Post() { Name = "企畫課主管" };
                Post post7 = new Post() { Name = "企畫課副主管" };
                Post post8 = new Post() { Name = "企畫課成員" };
                Post post9 = new Post() { Name = "管理課主管" };
                Post post10 = new Post() { Name = "管理課副主管" };
                Post post11 = new Post() { Name = "管理課成員" };
                Post post12 = new Post() { Name = "業務部主管" };
                Post post13 = new Post() { Name = "業務部副主管" };
                Post post14 = new Post() { Name = "業務一課主管" };
                Post post15 = new Post() { Name = "業務一課副主管" };
                Post post16 = new Post() { Name = "業務一課成員" };

                postRepository.SaveOrUpdate(post1);
                postRepository.SaveOrUpdate(post2);
                postRepository.SaveOrUpdate(post3);
                postRepository.SaveOrUpdate(post4);
                postRepository.SaveOrUpdate(post5);
                postRepository.SaveOrUpdate(post6);
                postRepository.SaveOrUpdate(post7);
                postRepository.SaveOrUpdate(post8);
                postRepository.SaveOrUpdate(post9);
                postRepository.SaveOrUpdate(post10);
                postRepository.SaveOrUpdate(post11);
                postRepository.SaveOrUpdate(post12);
                postRepository.SaveOrUpdate(post13);
                postRepository.SaveOrUpdate(post14);
                postRepository.SaveOrUpdate(post15);
                postRepository.SaveOrUpdate(post16);

                unitwork.SaveChanges();

                PartyService service = new PartyService(partyHireRepository);
                service.AddAccountability(post1, post2);
                unitwork.SaveChanges();
                service.AddAccountability(post1, post3);
                unitwork.SaveChanges();
                service.AddAccountability(post1, post4);
                unitwork.SaveChanges();
                service.AddAccountability(post1, post12);
                unitwork.SaveChanges();
                service.AddAccountability(post4, post5);
                unitwork.SaveChanges();
                service.AddAccountability(post4, post6);
                unitwork.SaveChanges();
                service.AddAccountability(post4, post9);
                unitwork.SaveChanges();
                service.AddAccountability(post6, post7);
                unitwork.SaveChanges();
                service.AddAccountability(post6, post8);
                unitwork.SaveChanges();
                service.AddAccountability(post9, post10);
                unitwork.SaveChanges();
                service.AddAccountability(post9, post11);
                unitwork.SaveChanges();
                service.AddAccountability(post12, post13);
                unitwork.SaveChanges();
                service.AddAccountability(post12, post14);
                unitwork.SaveChanges();
                service.AddAccountability(post14, post15);
                unitwork.SaveChanges();
                service.AddAccountability(post14, post16);
                unitwork.SaveChanges();
            }
        }
Example #44
0
        public void TestAddPermission()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Party,Guid> prtRepository = new Repository<Party,Guid>(store);
                IRepository<Organization,Guid> orgRepository = new Repository<Organization,Guid>(store);
                IRepository<Permission,Guid> perRepository = new Repository<Permission,Guid>(store);
                IRepository<Operation,Guid> oerRepository = new Repository<Operation,Guid>(store);
                IRepository<Entity,Guid> entRepository = new Repository<Entity,Guid>(store);

                //所有員工都可以看見Personal Information,且完全操作其功能
                Permission per1 = new Permission()
                {
                    Entity = entRepository.Query(q => q.Name == "Personal Information").First(),
                    Operation = oerRepository.Query(q => q.Comment == "Full Control").First(),
                    Level = 0
                };

                //人資部門可以看見Admin,Employees
                Permission per2 = new Permission()
                {
                    Organization = orgRepository.Query(q => q.Name == "人資部").First(),
                    Entity = entRepository.Query(q => q.Name == "Admin").First(),
                    Operation = oerRepository.Query(q => q.Comment == "View").First(),
                    Level = 0
                };

                Permission per3 = new Permission()
                {
                    Organization = orgRepository.Query(q => q.Name == "人資部").First(),
                    Entity = entRepository.Query(q => q.Name == "Employees").First(),
                    Operation = oerRepository.Query(q => q.Comment == "View").First(),
                    Level = 0
                };

                //企畫課員可以全權管理Admin下的技能設定,職稱設定,假期設定
                Permission per4 = new Permission()
                {
                    Party = prtRepository.Query(q => q.Name == "企畫課成員").First(),
                    Entity = entRepository.Query(q => q.Name == "Admin").First(),
                    Operation = oerRepository.Query(q => q.Comment == "Full Control").First(),
                    Level = 0
                };

                //企畫課長(副課長)可以全權管理Organization
                Permission per5 = new Permission()
                {
                    Party = prtRepository.Query(q => q.Name == "企畫課副主管").First(),
                    Entity = entRepository.Query(q => q.Name == "Organization").First(),
                    Operation = oerRepository.Query(q => q.Comment == "Full Control").First(),
                    Level = 0
                };

                //管理課對Admin下的所有功能只有View
                Permission per6 = new Permission()
                {
                    Organization = orgRepository.Query(q => q.Name == "管理課").First(),
                    Entity = entRepository.Query(q => q.Name == "Admin").First(),
                    Operation = oerRepository.Query(q => q.Comment == "View").First(),
                    Level = 0
                };

                //管理課對Admin下的所有功能只有View,下次要做檢查重複
                //Permission per7 = new Permission()
                //{
                //    Organization = orgRepository.Query(q => q.Name == "管理課").First(),
                //    Entity = entRepository.Query(q => q.Name == "Admin").First(),
                //    Operation = oerRepository.Query(q => q.Comment == "View").First(),
                //    Level = 0
                //};

                //管理課可以全權管理Employees下的基本資料,技能指定,組織設定
                Permission per8 = new Permission()
                {
                    Organization = orgRepository.Query(q => q.Name == "管理課").First(),
                    Entity = entRepository.Query(q => q.Name == "Employees").First(),
                    Operation = oerRepository.Query(q => q.Comment == "Full Control").First(),
                    Level = 0
                };

                //管理課長(副課長)可以查詢員工請假報表
                Permission per9 = new Permission()
                {
                    Party = prtRepository.Query(q => q.Name == "管理課副主管").First(),
                    Entity = entRepository.Query(q => q.Name == "員工請假報表").First(),
                    Operation = oerRepository.Query(q => q.Comment == "Full Control").First(),
                    Level = 0
                };

                //所以理論上管理課長對Report有View的權限
                Permission per10 = new Permission()
                {
                    Party = prtRepository.Query(q => q.Name == "管理課副主管").First(),
                    Entity = entRepository.Query(q => q.Name == "Reports").First(),
                    Operation = oerRepository.Query(q => q.Comment == "View").First(),
                    Level = 0
                };

                //企畫課對Employees下的所有功能只有View
                Permission per11 = new Permission()
                {
                    Organization = orgRepository.Query(q => q.Name == "企畫課").First(),
                    Entity = entRepository.Query(q => q.Name == "Employees").First(),
                    Operation = oerRepository.Query(q => q.Comment == "View").First(),
                    Level = 0
                };

                perRepository.SaveOrUpdate(per1);
                perRepository.SaveOrUpdate(per2);
                perRepository.SaveOrUpdate(per3);
                perRepository.SaveOrUpdate(per4);
                perRepository.SaveOrUpdate(per5);
                perRepository.SaveOrUpdate(per6);
                perRepository.SaveOrUpdate(per8);
                perRepository.SaveOrUpdate(per9);
                perRepository.SaveOrUpdate(per10);
                perRepository.SaveOrUpdate(per11);

                unitwork.SaveChanges();
            }
        }
Example #45
0
        public void TestAddEmployeeToPost()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Employee, Guid> empRepository = new Repository<Employee, Guid>(store);
                IRepository<Post, Guid> roleRepository = new Repository<Post, Guid>(store);
                IRepository<PartyHierarchy, Guid> partyHireRepository = new Repository<PartyHierarchy, Guid>(store);

                Employee prt1 = new Employee() { Name = "Allen" };
                Employee prt2 = new Employee() { Name = "Bob" };
                Employee prt3 = new Employee() { Name = "Cary" };
                Employee prt4 = new Employee() { Name = "David" };
                Employee prt5 = new Employee() { Name = "Edward" };
                Employee prt6 = new Employee() { Name = "Fred" };
                Employee prt7 = new Employee() { Name = "Gallon" };
                Employee prt8 = new Employee() { Name = "Hellen" };
                Employee prt9 = new Employee() { Name = "Ian" };
                Employee prt10 = new Employee() { Name = "Ivy" };
                Employee prt11 = new Employee() { Name = "Jay" };
                Employee prt12 = new Employee() { Name = "Kalad" };
                Employee prt13 = new Employee() { Name = "Larry" };
                Employee prt14 = new Employee() { Name = "Moppies" };
                Employee prt15 = new Employee() { Name = "Nana" };
                Employee prt16 = new Employee() { Name = "Outu" };

                empRepository.SaveOrUpdate(prt1);
                empRepository.SaveOrUpdate(prt2);
                empRepository.SaveOrUpdate(prt4);
                empRepository.SaveOrUpdate(prt5);
                empRepository.SaveOrUpdate(prt6);
                empRepository.SaveOrUpdate(prt7);
                empRepository.SaveOrUpdate(prt8);
                empRepository.SaveOrUpdate(prt9);
                empRepository.SaveOrUpdate(prt10);
                empRepository.SaveOrUpdate(prt11);
                empRepository.SaveOrUpdate(prt12);
                empRepository.SaveOrUpdate(prt13);
                empRepository.SaveOrUpdate(prt14);
                empRepository.SaveOrUpdate(prt15);
                empRepository.SaveOrUpdate(prt16);

                PartyService service = new PartyService(partyHireRepository);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "總經理室主管").First(), prt1);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "總經理室副主管").First(), prt2);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "總經理室秘書").First(), prt3);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "人資部主管").First(), prt4);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "人資部副主管").First(), prt5);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "企畫課主管").First(), prt6);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "企畫課副主管").First(), prt7);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "企畫課成員").First(), prt8);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "管理課主管").First(), prt9);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "管理課副主管").First(), prt10);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "管理課成員").First(), prt11);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "業務部主管").First(), prt12);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "業務部副主管").First(), prt13);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "業務一課主管").First(), prt14);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "業務一課副主管").First(), prt15);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "業務一課成員").First(), prt16);
                unitwork.SaveChanges();
            }
        }
Example #46
0
        public void TestAddEntity()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Entity, Guid> repository = new Repository<Entity, Guid>(store);
                Entity entity1 = new Entity() {Name = "Admin"};
                Entity entity2 = new Entity() {Name = "Employees"};
                Entity entity3 = new Entity() {Name = "Reports"};
                Entity entity4 = new Entity() {Name = "Personal Information"};
                Entity entity11 = new Entity() {Name = "Organization"};
                Entity entity12 = new Entity() {Name = "技能設定"};
                Entity entity13 = new Entity() {Name = "職稱設定"};
                Entity entity14 = new Entity() {Name = "假期設定"};
                Entity entity21 = new Entity() {Name = "基本資料"};
                Entity entity22 = new Entity() {Name = "組職設定"};
                Entity entity23 = new Entity() {Name = "技能指定"};
                Entity entity31 = new Entity() {Name = "員工請假報表"};
                Entity entity41 = new Entity() {Name = "基本資訊"};
                Entity entity42 = new Entity() {Name = "請假"};
                Entity entity43 = new Entity() {Name = "打卡資訊"};

                repository.SaveOrUpdate(entity1);
                repository.SaveOrUpdate(entity2);
                repository.SaveOrUpdate(entity3);
                repository.SaveOrUpdate(entity4);
                repository.SaveOrUpdate(entity11);
                repository.SaveOrUpdate(entity12);
                repository.SaveOrUpdate(entity13);
                repository.SaveOrUpdate(entity14);
                repository.SaveOrUpdate(entity21);
                repository.SaveOrUpdate(entity22);
                repository.SaveOrUpdate(entity23);
                repository.SaveOrUpdate(entity31);
                repository.SaveOrUpdate(entity41);
                repository.SaveOrUpdate(entity42);
                repository.SaveOrUpdate(entity43);

                entity1.ChildEntity.Add(entity11);
                entity1.ChildEntity.Add(entity11);
                entity1.ChildEntity.Add(entity12);
                entity1.ChildEntity.Add(entity13);
                entity1.ChildEntity.Add(entity14);
                entity2.ChildEntity.Add(entity21);
                entity2.ChildEntity.Add(entity22);
                entity2.ChildEntity.Add(entity23);
                entity3.ChildEntity.Add(entity31);
                entity4.ChildEntity.Add(entity41);
                entity4.ChildEntity.Add(entity42);
                entity4.ChildEntity.Add(entity43);

                unitwork.SaveChanges();
            }
        }
        public void should_persist_Audit_Role()
        {
            var auditRepo = new Repository<AuditLog>(Session);
           
            var roleId = Guid.Parse("7C270960-0C16-4812-9CEF-275EA308A1AD");

            // create the role

            Session.BeginTransaction();

            var roleRepo = new Repository<Role>(Session);

            var role = new Role("TestRole " + roleId) {Id = roleId};

            roleRepo.SaveOrUpdate(role);

            Session.Transaction.Commit();

            Session.Evict(role);

            // assert exists in the audit log

            var exists = auditRepo.Where(a => a.RecordId == roleId && a.CommitVersion.Value == 1 && a.EventType == "A" && a.EntityName == "Role");

            //Assert.True(exists.Any());

            // Update

            Session = null;
            Session = Container.Resolve<ISessionFactory>().OpenSession();

            // fine the role and modify the role

            Session.BeginTransaction();

            roleRepo = new Repository<Role>(Session);
            role = roleRepo.Get(roleId);

            role.UpdateValue("TestRoleX");
            Session.Transaction.Commit();

            Session.Evict(role);

            auditRepo = new Repository<AuditLog>(Session);

            exists = auditRepo.Where(a => a.RecordId == roleId && a.CommitVersion.Value == 2 && a.EventType == "M" && a.EntityName == "Role");

            //Assert.True(exists.Any());
            
            // delete
            
            Session = null;

            Session = Container.Resolve<ISessionFactory>().OpenSession();

            roleRepo = new Repository<Role>(Session);
            role = roleRepo.Get(roleId);
            
            Session.BeginTransaction();
            roleRepo.Delete(role);
            Session.Transaction.Commit();

            auditRepo = new Repository<AuditLog>(Session);

            exists = auditRepo.Where(a => a.RecordId == roleId && a.CommitVersion.Value == 3 && a.EventType == "D" && a.EntityName == "Role");
        }
 protected void InsertTestEntity(string name)
 {
     var testEntityRepository = new Repository<TestEntity>();
     var testEntity = new TestEntity
                          {
                              Name = name
                          };
     testEntityRepository.SaveOrUpdate(testEntity);
     NHibernateSession.Current.Evict(testEntity);
 }