public ActionResult Edit(int id) { SerieContext SC = new SerieContext(); var theSerie = SC.Serie.ToList().Where(s => s.SerieId == id).First(); return(View(theSerie)); }
List <Serie> CallesMetod(List <GenreType> genres) { var animated = Request["Animated"]; var action = Request["Action"]; var fantasy = Request["Fantasy"]; var db = new SerieContext(); var series = new List <Serie>(); foreach (var serie in db.Serie.ToList()) { foreach (var genre in genres) { if (serie.Genres.Any(g => g.Genre == genre)) { if (!series.Any(s => s.SerieId == serie.SerieId)) { series.Add(serie); } } } } return(series); }
// GET: Library public ActionResult Index() { SerieContext SC = new SerieContext(); List <Serie> List = SC.Serie.ToList(); return(View(List)); }
public ActionResult Create(Serie S) { SerieContext SC = new SerieContext(); SC.Serie.Add(S); SC.SaveChanges(); return(RedirectToAction("SearchResult")); }
// GET: MovieProfile public ActionResult Index(int?id) { SerieContext SC = new SerieContext(); if (id != null) { var Serie = SC.Serie.Where(s => s.SerieId == id).First(); return(View(Serie)); } return(View(SC.Serie.First())); }
// GET: UserProfile public ActionResult Index() { string userName = (string)Session["CurrentUser"]; User user = new User(); if (userName != "John Doe") { SerieContext context = new SerieContext(); user = context.Users.Where(u => u.Username == userName).First(); } return(View(user)); }
private IList <Serie> ImgListAdded(IList <Serie> List, SerieContext SC) { //Om Listan är skild från 0 eller null lägg till bilderna if (!(List.Count == 0) || (List == null)) { foreach (var item in List) { item.SerieImgsURL = (from x in item.SerieImgsURL where x.SerieId == item.SerieId select x).ToList(); } //List = SC.Serie.ToList(); } return(List); }
public ActionResult EditDetails() { SerieContext context = new SerieContext(); string sessionUsername = (string)Session["CurrentUser"]; User currentUser = context.Users.ToList().Where(u => u.Username == sessionUsername).First(); string tmpUsername = Request["username"]; string tmpLocation = Request["location"]; string tmpAge = Request["birthday"]; int age = 0; string tmpEmail = Request["email"]; if (!string.IsNullOrWhiteSpace(tmpUsername)) { if (!context.Users.Any(u => u.Username == tmpUsername)) { currentUser.Username = tmpUsername; Session["CurrentUser"] = tmpUsername; } } if (!string.IsNullOrWhiteSpace(tmpLocation)) { currentUser.Country = tmpLocation; } if (!string.IsNullOrWhiteSpace(tmpAge) && int.TryParse(tmpAge, out age)) { currentUser.Age = age; } if (!string.IsNullOrWhiteSpace(tmpEmail)) { currentUser.Email = tmpEmail; } context.SaveChanges(); return(RedirectToAction("/Index")); }
public ActionResult Delete(int id) { SerieContext SC = new SerieContext(); Serie theSerie; if (Request["Radera"] == null) { theSerie = SC.Serie.ToList().Where(s => s.SerieId == id).First(); return(View(theSerie)); } else { int number = int.Parse(Request["Radera"]); theSerie = SC.Serie.ToList().Where(s => s.SerieId == number).First(); SC.Serie.Remove(theSerie); SC.SaveChanges(); return(View("SearchResult", SC.Serie.ToList())); } }
public ActionResult Edit(Serie S) { SerieContext SC = new SerieContext(); foreach (var item in SC.Serie) { if (item.SerieId == S.SerieId) { item.Name = S.Name; item.NumberOfVotes = S.NumberOfVotes; item.ReleaseDatum = S.ReleaseDatum; item.Creator = S.Creator; item.Description = S.Description; item.AverageGrade = S.AverageGrade; } } SC.SaveChanges(); return(View("SearchResult", SC.Serie.ToList())); }
public ActionResult Login() { SerieContext context = new SerieContext(); List <User> listOfUsers = new List <User>(); string tmpUsername = Request["Username"]; string tmpPassword = Request["Password"]; bool canLogIn = false; if (context.Users.Count() > 0) { foreach (var user in context.Users.AsEnumerable()) { if (tmpUsername.ToLower() == user.Username.ToLower()) { if (tmpPassword == user.Password) { tmpUsername = user.Username; canLogIn = true; break; } } } } if (canLogIn) { Session["UserLoggedIn"] = true; Session["CurrentUser"] = tmpUsername; } else { Redirect("/User/WrongLogin"); } return(Redirect("/Home/Index")); }
// GET: Search public ActionResult SearchResult() { #region Setting Up Parameters IList <Serie> ResultList = new List <Serie>(); string textstring = Request["Search"]; DateTime From; DateTime.TryParse(Request["From"], out From); DateTime To; DateTime.TryParse(Request["To"], out To); double Grade; if (Request["Grade"] != null) { var culture = CultureInfo.InvariantCulture; Grade = double.Parse(Request["Grade"], culture); } else { Grade = 0; } List <int> Genres = new List <int>(); Genres = AddGenres(Genres); List <GenreType> gg = GetGenres(Genres); #endregion using (SerieContext SC = new SerieContext()) { //ResultList = SeriesBasedOnGenre(gg, SC); ResultList = CallesMetod(gg); ResultList = SeriesSelectedBasedOnRelease(ResultList, From, To, SC); ResultList = SeriesSelectedBasedOnGrade(ResultList, Grade, SC); ResultList = SeriesSelectedBasedOnTextString(ResultList, textstring, SC); ResultList = ImgListAdded(ResultList, SC); } return(View(ResultList)); }
private IList <Serie> SeriesSelectedBasedOnGrade(IList <Serie> List, double v, SerieContext SC) { IList <Serie> newList; if ((List.Count == 0) || (List == null)) { List = SC.Serie.ToList(); } newList = (from x in List where x.AverageGrade >= v select x).ToList(); return(newList); }
public ActionResult Register() { SerieContext context = new SerieContext(); List <User> users = new List <User>(); string tmpUsername = Request["usernameInput"]; string tmpEmail = Request["emailInput"]; int tmpAge; int.TryParse(Request["ageInput"], out tmpAge); string tmpPassword = Request["passwordInput"]; DateTime tmpBirthday = DateTime.Parse(Request["birthdayInput"]); string tmpPasswordRetype = Request["passwordInputRetype"]; string checkChars = "^([0-9a-zA-Z]([-\\.\\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{2,9})$"; if (string.IsNullOrWhiteSpace(tmpUsername) || string.IsNullOrWhiteSpace(tmpEmail) || string.IsNullOrWhiteSpace(tmpPassword)) { return(Redirect("/User/FieldIsEmpty")); } if (context.Users.Count() > 0) { foreach (var user in context.Users.AsEnumerable()) { users.Add(user); } } if (tmpPassword != tmpPasswordRetype) { return(Redirect("/User/PasswordNotMatch")); } foreach (var user in users.AsEnumerable()) { if (tmpUsername.ToLower() == user.Username.ToLower()) { return(Redirect("/User/UsernameExists")); } if (tmpEmail.ToLower() == user.Email.ToLower()) { return(Redirect("/User/EmailExists")); } } if (tmpUsername.Trim().Length < 3) { return(Redirect("User/UsernameTooShort")); } else if (tmpPassword.Trim().Length < 6) { return(Redirect("User/PasswordTooShort")); } try { var addr = new MailAddress(tmpEmail); } catch { return(Redirect("/User/EmailNotValid")); } if (!Regex.IsMatch(tmpEmail, checkChars)) { return(Redirect("/User/EmailNotValid")); } if (tmpBirthday > DateTime.Now) { return(Redirect("/User/NotBornYet")); } if (tmpUsername.Trim().Length >= 3 && tmpPassword.Trim().Length >= 6) { DateTime zeroTime = new DateTime(1, 1, 1); DateTime a = tmpBirthday; DateTime b = DateTime.Now; TimeSpan span = b - a; // because we start at year 1 for the Gregorian // calendar, we must subtract a year here. int years = (zeroTime + span).Year - 1; User userToAdd = new User(tmpUsername, tmpPassword, tmpEmail, years); Session["UserLoggedIn"] = true; Session["CurrentUser"] = tmpUsername; context.Users.Add(userToAdd); context.SaveChanges(); return(Redirect("/User/RegisterSuccess")); } return(Redirect("/User/RegisterError")); }
protected override void Seed(KBC.Models.SerieContext context) { // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. E.g. // // context.People.AddOrUpdate( // p => p.FullName, // new Person { FullName = "Andrew Peters" }, // new Person { FullName = "Brice Lambson" }, // new Person { FullName = "Rowan Miller" } // ); // //for (int i = 0; i < 8; i++) //{ // context.Genre.AddOrUpdate(new Genre() { GenreType = (GenreCollection)i, SerieIds = null, Serie = null }); //} context.Serie.AddOrUpdate( new Serie() { Name = "Game of Thrones", ReleaseDatum = new DateTime(2008, 3, 13, 8, 0, 0), AverageGrade = 5, NumberOfVotes = 100, Creator = "Jag", Description = "While a civil war brews between several noble families in Westeros," + "the children of the former rulers of the land attempt to rise up to power." + "Meanwhile a forgotten race, bent on destruction, return after thousands of years in the North." }, new Serie() { Name = "How I met your mother", ReleaseDatum = new DateTime(2005, 5, 24, 8, 0, 0), AverageGrade = 5, NumberOfVotes = 100, Creator = "Jag", Description = "How I Met Your Mother is a comedy about Ted (Josh Radnor) " + "and how he fell in love. It all starts when Ted's best friend, Marshall " + "(Jason Segel), drops the bombshell that he's going to propose to his long-time " + "girlfriend, Lily (Alyson Hannigan), a kindergarten teacher. At that moment, " + "Ted realizes that he had better get a move on if he too hopes to find true love." + " Helping him in his quest is Barney (Neil Patrick Harris), a friend with endless, " + "sometimes outrageous opinions, a penchant for suits and a foolproof way to meet women. " + "When Ted meets Robin (Cobie Smulders), he's sure it's love at first sight, but destiny may " + "have something else in store. The series is narrated through flashbacks from the future, " + "voiced by Bob Saget. The theme song is \"Hey Beautiful\" by The Solids." }); context.SaveChanges(); SerieContext.SetUpGenres(new List <int>() { 0, 1, 2, 3, 4 }, 1, context); SerieContext.SetUpGenres(new List <int>() { 4, 5, 6, 7 }, 2, context); Serie s = (from x in context.Serie where x.Name.Contains("Game") select x).First(); s.SerieImgsURL = new List <SerieImgURL>() { new SerieImgURL() { ImgType = ImgType.Cover, ImgURL = @"http://www.stoneykins.com/Patterns/product_images/e/149/Game_of_Thrones_tn__77121_std.png" }, { new SerieImgURL() { ImgType = ImgType.Banner, ImgURL = "URL" } } }; s = (from x in context.Serie where x.Name.Contains("How") select x).First(); s.SerieImgsURL = new List <SerieImgURL>() { new SerieImgURL() { ImgType = ImgType.Cover, ImgURL = @"https://v.cdn.vine.co/r/avatars/D0A6B55AAB1040788837653241856_17a62797dbd.4.7_X9TGvDShOHDefmN6ACIt13Gy3zNZMBMcyN7KnvN81Xfj8iKVr2bgYnsCNiLrP5KS.jpg?versionId=z_AG4BQSS9tua.zxJCeENZLeRFf04.5a" }, { new SerieImgURL() { ImgType = ImgType.Banner, ImgURL = "URL" } } }; }
public ActionResult AddImg(int id) { SerieContext SC = new SerieContext(); return(View(SC.SerieImgURLs.Where(s => s.SerieId == id).First())); }
public IList <Serie> SeriesBasedOnGenre(IList <GenreType> genres, SerieContext SC) { //var series = new List<Serie>(); //var series = SC.Serie.Where(s => s.Genres.Where(g => g.Genre == )) //foreach (var serie in SC.Serie.ToList()) //{ // foreach (var genre in genres) // { // if (serie.Genres.Any(g => g.Genre == genre)) // { // series.Add(serie); // } // } //} IList <Serie> List = new List <Serie>(); HashSet <Serie> Kortare = new HashSet <Serie>(); foreach (var Genre in genres) { foreach (var item in SC.Genre) { if ((GenreType)Genre == item.Genre) { using (SerieContext Sc = new SerieContext()) { var s = (from x in Sc.Serie.ToList() where x.Genres.Contains(item) select x).ToList(); if (!(s == null)) { if ((List.Count == 0 || List == null)) { List = s; } else { List.Union(s); } } //if (!Kortare.Any(s=>s.SerieId) //{ Kortare.Add(s); } } } } } //foreach (var item in Kortare) //{ // var s = (from x in SC.Serie // where x.SerieId == item.SerieId // select x).First(); // List.Add(s); //} //List = Kortare.ToList(); return(List); }
public CategoriesViewComponent(SerieContext context) { _context = context; }
private IList <Serie> SeriesSelectedBasedOnTextString(IList <Serie> List, string textstring, SerieContext SC) { IList <Serie> newList; if ((List.Count == 0) || (List == null)) { List = SC.Serie.ToList(); } if (textstring != null) { newList = (from x in List where x.Name.ToLower().Contains(textstring.ToLower()) || x.Description.ToLower().Contains(textstring.ToLower()) select x).ToList(); } else { return(List); } return(newList); }
private IList <Serie> SeriesSelectedBasedOnRelease(IList <Serie> List, DateTime From, DateTime to, SerieContext SC) { IList <Serie> newList; if ((List.Count == 0) || (List == null)) { List = SC.Serie.ToList(); } DateTime D = new DateTime(1800, 1, 1, 0, 0, 0); if (From > D && to > D) { newList = (from x in List where (From <= x.ReleaseDatum) && (x.ReleaseDatum <= to) select x).ToList(); return(newList); } else { return(List); } }
public SeriesController(SerieContext context) { _context = context; }
public HomeController(SerieContext context) { _context = context; }