예제 #1
0
        public IActionResult Create(Serie d)
        {
            if (ModelState.IsValid)
            {
                //SerieRepository.Add(d);
                _context.Series.Add(d);
                _context.SaveChanges();
                return(RedirectToAction("List"));
            }

            ViewBag.Category = new SelectList(_context.Categories.ToList(), "CategoryId", "Name");
            return(View());
        }
예제 #2
0
        public ActionResult Create(Serie S)
        {
            SerieContext SC = new SerieContext();

            SC.Serie.Add(S);
            SC.SaveChanges();

            return(RedirectToAction("SearchResult"));
        }
예제 #3
0
        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"));
        }
예제 #4
0
        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()));
        }
예제 #5
0
        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()));
            }
        }
예제 #6
0
        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"));
        }