/// <summary> /// Displays a details page for request, different view depending on the type of media /// </summary> /// <param name="id">The id of the request</param> /// <returns></returns> public ActionResult Details(int?id) { if (id.HasValue) { var model = _unitOfWork.RequestRepository.Get() .Where(r => r.ID == id) .SingleOrDefault(); if (model != null) { string type = model.Media.GetType().BaseType.Name; switch (type) { case "Movie": return(View("MovieRequestDetails", model)); case "Show": ShowRequestViewModel showModel = new ShowRequestViewModel(); showModel.Request = model; var myShow = _unitOfWork.ShowRepository.GetByID(model.MediaID); showModel.Show = myShow; return(View("ShowRequestDetails", showModel)); case "Clip": return(View("ClipRequestDetails", model)); default: throw new ApplicationException(); } } throw new DataNotFoundException(); } throw new MissingParameterException(); }
public ActionResult CreateShow(ShowRequestViewModel showRequest) { if (ModelState.IsValid) { var show = showRequest.Show; Translation translation; Request req = null; // Check if the show the user is trying to create a request for already exists. var showToCheckFor = _unitOfWork.ShowRepository.Get() .Where(s => s.Title == show.Title) .Where(s => s.ReleaseYear == show.ReleaseYear) .Where(s => s.Series == show.Series) .Where(s => s.Episode == show.Episode) .SingleOrDefault(); // If the show doesn't exists, insert the show and request to the database. if (showToCheckFor == null) { _unitOfWork.ShowRepository.Insert(showRequest.Show); _unitOfWork.RequestRepository.Insert(showRequest.Request); _unitOfWork.Save(); TempData["UserMessage"] = "Beiðnin var stofnuð"; return(RedirectToAction("Index", "Request")); } // If the show exists we need to check if it already has the translation or the request else if ((translation = _unitOfWork.TranslationRepository.Get() .Where(t => t.MediaID == showToCheckFor.ID) .Where(t => t.LanguageID == showRequest.Request.LanguageID) .SingleOrDefault()) == null && (req = _unitOfWork.RequestRepository.Get() .Where(r => r.MediaID == showToCheckFor.ID) .Where(r => r.LanguageID == showRequest.Request.LanguageID) .SingleOrDefault()) == null) { // If not we insert the request. showRequest.Request.MediaID = showToCheckFor.ID; _unitOfWork.RequestRepository.Insert(showRequest.Request); _unitOfWork.Save(); TempData["UserMessage"] = "Beiðnin var stofnuð"; return(RedirectToAction("Index", "Request")); } showRequest.Show = showToCheckFor; if (req != null) { ViewBag.Errormsg = "Þessi beiðni er nú þegar til."; ViewBag.ReqExist = true; } else { ViewBag.Errormsg = "Þessi þýðing er nú þegar til."; ViewBag.ReqExist = false; ViewBag.TranslationID = translation.ID; } } ViewBag.SubCategories = new SelectList(_unitOfWork.CategoryRepository.Get(), "ID", "Name", showRequest.Show.CategoryID); ViewBag.Languages = new SelectList(_unitOfWork.LanguageRepository.Get(), "ID", "Name"); return(View("RequestShow")); }