protected void sender_Click(object sender, EventArgs e) { try { UserEN user = new UserEN(); user.Email = userBox.Text; user.Password = passBox.Text; if (user.ValidationUser()) { Session.Clear(); Session["login"] = userBox.Text; Response.Redirect("LogOnOK.aspx"); } else { Control.Text = "The email and the password don't match"; } } catch (Exception ex) { Control.Text = ex.Message; } }
protected void Page_Load(object sender, EventArgs e) { UserEN usuario = new UserEN(); usuario.Email = Session["Login"].ToString(); usuario = usuario.Read(); Email.Text = Session["login"].ToString(); Nombre.Text = usuario.Name; Apellidos.Text = usuario.Surname; Pais.Text = usuario.Country; Age.Text = usuario.Age.ToString(); Nickname.Text = usuario.Nick; Contraseña.Text = usuario.Password; }
protected void sender_Click(object sender, EventArgs e) { try { UserEN usuario = new UserEN(); usuario.Email = email.Text; if (usuario.CheckEmail()) { Label1.Text = "This email is already in use!"; } else { usuario.Nick = userBox.Text; usuario.Password = passBox.Text; usuario.Email = email.Text; usuario.Name = name.Text; usuario.Surname = surname.Text; usuario.Country = country.Text; if(age.Text != "") usuario.Age = Int32.Parse(age.Text); if (usuario.InsertUser()) { Session["login"] = usuario.Email; Response.Redirect("RegisterOK.aspx"); } else { Label1.Text = "A problem has ocurred during the creation of the user"; } } } catch (Exception ex) { } }
public bool Comment(UserEN u, RecipeEN r, CommentEN c) { bool added = false; SqlConnection sql = new SqlConnection(db); try { sql.Open(); SqlCommand com = new SqlCommand("INSERT INTO Ternary (Email, Id, Code)" + " VALUES ('" + u.Email + "', " + r.Id + ", " + c.Code + ")", sql); com.ExecuteNonQuery(); added = true; } catch (Exception ex) { } finally { sql.Close(); } return added; }
public bool VoteRecipe(UserEN u, RecipeEN r, int vote) { bool added = false; SqlConnection c = new SqlConnection(db); try { c.Open(); SqlCommand com = new SqlCommand("INSERT INTO Puntuation (Email, Id, Puntuation)" + " VALUES ('" + u.Email + "', " + r.Id + ", " + vote + ")", c); com.ExecuteNonQuery(); added = true; } catch (Exception ex) { } finally { c.Close(); } return added; }
public UserEN Read(UserEN u) { UserEN user = new UserEN(); SqlConnection c = new SqlConnection(db); try { c.Open(); SqlCommand com = new SqlCommand("SELECT * FROM Users WHERE email = '" + u.Email + "'", c); SqlDataReader dr = com.ExecuteReader(); if (dr.Read()) { user.Email = dr["Email"].ToString(); user.Name = dr["Name"].ToString(); user.Surname = dr["Surname"].ToString(); user.Country = dr["Country"].ToString(); user.Age = Int32.Parse(dr["Age"].ToString()); user.Nick = dr["Nick"].ToString(); user.Password = dr["Password"].ToString(); } dr.Close(); } catch (Exception ex) {} finally { c.Close(); } return user; }
// Returns a list with the recipes that a user have done public List<RecipeEN> RecipesUser(UserEN user) { List<RecipeEN> lista = new List<RecipeEN>(); RecipeCAD recipeCad = new RecipeCAD(); RecipeEN recipe; SqlConnection c = new SqlConnection(db); try { c.Open(); SqlCommand com = new SqlCommand("SELECT Id FROM Recipe WHERE User = '******'", c); SqlDataReader dr = com.ExecuteReader(); while (dr.Read()) { recipe = recipeCad.getRecipe(long.Parse(dr["Id"].ToString())); lista.Add(recipe); } dr.Close(); } catch (Exception ex) { } finally { c.Close(); } return lista; }
// Deletes as user from the database public bool DeleteUser(UserEN u) { bool deleted = false; SqlConnection c = new SqlConnection(db); try { c.Open(); SqlCommand com = new SqlCommand("DELETE FROM Users WHERE Email = '" + u.Email + "'", c); com.ExecuteNonQuery(); deleted = true; } catch (Exception ex) { } finally { c.Close(); } return deleted; }
// Inserts a user on the database public bool InsertUser(UserEN u) { bool added = false; SqlConnection c = new SqlConnection(db); try { c.Open(); string comando = "INSERT INTO Users (Email, Name, Surname, Country, Age, Nick, Password) VALUES ('" + u.Email + "', '" + u.Name + "', '" + u.Surname + "', '" + u.Country + "', " + u.Age + ", '" + u.Nick + "', '" + u.Password + "')"; SqlCommand com = new SqlCommand(comando, c); com.ExecuteNonQuery(); added = true; } catch (Exception ex) { } finally { c.Close(); } return added; }
// Returns a list with the recipes that a user have done public List<RecipeEN> RecipesUser(UserEN user) { List<RecipeEN> recetas = new List<RecipeEN>(); return recetas; }
public void voteRecipe(UserEN user, RecipeEN recipe, int vote) { }
// Inserts a user on the database public void InsertUser(UserEN user) { }
// Deletes as user from the database public void DeletesUser(UserEN user) { }
// Returns a list with the comments that a user have done public List<CommentEN> CommentsUser(UserEN user) { List<CommentEN> comentarios = new List<CommentEN>(); return comentarios; }
public void comment(UserEN user, CommentEN comment) { }
protected void Upload_recipe(object sender, EventArgs e) { if (Session["login"] != null) { RecipeEN receta = new RecipeEN(); UserEN usuario = new UserEN(); //usuario.Password = (string)Session["login"]; //usuario = usuario.Read(); usuario.Email = Session["Login"].ToString(); usuario = usuario.Read(); receta.Name = Nombre.Text; receta.Subtitle = Subtitulo.Text; receta.Time = Int32.Parse(Tiempo.Text); receta.Description = Descripcion.Text; receta.Origin = Origen.Text; receta.Imagen = Foto.Text; receta.Video = Video.Text; receta.Imagen = Foto.Text; receta.User = usuario; string num = DropDownList1.SelectedIndex.ToString(); if (num == "0") { receta.Difficulty = "Easy"; } else if (num == "1") { receta.Difficulty = "Medium"; } else if (num == "2") { receta.Difficulty = "Hard"; } else { receta.Difficulty = "Impossible"; } string tipo = DropDownList2.SelectedIndex.ToString(); if (tipo == "0") { receta.Type = "Starter"; } else if (tipo == "1") { receta.Type = "First Plate"; } else if (tipo == "2") { receta.Type = "Second Plate"; } else { receta.Type = "Dessert"; } //receta.User = usuario; if (receta.INSERT()) { //MensajeOK.Text = "The recipe was uploaded correctly"; Nombre.Text = ""; Subtitulo.Text = ""; Tiempo.Text = ""; Descripcion.Text = ""; Origen.Text = ""; Descripcion.Text = ""; Video.Text = ""; MensajeOK.Text = "The recipe is uploaded! Thank You!"; } else { MensajeOK.Text = "The recipe can not be uploaded"; } } else { MensajeOK.Text = "You have to be a registered user to upload a recipe!"; } }