Ejemplo n.º 1
0
        public ActionResult Create([Bind(Include = "ProjectID,TypeID,Name,About,CodeLanguage,Picture,Link")] Project project)
        {
            if (ModelState.IsValid)
            {
                db.Projects.Add(project);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.TypeID = new SelectList(db.ApplicationTypes, "TypeID", "AppType", project.TypeID);
            return(View(project));
        }
        public ActionResult PostComment(string comment, string returnUrl)
        {
            var Loggedin = ((Session?["Loggedin"] as bool?) ?? false);

            if (string.IsNullOrWhiteSpace(comment) || comment.Length > 140)
            {
                TempData["Error"] = "the comment is empty or above 140 caracters";
            }
            else
            {
                _database.Comments.Add(new Comment()
                {
                    CommentText = comment,
                    Date        = DateTime.UtcNow,
                    UserID      = Loggedin ? Session["ID"] as int? : null
                });
                _database.SaveChanges();
            }
            return(Redirect(returnUrl + "#comments"));
        }
Ejemplo n.º 3
0
        public ActionResult Register(RegisterViewModel model)
        {
            if (string.IsNullOrWhiteSpace(model.Username) || model.Username.Length > 20)
            {
                TempData["Error"] = "The Username is empty or above 20 caracters";
                return(View(model));
            }
            if (string.IsNullOrWhiteSpace(model.Password) || model.Password.Length > 20 || model.Password.Length < 4)
            {
                TempData["Error"] = "The Password is empty, above 20 caracters or below 4 caracters";
                return(View(model));
            }
            if (model.ConfirmPassword != model.Password)
            {
                TempData["Error"] = "The Password does not match the Retype Password ";
                return(View(model));
            }
            if (string.IsNullOrWhiteSpace(model.Email) || model.Email.Length > 30)
            {
                TempData["Error"] = "The Email is empty or above 30 caracters";
                return(View(model));
            }
            //Checks if there is a user with the same name in tne database
            if (_database.Users.Any(u => u.Username == model.Username))
            {
                TempData["Error"] = "The Username is already taken";
                return(View(model));
            }
            _database.Users.Add(new User()
            {
                Username = model.Username,
                Password = model.Password,
                Email    = model.Email
            });
            _database.SaveChanges();

            return(RedirectToAction("Login"));
        }