Пример #1
0
        public void TestAll()
        {
            using (MemberRepository memberRepository = new MemberRepository())
            {
                var member = memberRepository.CreateNew();
                member.Title    = "Test Member";
                member.UserName = "******";
                member.Password = "******";
                member.Email    = "*****@*****.**";
                memberRepository.Save();
            }

            using (MemberRepository memberRepository = new MemberRepository())
            {
                var members = memberRepository.GetAll(query => query.CreateDate >= DateTime.Today).ToList();

                foreach (var member in members)
                {
                    member.Title += " Lastname";
                }

                memberRepository.Save();
            }

            using (MemberRepository memberRepository = new MemberRepository())
            {
                var member = memberRepository.GetById(new Guid("4D33AB34-5C5C-4A03-AF18-5C5FE6FC121A"));
                member.Title = "Selected Member";
                memberRepository.Save();
            }

            using (MemberRepository memberRepository = new MemberRepository())
            {
                var member = memberRepository.GetSingle(query => query.Title == "Selected Member");
                member.Title = "Selected Member 2";
                memberRepository.Save();
            }

            using (MemberRepository memberRepository = new MemberRepository())
            {
                memberRepository.Delete(query => query.Title == "Selected Member 2");
                memberRepository.Save();
            }

            using (MemberRepository memberRepository = new MemberRepository())
            {
                var  member = memberRepository.CreateNew();
                bool isNew  = memberRepository.IsNew(member);
            }
        }
Пример #2
0
        public void TestAll()
        {
            string createdId = string.Empty;

            //New Entity
            using (MemberRepository memberRepository = new MemberRepository())
            {
                var member = memberRepository.CreateNew();

                member.MemberId = Guid.NewGuid().ToString();
                member.Title    = "Test Member";
                member.UserName = "******";
                member.Password = "******";
                member.Email    = "*****@*****.**";
                memberRepository.Save();

                createdId = member.Id;
            }

            //Update Multiple Entity
            using (MemberRepository memberRepository = new MemberRepository())
            {
                var members = memberRepository.GetAll("member*");

                foreach (var member in members)
                {
                    member.Title += " Lastname";
                }

                memberRepository.Save();
            }

            //Update Single Entity
            using (MemberRepository memberRepository = new MemberRepository())
            {
                var member = memberRepository.GetById(createdId);

                if (member != null)
                {
                    member.Title = "Selected Member";
                    memberRepository.Save(expiration: TimeSpan.FromDays(2)); //overwrite expiration during save if you like otherwise it uses repository expiration value.
                }
            }

            //IsNew
            using (MemberRepository memberRepository = new MemberRepository())
            {
                var member = memberRepository.CreateNew();
                Console.WriteLine("Is my entity new? Answer: " + memberRepository.IsNew(member));
            }


            //Has Changes
            using (MemberRepository memberRepository = new MemberRepository())
            {
                var member = memberRepository.GetById(createdId);

                if (member != null)
                {
                    member.Title += " and again changed";
                    Console.WriteLine("Has my entity changed? Answer: " + memberRepository.HasChanges(member));
                }
            }

            //Delete Entity
            using (MemberRepository memberRepository = new MemberRepository())
            {
                memberRepository.Delete(createdId);
            }

            //Pub Sub. Use this only when you enable keyspace on Redis. Sample cli code: config set notify-keyspace-events KEA
            //using (MemberRepository memberRepository = new MemberRepository())
            //{
            //    memberRepository.SubscriptionTriggered += MemberRepository_SubscriptionTriggered;
            //}
        }