public IActionResult FavoriteMovies(int id)
        {
            var                  favMovies      = _context.Favorites.Where(i => i.GroupMembersID == id).ToList();
            var                  filteredMovies = new List <SavedMovies>();
            List <string>        apiValList     = new List <string>();
            List <int>           favIdList      = new List <int>();
            List <MovieApiModel> apiItemList    = new List <MovieApiModel>();

            for (int x = 0; x < favMovies.Count; x++)
            {
                favIdList.Insert(x, favMovies[x].MovieFavoritesID);
            }
            for (int x = 0; x < favMovies.Count; x++)
            {
                var tempMovies = _context.Movies.Where(i => i.SavedMoviesID == favMovies[x].SavedMoviesID);
                foreach (SavedMovies t in tempMovies)
                {
                    filteredMovies.Insert(x, t);
                }
            }
            for (int x = 0; x < filteredMovies.Count; x++)
            {
                string apiIdVal = filteredMovies[x].APIReferenceID.ToString();
                apiValList.Insert(x, apiIdVal);
            }
            for (int x = 0; x < apiValList.Count; x++)
            {
                MovieApiModel movie = new MovieApiModel();
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(UriString);
                    var responseTask = client.GetAsync(apiValList[x] + "?api_key=" + apiKey);
                    responseTask.Wait();

                    var result = responseTask.Result;
                    if (result.IsSuccessStatusCode)
                    {
                        var readTask = result.Content.ReadAsAsync <MovieApiModel>();
                        readTask.Wait();

                        movie = readTask.Result;
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, "Server error. Please contact admin.");
                    }
                    apiItemList.Insert(x, movie);
                }
            }
            var model = new HobbyViewModel
            {
                MoviesList     = filteredMovies,
                ApiContentList = apiItemList
            };

            ViewBag.Title = "My Movies List";
            return(View(model));
        }
        public void Create(HobbyViewModel hobbyVM)
        {
            var Hobby = new Hobby
            {
                HobbyName = hobbyVM.HobbyName
            };

            unitOfWork.HobbyRepository.Insert(Hobby);
            unitOfWork.Save();
        }
        public void Update(HobbyViewModel hobbyVM)
        {
            var Hobby = new Hobby
            {
                HobbyId   = hobbyVM.HobbyId,
                HobbyName = hobbyVM.HobbyName
            };

            unitOfWork.HobbyRepository.Update(Hobby);
            unitOfWork.Save();
        }
Beispiel #4
0
        public async Task <IActionResult> Create(HobbyViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var result = await _services.CreateAsync(_mapper.Map <DirectoryDTO>(vm));

                return(result.IsValid
                    ? RedirectToAction("Index")
                    : _oops.OutPutError("Hobby", "Index", result.ErrorsList));
            }
            return(View(vm));
        }
