Exemple #1
0
        public void AddToonOfDay(CartoonOfTheDay toonToAdd)
        {
            var repo = ToonOfDayFactory.CreateToonOfDayRepository();

            toonToAdd.WhenPosted = DateTime.Today;
            repo.AddToonOfDay(toonToAdd);
        }
Exemple #2
0
        public void addToonCheckTheDelete()
        {
            var repo = ToonOfDayFactory.CreateToonOfDayRepository();

            CartoonOfTheDay toon     = new CartoonOfTheDay();
            var             filename = "img.png";

            toon.ShowName         = "That show";
            toon.Season           = 1;
            toon.Episode          = 1;
            toon.DateCreated      = DateTime.Today;
            toon.Author           = "Derrek";
            toon.Approved         = Approved.Yes;
            toon.ImgUrl           = "" + filename;
            toon.WhenPosted       = DateTime.Today;
            toon.HasNotBeenPosted = false;

            repo.AddToonOfDay(toon);

            List <CartoonOfTheDay> toons = repo.GetAllToons();


            CartoonOfTheDay check = toons.Last();

            Assert.AreEqual("Derrek", check.Author);
            Assert.AreEqual("That show", check.ShowName);

            repo.RemoveToonOfDay(toon);

            // check that this toon is no longer in database
            Assert.IsNull(repo.GetPostByID(toon.Id));
        }
Exemple #3
0
        public List <CartoonOfTheDay> GetUnapprovedToons()
        {
            var repo = ToonOfDayFactory.CreateToonOfDayRepository();

            var allToons = repo.GetAllToons();

            var results = from p in allToons
                          where p.Approved == Approved.Waiting
                          select p;

            return(results.ToList());
        }
Exemple #4
0
        public CartoonOfTheDay ChooseCartoon()
        {
            var repo  = ToonOfDayFactory.CreateToonOfDayRepository();
            var toons = repo.GetAllToons();

            var result = from t in toons
                         where t.Approved == Approved.Yes && t.WhenPosted <= DateTime.Now.AddDays(-1)
                         select t;

            var theToon = result.OrderBy(t => t.DateCreated).FirstOrDefault();

            if (theToon == null)
            {
                var getNewUnposted = from t in toons
                                     where t.Approved == Approved.Yes && t.HasNotBeenPosted
                                     select t;

                Random rnd   = new Random();
                var    rlist = getNewUnposted.ToList();

                if (rlist.Any())
                {
                    int r = rnd.Next(rlist.Count);

                    return(rlist[r]);
                }
            }


            if (theToon == null)
            {
                var recycle = from t in toons
                              where t.Approved == Approved.Yes && t.HasNotBeenPosted == false
                              select t;

                Random rnd   = new Random();
                var    rlist = recycle.ToList();

                int r = rnd.Next(rlist.Count);

                return(rlist[r]);
            }
            return(theToon);
        }
Exemple #5
0
        //}
        public CartoonOfTheDay GetCartoonOfTheDay(int id)
        {
            //ToonOfDayResponse response = new ToonOfDayResponse();

            var repo = ToonOfDayFactory.CreateToonOfDayRepository();

            return(repo.GetPostByID(id));

            //if (toon != null)
            //{
            //    response.Success = true;
            //    response.Message = "It worked!";
            //    response.ToonOfTheDay = toon;
            //}
            //else
            //{
            //    response.Success = false;
            //    response.Message = "Not Found!";
            //}
            //return toon;
        }
Exemple #6
0
        public void EditToonOfDay(CartoonOfTheDay toonToEdit)
        {
            var repo = ToonOfDayFactory.CreateToonOfDayRepository();

            repo.EditToonOfDay(toonToEdit);
        }
Exemple #7
0
        public void RemoveToonOfDay(CartoonOfTheDay toonToRemove)
        {
            var repo = ToonOfDayFactory.CreateToonOfDayRepository();

            repo.RemoveToonOfDay(toonToRemove);
        }
Exemple #8
0
        public List <CartoonOfTheDay> GetAllToons()
        {
            var repo = ToonOfDayFactory.CreateToonOfDayRepository();

            return(repo.GetAllToons());
        }