[HttpPost] // patch for shared server compatibility, usually would use [HttpPut]
        public JsonNetResult UpdatePageWidget(PageWidgetModel model)
        {
            PageWidget widget = Mapper.Map <PageWidget>(model);

            _pageWidgetRepository.Update(widget);
            Mapper.Map(widget, model);

            return(new JsonNetResult(model));
        }
Exemple #2
0
        public static void Test(IKeyedRepository <TKey, TEntity> repo, List <string> protectedPropertyNames, TEntity seed)
        {
            // Get the inital count
            int countBefore = repo.All().Count();

            // Look for the seed.Id item in the DB; if found, refresh up to 5 times then error.
            int loopCount = 0;

            while (true)
            {
                var item = repo.FindBy(seed.Id);
                if (item == null)
                {
                    break;
                }
                if (loopCount > 4)
                {
                    Assert.Fail("Can't find a unique new key for: " + repo.GetType().Name);
                    return;
                }
                seed = Random <TEntity> .UpdateSpecifiedProperties(seed, new List <string> {
                    "Id"
                });

                loopCount += 1;
            }


            // add
            repo.Insert(seed);
            int countAfter = repo.All().Count();

            Assert.IsTrue(countBefore + 1 == countAfter);


            // read
            TEntity entity2 = repo.FindBy(seed.Id);

            //Assert.IsTrue(seed.Equals(entity2));
            Assert.IsTrue(Comparison.PublicInstancePropertiesEqual(seed, entity2, protectedPropertyNames));

            // update
            protectedPropertyNames.Add("Id");             // Make sure Id is now in the list.
            seed = Random <TEntity> .Update(seed, protectedPropertyNames);

            repo.Update(seed);
            TEntity entity3 = repo.FindBy(seed.Id);

            Assert.IsFalse(Comparison.PublicInstancePropertiesEqual(entity2, seed, protectedPropertyNames));
            Assert.IsTrue(Comparison.PublicInstancePropertiesEqual(entity3, seed, protectedPropertyNames));

            // delete
            repo.Delete(seed.Id);
            countAfter = repo.All().Count();
            Assert.IsTrue(countAfter == countBefore);
        }
Exemple #3
0
        public void Update_Returns_False_If_Does_Not_Exist_And_Does_Not_Modify_List()
        {
            using (IDbSession dbSession = _dbSessionFactory.Create())
            {
                IKeyedRepository <Guid, Person> repo = dbSession.CreateKeyedRepository <Guid, Person>();

                int    countBefore  = repo.All().Count();
                Person doesNotExist = new Person {
                    FirstName = "Julio", LastName = "Gonzalas"
                };
                Assert.IsFalse(repo.Update(doesNotExist));
                Assert.IsTrue(repo.All().Count() == countBefore);

                dbSession.Commit();
            }
        }
Exemple #4
0
        public void Update_Returns_True_And_Modifies_Exising()
        {
            using (IDbSession dbSession = _dbSessionFactory.Create())
            {
                IKeyedRepository <Guid, Person> repo = dbSession.CreateKeyedRepository <Guid, Person>();

                int    countBefore    = repo.All().Count();
                Person person1Updated = repo.FindBy(_persons[0].Id);
                person1Updated.LastName = Guid.NewGuid().ToString();
                Assert.IsTrue(repo.Update(person1Updated));
                Assert.AreNotEqual(person1Updated, _persons[0]);
                Assert.IsTrue(repo.All().Count() == countBefore);

                dbSession.Commit();
            }
        }