private void detach_Users(User entity)
		{
			this.SendPropertyChanging();
			entity.Category = null;
		}
 partial void DeleteUser(User instance);
 partial void UpdateUser(User instance);
		private void attach_Users(User entity)
		{
			this.SendPropertyChanging();
			entity.Category = this;
		}
 partial void InsertUser(User instance);
		private void detach_Users1(User entity)
		{
			this.SendPropertyChanging();
			entity.filesTable1 = null;
		}
		private void attach_Users(User entity)
		{
			this.SendPropertyChanging();
			entity.filesTable = this;
		}
        public ActionResult Register(User model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    if (model.userName != null && model.userEmail != null && model.password != null)
                    {
                        using (FilesDatabaseClass1DataContext _db = new FilesDatabaseClass1DataContext())
                        {
                            var NameIsNew = _db.Users.Any(x => x.userName == model.userName);
                            var EmailIsNew = _db.Users.Any(x => x.userEmail == model.userEmail);
                            if (NameIsNew == false && EmailIsNew == false)
                            {
                                User newUser = new User
                                    {
                                        userName = model.userName,
                                        password = model.password,
                                        userEmail = model.userEmail
                                    };
                                _db.Users.InsertOnSubmit(newUser);
                                _db.SubmitChanges();
                                Login(model, "");
                            }
                        }
                        return RedirectToAction("Index", "Home");
                    }

                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
        public ActionResult Login(User model, string returnUrl)
        {
            //if (ModelState.IsValid && WebSecurity.Login(model.userName, model.password, persistCookie: model.rememberMe))
            //{
            //    return RedirectToLocal(returnUrl);
            //}

            //// If we got this far, something failed, redisplay form
            //ModelState.AddModelError("", "The user name or password provided is incorrect.");
            //return View(model);

            // Lets first check if the Model is valid or not
            if (ModelState.IsValid)
            {
                using (FilesDatabaseClass1DataContext db = new FilesDatabaseClass1DataContext())
                {
                    string username = model.userName;
                    string password = model.password;

                    // Now if our password was enctypted or hashed we would have done the
                    // same operation on the user entered password here, But for now
                    // since the password is in plain text lets just authenticate directly

                    bool userValid = db.Users.Any(user => user.userName == username && user.password == password);

                    // User found in the database
                    if (userValid)
                    {

                        FormsAuthentication.SetAuthCookie(username, false);
                        if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
                            && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                        {
                            return Redirect(returnUrl);
                        }
                        else
                        {
                            return RedirectToAction("Index", "Home");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "The user name or password provided is incorrect.");
                    }
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }