/// <summary> /// Poonam Dubey /// 04/06/2016 /// Function to call DB and insert groupmember request /// /// Altered by Nicholas King /// </summary> /// <param name="reqObj"></param> /// <returns></returns> public static int CreateGroupMember(GroupRequest reqObj) { string query = @"Admin.spInsertGroupRequest"; int rowCount = 0; var conn = DBConnection.GetDBConnection(); var cmd = new SqlCommand(query, conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@GroupID", reqObj.GroupID); cmd.Parameters.AddWithValue("@UserID", reqObj.UserID); //This Para is not used by the stored procedure //cmd.Parameters.AddWithValue("@RequestStatus", reqObj.RequestStatus); cmd.Parameters.AddWithValue("@RequestDate", reqObj.RequestDate); try { conn.Open(); rowCount = cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { conn.Close(); } return(rowCount); }
public static int PledgeVolunteerHours(DateTime start, DateTime end, DateTime date, int UserID) { int rowCount = 0; var conn = DBConnection.GetDBConnection(); var query = "Donations.spInsertTimePledge"; var cmd = new SqlCommand(query, conn); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@UserID", UserID); cmd.Parameters.AddWithValue("@StartTime", start); cmd.Parameters.AddWithValue("@FinishTime", end); cmd.Parameters.AddWithValue("@Date", date); cmd.Parameters.Add(new SqlParameter("RowCount", SqlDbType.Int)); cmd.Parameters["RowCount"].Direction = ParameterDirection.ReturnValue; try { conn.Open(); rowCount = (int)cmd.ExecuteNonQuery(); } catch (Exception) { throw new ApplicationException("Invalid Selection!"); } finally { conn.Close(); } return(rowCount); }
/// <summary> /// /// Created By: Trent Cullinan 04/14/16 /// </summary> /// <param name="needContribution"></param> /// <returns></returns> public int SendContribution(NeedContribution needContribution) { int rowsAffected = 0; var conn = DBConnection.GetDBConnection(); var cmd = new SqlCommand("Needs.spInsertContributions", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@NeedID", needContribution.Need.GardenNeedId); cmd.Parameters.AddWithValue("@Description", needContribution.Description); cmd.Parameters.AddWithValue("@UserID", this.userId); try { conn.Open(); rowsAffected = cmd.ExecuteNonQuery(); } catch (SqlException) { throw; } finally { conn.Close(); } return(rowsAffected); }
/// <summary> /// Confirms information entered by user is correct in database. /// /// Created by: Trent Cullinan 03/25/16 /// </summary> /// <param name="userName">Username that relates.</param> /// <param name="email">Email to verified against database.</param> /// <param name="password">Password to be verified against database.</param> /// <returns>Whether all values can match.</returns> public static bool ConfirmUserInfo(string userName, string email, string password) { bool flag = false; var conn = DBConnection.GetDBConnection(); var cmd = new SqlCommand("Admin.spSelectUserInformationCount", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@UserName", userName); cmd.Parameters.AddWithValue("@EmailAddress", email); cmd.Parameters.AddWithValue("@Password", password); try { conn.Open(); flag = 1 == (int)cmd.ExecuteScalar(); } catch (SqlException) { throw; } finally { conn.Close(); } return(flag); }
/// <summary> /// Rhett Allen /// Created Date: 3/31/16 /// Counts how many recipes with a similar keyword and specified category are in the database /// </summary> /// <param name="keyword">Word that is like recipe fields</param> /// <param name="category">The recipe's category. Null category acts like all categories.</param> /// <returns>The number of recipes with a similar keyword and specified category are in the database</returns> /// changed method name from CountRecipes 4/21/16 Steve Hoover public static int RetrieveRecipeCount(string keyword = "", string category = null) { int count = 0; var conn = DBConnection.GetDBConnection(); var query = @"Expert.spCountRecipes"; var cmd = new SqlCommand(query, conn); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Keyword", keyword); if (category == null) { cmd.Parameters.AddWithValue("@Category", DBNull.Value); } else { cmd.Parameters.AddWithValue("@Category", category); } try { conn.Open(); count = (int)cmd.ExecuteScalar(); } catch (Exception) { throw; } finally { conn.Close(); } return(count); }
//Updated class name 4/14/16 Emily public static int RetrieveUserByUsernameAndPassword(string username, string password) { int count = 0; var conn = DBConnection.GetDBConnection(); var query = @"Admin.spSelectUserWithUsernameAndPassword"; var cmd = new SqlCommand(query, conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@username", username); cmd.Parameters.AddWithValue("@password", password); try { conn.Open(); count = (int)cmd.ExecuteScalar(); } catch (Exception) { throw; } finally { conn.Close(); } return(count); }
/// /// Is no need for two User Count methods. I commented this one out as the other one uses a /// Stored Procedure. I'm leaving this here, just in case it is decided to just fix this one and delete the other for /// some reason ///-Emily 4-14-16 public static int RetrieveUserCount(int userID) { int count = 0; // let's try a scalar query // start with a connection object var conn = DBConnection.GetDBConnection(); // write some command text string query = @"SELECT COUNT(*) " + @"FROM Admin.Users "; // create a command object var cmd = new SqlCommand(query, conn); try { conn.Open(); count = (int)cmd.ExecuteScalar(); } catch (Exception) { throw; } return(count); }
/// <summary> /// Poonam Dubey /// 19th April 2016 /// Function to mark a task as completed /// </summary> /// <param name="taskID"></param> /// <returns></returns> public static bool CompleteTask(int taskID) { var conn = DBConnection.GetDBConnection(); var query = "Gardens.spMarkTaskAsComplete"; var cmd = new SqlCommand(query, conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@TaskID", taskID); bool flag = false; try { conn.Open(); if (cmd.ExecuteNonQuery() != 0) { flag = true; } } catch (Exception) { throw; } finally { conn.Close(); } return(flag); }
///<summary> ///Author: Stenner Kvindlog ///submits application to database to be reviewed ///Date: 3/19/16 ///</summary> /// <remarks> /// Updated by: Chris Sheehan /// Date: 4/28/16 /// </remarks> public static bool CreateExpertApplication(String Title, String Description, int UserID, DateTime Time) { var conn = DBConnection.GetDBConnection(); var query = "Admin.spInsertExpertRequest"; var cmd = new SqlCommand(query, conn); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@UserID", UserID); cmd.Parameters.AddWithValue("@Title", Title); cmd.Parameters.AddWithValue("@Content", Description); cmd.Parameters.AddWithValue("@DateCreated", DateTime.Now); bool flag = false; try { conn.Open(); if (cmd.ExecuteNonQuery() == 1) { flag = true; } } catch (Exception) { throw; } finally { conn.Close(); } return(flag); }
/// <summary> /// Insert a task in a garden. /// Created By: Nasr Mohammed 3/4/2016 /// Modified on: 3/15/2016 /// </summary> /// <param name="job">The task that should be created </param> /// <returns>A rowsAffected if it's inserted successfully</returns> public static int CreateTask(Job job) { int rowsAffected = 0; var conn = DBConnection.GetDBConnection(); var cmdText = @"Gardens.spInsertTasks"; var cmd = new SqlCommand(cmdText, conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@gardenID", job.GardenID); cmd.Parameters.AddWithValue("@description", job.Description); cmd.Parameters.AddWithValue("@dateAssigned", job.DateAssigned); cmd.Parameters.AddWithValue("@assignedFrom", job.AssignedFrom); cmd.Parameters.AddWithValue("@userNotes", job.UserNotes); try { conn.Open(); rowsAffected = (int)cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { conn.Close(); } return(rowsAffected); }
public static List <int> RetrieveGardenIdByUserId(int userId) { var ints = new List <int>(); var conn = DBConnection.GetDBConnection(); // need to send Chris stored procedure var query = @"SELECT GardenID " + @"WHERE UserID=" + userId + "AND Active=1"; var cmd = new SqlCommand(query, conn); try { conn.Open(); var reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { ints.Add(reader.GetInt32(0)); } } } catch (Exception) { throw; } finally { conn.Close(); } return(ints); }
public static int UpdateGroupMemberRequest(GroupRequest request) { int count = 0; var conn = DBConnection.GetDBConnection(); string cmdText = "Admin.spAcceptRequest"; var cmd = new SqlCommand(cmdText, conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@GroupID", request.GroupID); cmd.Parameters.AddWithValue("@UserID", request.UserID); cmd.Parameters.AddWithValue("@ApprovedID", request.ApprovedBy); cmd.Parameters.AddWithValue("@ApprovedDate", request.ApprovedDate); try { conn.Open(); count = cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { conn.Close(); } return(count); }
/// <summary> /// Modifies the group member to either be /// active or inactive for a particular group. /// /// Created By: Trent Cullinan 02/31/2016 /// </summary> /// <param name="userId">User from group to be modified.</param> /// <param name="groupId">Group the user belongs to.</param> /// <returns>Rows affected by change.</returns> public static int UpdateInactivateGroupMember(int userId, int groupId) { int rowsAffected = 0; var conn = DBConnection.GetDBConnection(); var cmd = new SqlCommand("Gardens.spUpdateGroupMemberInactive", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@UserID", userId); cmd.Parameters.AddWithValue("@GroupID", groupId); try { conn.Open(); rowsAffected = cmd.ExecuteNonQuery(); } catch (SqlException) { throw; } finally { conn.Close(); } return(rowsAffected); }
/// <summary> /// Luke Frahm /// Created 03/31/16 /// Update database to set this group to inactive. /// </summary> /// <param name="groupID">ID of the group to deactivate</param> /// <returns>True if deactivated, False otherwise</returns> public static bool UpdateDeactivateGroupByID(int groupID) { int rowCount = 0; var conn = DBConnection.GetDBConnection(); string query = @"Gardens.spDeactivateGroupByID"; var cmd = new SqlCommand(query, conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@GroupID", groupID); cmd.Parameters.AddWithValue("@Active", 0); try { conn.Open(); rowCount = cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { conn.Close(); } return(rowCount == 1); }
/// <summary> /// Comments added by TRex /// This method allows a user to add a blog. /// </summary> /// <param name="blog"></param> /// <returns></returns> public static int InsertBlog(Blog blog) { int count = 0; var conn = DBConnection.GetDBConnection(); var query = @"Expert.spInsertBlogEntry"; var cmd = new SqlCommand(query, conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@BlogData", blog.BlogData); cmd.Parameters.AddWithValue("@BlogTitle", blog.BlogTitle); cmd.Parameters.AddWithValue("@CreatedBy", blog.CreatedBy); cmd.Parameters.AddWithValue("@CreatedDate", blog.DateCreated); cmd.Parameters.AddWithValue("@ModifiedBy", blog.CreatedBy); cmd.Parameters.AddWithValue("@ModifiedDate", blog.DateCreated); try { conn.Open(); count = (int)cmd.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(count); }
public static int CreateGardenTemplate(byte[] file, int userID, string fileName) { int count = 0; var conn = DBConnection.GetDBConnection(); var query = @"Expert.spInsertGardenTemplate"; var cmd = new SqlCommand(query, conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ImageName", fileName); cmd.Parameters.AddWithValue("@CreatedBy", userID); cmd.Parameters.AddWithValue("@CreateDate", DateTime.Now); cmd.Parameters.AddWithValue("@Active", 1); cmd.Parameters.AddWithValue("@ImageFile", file); try { conn.Open(); count = cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { conn.Close(); } return(count); }
/// <summary> /// Created by: Kristine /// </summary> /// <param name="userID"></param> /// <param name="garden"></param> /// <returns></returns> public static bool CreateAddGarden(Garden garden) { var conn = DBConnection.GetDBConnection(); var query = "Gardens.spInsertGardens"; var cmd = new SqlCommand(query, conn); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@GroupID", garden.GroupID); cmd.Parameters.AddWithValue("@GardenName", garden.GardenName); cmd.Parameters.AddWithValue("@UserID", garden.UserID); cmd.Parameters.AddWithValue("@GardenDescription", garden.GardenDescription); cmd.Parameters.AddWithValue("@GardenRegion", garden.GardenRegion); bool updated = false; try { conn.Open(); if (cmd.ExecuteNonQuery() == 1) { updated = true; } } catch (Exception) { throw; } finally { conn.Close(); } return(updated); }
///<summary> ///Author: Nicholas King ///Date: 3/19/16 ///Retrieve a garden templete name ///</summary> public static byte[] RetrieveGardenTemplate(string fileName) { byte[] data; var conn = DBConnection.GetDBConnection(); var query = @"Expert.spSelectGardenTemplate"; var cmd = new SqlCommand(query, conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@FileName", fileName); try { conn.Open(); data = cmd.ExecuteScalar() as byte[]; } catch (Exception) { throw; } finally { conn.Close(); } return(data); }
//Updated class name 4/14/16 Emily public static int CreatePasswordForUsername(string username, string oldPassword, string newPassword) { int count = 0; var conn = DBConnection.GetDBConnection(); var query = @"Admin.spUpdatePassword"; var cmd = new SqlCommand(query, conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@username", username); cmd.Parameters.AddWithValue("@oldPassword", oldPassword); cmd.Parameters.AddWithValue("@newPassword", newPassword); try { conn.Open(); count = (int)cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { conn.Close(); } return(count); }
// Created By: Trent Cullinan 02/24/2016 private int UpdateGroupLeader(Group group, GroupMember groupMember, bool active = true) { int rowsAffected = 0; var conn = DBConnection.GetDBConnection(); var cmd = new SqlCommand("Gardens.spUpdateGroupLeader", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@GroupID", group.GroupID); cmd.Parameters.AddWithValue("@UserID", groupMember.User.UserID); cmd.Parameters.AddWithValue("@Active", active); try { conn.Open(); rowsAffected = cmd.ExecuteNonQuery(); } catch (SqlException) { throw; } finally { conn.Close(); } return(rowsAffected); }
/// <summary> /// Checks to see if the value exists as a username with password in the database. /// /// Created by: Trent Cullinan 03/25/16 /// </summary> /// <param name="userName">Value to check database.</param> /// <param name="passWord">Value to check database.</param> /// <returns>Whether the username exists with password in the database.</returns> public static bool CheckUserNameWithPassword(string userName, string passWord) { bool flag = true; var conn = DBConnection.GetDBConnection(); var cmd = new SqlCommand("Admin.spSelectUserWithUsernameAndPassword", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@UserName", userName); cmd.Parameters.AddWithValue("@PassWord", passWord); try { conn.Open(); flag = 1 == (int)cmd.ExecuteScalar(); } catch (SqlException) { throw; } finally { conn.Close(); } return(flag); }
// upload blueprint to database public static bool UploadBlueprint(Blueprint blueprint) { bool flag = false; var conn = DBConnection.GetDBConnection(); var query = @"Expert.spInsertExpertBluePrints"; var cmd = new SqlCommand(query, conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Title", blueprint.Title); cmd.Parameters.AddWithValue("@Description", blueprint.Description); cmd.Parameters.AddWithValue("@DateCreated", blueprint.DateCreated); cmd.Parameters.AddWithValue("@CreatedBy", blueprint.ModifiedBy); cmd.Parameters.AddWithValue("@FilePath", blueprint.FilePath); try { // open the connection conn.Open(); // execute the command with ExecuteScalar() cmd.ExecuteScalar(); flag = true; } catch (Exception) { throw; } finally { conn.Close(); } return(flag); }
/// <summary> /// Change password for user. /// /// Created by: Trent Cullinan 03/25/16 /// </summary> /// <param name="userName">Username that relates.</param> /// <param name="oldPassWord">Password to be verified against database.</param> /// <param name="newPassWord">New password to be set in database.</param> /// <returns>Whether the action was successful.</returns> public static bool UpdateUserPassword(string userName, string oldPassWord, string newPassWord) { bool flag = false; var conn = DBConnection.GetDBConnection(); var cmd = new SqlCommand("Admin.spUpdatePassword", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@username", userName); cmd.Parameters.AddWithValue("@oldPassWord", oldPassWord); cmd.Parameters.AddWithValue("@newPassWord", newPassWord); try { conn.Open(); flag = 1 == (int)cmd.ExecuteNonQuery(); } catch (SqlException) { throw; } finally { conn.Close(); } return(flag); }
/// <summary> /// Rhett Allen /// Created Date: 4/7/16 /// Adds a single nutrient to a plant /// </summary> /// <param name="nutrientID">Nutrient ID of nutrient to be added</param> /// <param name="plantID">Plant ID of plant the nutrient is added to</param> /// <returns>True if the nutrient was added successfully</returns> public static bool InsertPlantNutrients(int nutrientID, int?plantID) { bool inserted = false; var conn = DBConnection.GetDBConnection(); var query = "Expert.spInsertPlantNutrients"; var cmd = new SqlCommand(query, conn); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@PlantID", plantID); cmd.Parameters.AddWithValue("@NutrientID", nutrientID); try { conn.Open(); if (cmd.ExecuteNonQuery() == 1) { inserted = true; } } catch (Exception) { throw; } finally { conn.Close(); } return(inserted); }
/// <summary> /// /// Created By: Trent Cullinan 04/14/16 /// </summary> /// <returns></returns> public IEnumerable <NeedContribution> RetrieveDeclinedContributions() { List <NeedContribution> contributions = new List <NeedContribution>(); var conn = DBConnection.GetDBConnection(); var cmd = new SqlCommand("", conn); cmd.CommandType = CommandType.StoredProcedure; try { conn.Open(); var reader = cmd.ExecuteReader(); while (reader.Read()) { contributions.Add(new NeedContribution() { }); } } catch (SqlException) { throw; } finally { conn.Close(); } return(contributions); }
/// <summary> /// Demote a User from expert status. /// /// Created By: Trent Cullinan 03/15/2016 /// </summary> /// <param name="user">User that is an expert to be demoted.</param> /// <returns>Rows affected by action.</returns> /// ///TRex changed the name of the method from DemoteExpert to UpdateExpertDemote 4/11/16 public int UpdateExpertDemote(User user) { int rowsAffected = 0; var conn = DBConnection.GetDBConnection(); var cmd = new SqlCommand("Admin.spRemoveUserRole", conn); cmd.CommandType = CommandType.StoredProcedure; CreateExpertChangeParams(cmd, user, active: false); try { conn.Open(); rowsAffected = cmd.ExecuteNonQuery(); } catch (SqlException) { throw; } finally { conn.Close(); } return(rowsAffected); }
/// <summary> /// /// Created By: Trent Cullinan 04/14/16 /// </summary> /// <returns></returns> public IEnumerable <GardenNeed> RetrieveAvailableNeeds() { List <GardenNeed> needs = new List <GardenNeed>(); var conn = DBConnection.GetDBConnection(); var cmd = new SqlCommand("", conn); cmd.CommandType = CommandType.StoredProcedure; try { conn.Open(); var reader = cmd.ExecuteReader(); while (reader.Read()) { needs.Add(new GardenNeed() { }); } } catch (SqlException) { throw; } finally { conn.Close(); } return(needs); }
public static bool CreateVolunteer(Volunteer volunteer) { var conn = DBConnection.GetDBConnection(); var query = "Gardens.spInsertVolunteers"; var cmd = new SqlCommand(query, conn); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@UserID", volunteer.UserID); cmd.Parameters.AddWithValue("@NeedID", volunteer.NeedID); cmd.Parameters.AddWithValue("@DateWIllVolunteer", volunteer.DateWillVolunteer); cmd.Parameters.AddWithValue("@Description", volunteer.Description); bool updated = false; try { conn.Open(); if (cmd.ExecuteNonQuery() == 1) { updated = true; } } catch (Exception) { throw; } finally { conn.Close(); } return(updated); }
/// <summary> /// /// Created By: Trent Cullinan 04/14/16 /// </summary> /// <param name="needContributionId"></param> /// <returns></returns> public int CancelPendingContribution(int needContributionId) { int rowsAffected = 0; var conn = DBConnection.GetDBConnection(); var cmd = new SqlCommand("Needs.spUpdateCancelContribution", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue(@"@ContributionID", needContributionId); try { conn.Open(); rowsAffected = cmd.ExecuteNonQuery(); } catch (SqlException) { throw; } finally { conn.Close(); } return(rowsAffected); }
/// <summary> /// Ryan Taylor and Luke Frahm /// Created 03/31/16 /// Query database to determine of the supplied user is a leader in the group. /// </summary> /// <param name="userID">ID of user to check status</param> /// <param name="groupID">ID of the group to query for user status</param> /// <returns>True if data was added, False otherwise</returns> public static bool RetrieveGroupLeaderStatus(int userID, int groupID) { bool isLeader = false; var conn = DBConnection.GetDBConnection(); string query = @"Gardens.spCheckLeaderStatus"; var cmd = new SqlCommand(query, conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@GroupId", groupID); cmd.Parameters.AddWithValue("@UserId", userID); try { conn.Open(); var reader = cmd.ExecuteReader(); isLeader = reader.HasRows; } catch (Exception ex) { throw new ApplicationException(ex.Message); } finally { conn.Close(); } return(isLeader); }