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); } } } }
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>"); } } }