public List <Tasks> GetTasks() { List <Tasks> tasks = new List <Tasks>(); using (SqlConnection con = new SqlConnection(Addonet.Get())) { string query = "Select Id , Name,Type,Cost From Tasks "; SqlCommand cmd = new SqlCommand(query, con); con.Open(); using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { Tasks t = new Tasks() { Id = reader.GetInt32(0), Name = reader.GetString(1), Type = reader.GetString(2), Cost = reader.GetInt32(3) }; tasks.Add(t); } } } return(tasks); }
public User LoginAttempt(UserViewModel user) { User U = null; using (SqlConnection con = new SqlConnection(Addonet.Get())) { string query = "Select Id, Email, Password, Privilage From Users Where Email = @Email and Password = @Password"; SqlCommand cmd = new SqlCommand(query, con); cmd.Parameters.AddWithValue("@Email", user.Email); cmd.Parameters.AddWithValue("@Password", user.Password); con.Open(); using (SqlDataReader reader = cmd.ExecuteReader()) { if (reader.Read()) { User dbUser = new User(); dbUser.Id = reader.GetInt32(0); dbUser.Email = reader.GetString(1); dbUser.Privilage = reader.GetInt32(3); U = dbUser; } } } return(U); }
public Tasks GetTaskByID(int Id) { using (SqlConnection con = new SqlConnection(Addonet.Get())) { string query = "Select Id,Name,Type,Cost From Tasks Where Id = @Id"; SqlCommand cmd = new SqlCommand(query, con); cmd.Parameters.AddWithValue("@Id", Id); con.Open(); using (SqlDataReader reader = cmd.ExecuteReader()) { if (reader.Read()) { Tasks t = new Tasks() { Id = reader.GetInt32(0), Name = reader.GetString(1), Type = reader.GetString(2), Cost = reader.GetInt32(3) }; return(t); } } } return(null); }
public bool Delete(int Id) { using (SqlConnection con = new SqlConnection(Addonet.Get())) { string query = "Delete From Tasks Where Id = @Id"; SqlCommand cmd = new SqlCommand(query, con); cmd.Parameters.AddWithValue("@Id", Id); con.Open(); return(cmd.ExecuteNonQuery() == 1); } }
public bool Create(Tasks task) { using (SqlConnection con = new SqlConnection(Addonet.Get())) { string query = "Insert Into Tasks(Name,Type,Cost) Values (@N,@T,@C)"; SqlCommand cmd = new SqlCommand(query, con); cmd.Parameters.AddWithValue("@N", task.Name); cmd.Parameters.AddWithValue("@T", task.Type); cmd.Parameters.AddWithValue("@C", task.Cost); con.Open(); return(cmd.ExecuteNonQuery() == 1); } }
public bool Update(Tasks task) { using (SqlConnection con = new SqlConnection(Addonet.Get())) { string query = "Update Tasks Set Name = @N, Type = @T,Cost = @C Where Id = @Id"; SqlCommand cmd = new SqlCommand(query, con); cmd.Parameters.AddWithValue("@N", task.Name); cmd.Parameters.AddWithValue("@T", task.Type); cmd.Parameters.AddWithValue("@C", task.Cost); cmd.Parameters.AddWithValue("@Id", task.Id); con.Open(); return(cmd.ExecuteNonQuery() == 1); } }
public bool Register(UserViewModel user) { using (SqlConnection con = new SqlConnection(Addonet.Get())) { string query = "Select Id From Users Where Email = @Email"; SqlCommand cmd = new SqlCommand(query, con); cmd.Parameters.AddWithValue("@Email", user.Email); con.Open(); using (SqlDataReader reader = cmd.ExecuteReader()) { if (reader.Read()) { return(false); } } query = "Insert Into Users (Email,Password) Values(@Email,@Password)"; cmd = new SqlCommand(query, con); cmd.Parameters.AddWithValue("@Email", user.Email); cmd.Parameters.AddWithValue("@Password", user.Password); bool result = cmd.ExecuteNonQuery() == 1; return(result); } }