Exemplo n.º 1
0
        public ActionResult RemoveFromFavourite(string charId)
        {
            try
            {
                string userName = User.Identity.Name;

                if (db.tblUserFavouriteCharacters.Any(x => x.UserName.Equals(userName) && x.FavCharId.ToString() == charId))
                {
                    db.tblUserFavouriteCharacters.Remove(db.tblUserFavouriteCharacters.Where(x => x.UserName.Equals(userName) && x.FavCharId.ToString() == charId).First());
                    db.SaveChanges();
                }
                List <ComicCharacter> myFavChars = new List <ComicCharacter>();

                List <int> myFavCharDBEntries = db.tblUserFavouriteCharacters.Where(x => x.UserName.Equals(User.Identity.Name)).Select(x => x.FavCharId).ToList();

                foreach (var item in myFavCharDBEntries)
                {
                    ComicCharacter comicChar = SuperheroAPIHandler.GetCharacterById(item.ToString());
                    if (comicChar != null)
                    {
                        myFavChars.Add(comicChar);
                    }
                }
                ViewData["FromUserFavouriteCharacters"] = true;
                return(View("UserFavouriteCharacters", myFavChars));
            }
            catch (Exception)
            {
                return(Json(new { Result = false }));
            }
        }
Exemplo n.º 2
0
        public ActionResult Index()
        {
            List <ComicCharacter> comicChars = new List <ComicCharacter>();

            foreach (var item in SuperheroAPIHandler.FavouriteCharacters.Take(4))
            {
                var character = SuperheroAPIHandler.GetCharacterById(item.ToString());
                if (character != null)
                {
                    comicChars.Add(character);
                }
            }
            return(View(comicChars));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get User Favourite Characters
        /// </summary>
        /// <returns></returns>
        public ActionResult UserFavouriteCharacters()
        {
            List <ComicCharacter> myFavChars = new List <ComicCharacter>();

            List <int> myFavCharDBEntries = db.tblUserFavouriteCharacters.Where(x => x.UserName.Equals(User.Identity.Name)).Select(x => x.FavCharId).ToList();

            foreach (var charId in myFavCharDBEntries)
            {
                ComicCharacter comicChar = SuperheroAPIHandler.GetCharacterById(charId.ToString());
                if (comicChar != null)
                {
                    myFavChars.Add(comicChar);
                }
            }
            ViewData["FromUserFavouriteCharacters"] = true;
            return(View(myFavChars));
        }
Exemplo n.º 4
0
        public JsonResult LoadNextRandomCharactersToCarousel(int offset, int size)
        {
            List <ComicCharacter> comicChars = new List <ComicCharacter>();
            Random rnd = new Random();

            int[] generatedRandomCharIds = SuperheroAPIHandler.FavouriteCharacters.Skip(offset).Take(size).ToArray();
            foreach (var ComicChar in generatedRandomCharIds)
            {
                ComicCharacter comicChar = SuperheroAPIHandler.GetCharacterById(ComicChar.ToString());
                if (comicChar != null)
                {
                    comicChars.Add(comicChar);
                }
            }
            if (comicChars.Any())
            {
                string modelString = RenderRazorViewToString("_CarouselRandomChars", comicChars);
                return(Json(new { ModelString = modelString, ModelCount = SuperheroAPIHandler.FavouriteCharacters.Count() }));
            }
            return(Json(comicChars));
        }
Exemplo n.º 5
0
 /// <summary>
 /// Display character details on page
 /// </summary>
 /// <param name="charId"></param>
 /// <returns></returns>
 public ActionResult CharacterDetails(string charId)
 {
     return(View(SuperheroAPIHandler.GetCharacterById(charId)));
 }