public ActionResult Index(User user)
        {
            BudgetDBEntities db = new BudgetDBEntities();

            db.Users.Add(user);
            try
            {
                db.SaveChanges();
            }
            catch (DbEntityValidationException ex)
            {
                foreach (var entityValidationErrors in ex.EntityValidationErrors)
                {
                    foreach (var validationError in entityValidationErrors.ValidationErrors)
                    {
                        Response.Write("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage);
                    }
                }
            }
            string message = string.Empty;

            switch (user.UserID)
            {
            case -1:
                message = "Username already exists.\\nPlease choose a different username.";
                break;

            default:
                message = "Registration successful.\\nUser Id: " + user.UserID.ToString();
                break;
            }
            ViewBag.Message = message;

            return(View(user));
        }
Exemple #2
0
        public ActionResult Index(User user)
        {
            BudgetDBEntities db = new BudgetDBEntities();
            int?userID          = db.ValidateUser(user.UserUseName, user.UserPassword).FirstOrDefault();

            string message = string.Empty;

            switch (userID.Value)
            {
            case -1:
                message = "Username and/or password is incorrect.";
                break;

            case -2:
                return(RedirectToAction("Welcome"));

            default:

                return(RedirectToAction("Welcome"));
            }

            ViewBag.Message = message;
            return(View(user));
        }