Beispiel #5
0
        public ApplicationResult AddNewHobby(HobbyViewModel model, string userId)
        {
            var user = _userRepository.GetById(userId);

            if (user == null)
            {
                return(ApplicationResult.Fail("User does not exist"));
            }
            model.UserId = userId;
            var device = _hobbyRepository.Insert(Mapper.Map <Hobby>(model));

            return(ApplicationResult.Ok(Mapper.Map <HobbyViewModel>(device)));
        }
        // GET: Hobby/Details/5
        public ActionResult Details(int id = 0)
        {
            if (id == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            HobbyViewModel details = hobbyService.GetById(id);

            if (details == null)
            {
                return(HttpNotFound());
            }
            return(View(details));
        }
        public IActionResult About(int id)
        {
            var members   = _context.Members.ToList();
            var movies    = _context.Movies.OrderBy(n => n.MovieName).ToList();
            var favorites = _context.Favorites.Where(r => r.Rating == 5).ToList();
            var model     = new HobbyViewModel
            {
                TeamList            = members,
                FavoritesCollection = favorites,
                MoviesList          = movies,
                MemID = id
            };

            ViewBag.Title = "About Me";
            return(View(model));
        }
Beispiel #8
0
        public async Task <IActionResult> UpdateConfirmed(HobbyViewModel vm)
        {
            if (ModelState.IsValid)
            {
                if (vm.HashId == null)
                {
                    return(NotFound());
                }
                var result = await _services.UpdateAsync(_mapper.Map <DirectoryDTO>(vm));

                return(result.IsValid
                    ? RedirectToAction("Index")
                    : _oops.OutPutError("Hobby", "Index", result.ErrorsList));
            }
            return(View(vm));
        }
Beispiel #9
0
        public IActionResult ViewAll()
        {
            var allMovies = _context.Movies
                            .OrderBy(m => m.MovieName).ToList();
            List <string>        apiValList  = new List <string>();
            List <MovieApiModel> apiItemList = new List <MovieApiModel>();

            for (int x = 0; x < allMovies.Count; x++)
            {
                string apiIdVal = allMovies[x].APIReferenceID.ToString();
                apiValList.Insert(x, apiIdVal);
            }
            for (int x = 0; x < apiValList.Count; x++)
            {
                MovieApiModel movie = new MovieApiModel();
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(UriString);
                    var responseTask = client.GetAsync(apiValList[x] + "?api_key=" + apiKey);
                    responseTask.Wait();

                    var result = responseTask.Result;
                    if (result.IsSuccessStatusCode)
                    {
                        var readTask = result.Content.ReadAsAsync <MovieApiModel>();
                        readTask.Wait();

                        movie = readTask.Result;
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, "Server error. Please contact admin.");
                    }
                    apiItemList.Insert(x, movie);
                }
            }
            var model = new HobbyViewModel
            {
                MoviesList     = allMovies,
                ApiContentList = apiItemList
            };

            ViewBag.Title = "All Movies";
            return(View(model));
        }
        public ActionResult Edit(HobbyViewModel hobbyVM)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    // TODO: Add update logic here

                    hobbyService.Update(hobbyVM);
                    return(RedirectToAction("Index"));
                }
                catch
                {
                    return(View());
                }
            }
            return(View());
        }
        public ActionResult Create(HobbyViewModel hobbyVM)
        {
            try
            {
                // TODO: Add insert logic here
                if (ModelState.IsValid)
                {
                    hobbyService.Create(hobbyVM);
                }


                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult Index(int?id)
        {
            HobbyViewModel model = new HobbyViewModel();

            if (id.HasValue)
            {
                int realid = id.Value;
                model.currentUser               = accountService.getUserByName(User.Identity.Name);
                model.currentHobby              = hobbyService.getHobbyByID(realid);
                model.currentHobbyGroups        = hobbyService.getGroupsByHobby(model.currentHobby);
                model.currentHobbyStatusHistory = statusService.getStatusesByHobby(model.currentHobby);
                model.currentHobbyUsers         = hobbyService.getUsersByHobby(model.currentHobby);

                return(View(model));
            }
            else
            {
                return(View("Error"));
            }
        }
Beispiel #13
0
        public ActionResult Hobbies()
        {
            var hobbies = new HobbiesViewModel(MenuType.Hobbies, Request.IsAuthenticated, HttpContext.User);

            var hobby0 = new HobbyViewModel
            {
                HobbyId = 0,
                Picture = "Hobby/Coding/Coding-logo.png",
                Titile  = "Coding"
            };

            var hobby1 = new HobbyViewModel
            {
                HobbyId = 1,
                Picture = "Hobby/Acrobatics/Acro-logo.jpg",
                Titile  = "Acrobatics"
            };

            var hobby2 = new HobbyViewModel
            {
                HobbyId = 2,
                Picture = "Hobby/Outdoor/Outdoor-logo.jpeg",
                Titile  = "Outdoor Activities"
            };

            var hobby3 = new HobbyViewModel
            {
                HobbyId = 3,
                Picture = "Hobby/Snowboarding/Snowboard-logo.jpg",
                Titile  = "Snowboarding"
            };

            hobbies.Hobbies.Add(hobby0);
            hobbies.Hobbies.Add(hobby1);
            hobbies.Hobbies.Add(hobby2);
            hobbies.Hobbies.Add(hobby3);

            return(View(hobbies));
        }
Beispiel #14
0
 public IActionResult AddNewHobby(HobbyViewModel model)
 {
     return(Result(() => _hobbyService.AddNewHobby(model, CurrentUser.Id)));
 }