public void SaveTasks(string tasksArray)
 {
     try
     {
         using (var db = new webProjectEntities())
         {
             var  tasksTable     = JsonConvert.DeserializeObject(tasksArray);
             var  tasksTablejson = JsonConvert.DeserializeObject(tasksTable.ToString());
             var  userName       = ((user)Session["Account"]).userName;
             user account        = db.user.FirstOrDefault(u => u.userName == userName);
             account.tasks      = tasksTablejson.ToString();
             Session["Account"] = account;
             db.SaveChanges();
         }
     }
     catch (DbEntityValidationException dbEx)
     {
         foreach (var validationErrors in dbEx.EntityValidationErrors)
         {
             foreach (var validationError in validationErrors.ValidationErrors)
             {
                 Console.WriteLine("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
             }
         }
     }
 }
Ejemplo n.º 2
0
 protected void login(object sender, EventArgs e)
 {
     try
     {
         using (var db = new webProjectEntities())
         {
             var user = db.user.Where(tempAccount => tempAccount.userName.Equals(email.Text) && tempAccount.password.Equals(password.Text)).FirstOrDefault();
             if (user == null)
             {
                 Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "ShowInvalidateCredentials()", true);
             }
             else
             {
                 Session["Account"] = user;
                 Response.Redirect("Homepage.aspx");
             }
         }
     }
     catch (Exception)
     {
         Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "ShowInvalidateCredentials()", true);
     }
 }
 public string LoadTasks()
 {
     try
     {
         using (var db = new webProjectEntities())
         {
             var  userName = ((user)Session["Account"]).userName;
             user account  = db.user.FirstOrDefault(u => u.userName == userName);
             return(account.tasks);
         }
     }
     catch (DbEntityValidationException dbEx)
     {
         foreach (var validationErrors in dbEx.EntityValidationErrors)
         {
             foreach (var validationError in validationErrors.ValidationErrors)
             {
                 Console.WriteLine("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
             }
         }
         return(null);
     }
 }
        protected void register(object sender, EventArgs e)
        {
            using (var db = new webProjectEntities())
            {
                if (!(password.Text.Equals(password2.Text)))
                {
                    Response.Write("<script>alert('Password doesnt match')</script>");
                    return;
                }
                if (!IsValidEmail(email.Text))
                {
                    Response.Write("<script>alert('Email address is not valid')</script>");
                    return;
                }

                var newUser = new user()
                {
                    userName = email.Text,
                    password = password.Text,
                };
                try
                {
                    db.user.Add(newUser);
                    db.SaveChanges();
                    email.Text     = "";
                    password.Text  = "";
                    password2.Text = "";
                    Response.Write("<script>alert('Registered Successfully')</script>");
                    Response.Redirect("Login.aspx");
                }
                catch (Exception)
                {
                    Response.Write("<script>alert('Email already exists, please choose a different email')</script>");
                }
            }
        }