public void CreateNewSubmission(string title, string link, string username) { SubmissionDAO dao = new SubmissionDAO(); UserDAO userDAO = new UserDAO(); SubmissionVO newSub = new SubmissionVO(); if (title == null) { throw new Exception("You need to enter a title"); } if (link == null) { throw new Exception("You need to enter a link"); } newSub.Title = title; newSub.Link = link; newSub.Rating = 0; newSub.PostTime = DateTime.Now; newSub.UserID = userDAO.GetUser(username).UserID; dao.InsertSubmission(newSub); }
public void DeleteSubmission(SubmissionVO sub) { int rowsAffected = 0; try { DbCommand command = Database.GetSqlStringCommand(DELETE_SUBMISSION); Database.AddInParameter(command, SUBMISSION_ID, DbType.Int32, sub.SubmissionID); rowsAffected = Database.ExecuteNonQuery(command); } catch (Exception e) { LogError("Something exploded while deleting a submission from the database!", e); throw new Exception("Something exploded while deleting a submission from the database!", e); } if (rowsAffected == 0) { LogError("No submission found with an ID of " + sub.SubmissionID); throw new Exception("The delete command didn't delete anything!"); } }
private List<SubmissionVO> GetSubmissionList(DbCommand command) { List<SubmissionVO> subList = new List<SubmissionVO>(); IDataReader reader = null; try{ reader = Database.ExecuteReader(command); LogDebug("DataReader created, retrieving requested submission VO's..."); while(reader.Read()){ SubmissionVO sub = new SubmissionVO(); sub.SubmissionID = reader.GetInt32(0); sub.Title = reader.GetString(1); sub.Link = reader.GetString(2); sub.Rating = reader.GetInt32(3); sub.UserID = reader.GetInt32(4); sub.PostTime = reader.GetDateTime(5); subList.Add(sub); } LogDebug("List created!"); } catch (Exception e) { LogError("Something exploded in trying to retrieve a submission VO!", e); throw new Exception("Something exploded in trying to retrieve a submission VO!", e); } finally { base.CloseReader(reader); } return subList; }
private SubmissionVO FillInSubmissionVO(ref IDataReader reader) { SubmissionVO sub = new SubmissionVO(); sub.SubmissionID = reader.GetInt32(0); sub.Title = reader.GetString(1); sub.Link = reader.GetString(2); sub.Rating = reader.GetInt32(3); sub.UserID = reader.GetInt32(4); sub.PostTime = reader.GetDateTime(5); return sub; }
public void UpdateSubmission(SubmissionVO sub) { DbCommand command = Database.GetSqlStringCommand(UPDATE_SUBMISSION); try { Database.AddInParameter(command, TITLE, DbType.String, sub.Title); Database.AddInParameter(command, LINK, DbType.String, sub.Link); Database.AddInParameter(command, RATING, DbType.Int32, sub.Rating); Database.AddInParameter(command, USER_ID, DbType.Int32, sub.UserID); Database.AddInParameter(command, POST_TIME, DbType.DateTime, sub.PostTime); Database.AddInParameter(command, SUBMISSION_ID, DbType.Int32, sub.SubmissionID); Database.ExecuteScalar(command); } catch (Exception e) { LogError("Something exploded while updating submission " + sub.SubmissionID); throw new Exception("Something exploded while updating submission " + sub.SubmissionID); } }
public SubmissionVO InsertSubmission(SubmissionVO sub) { int sID = 0; try{ DbCommand command = Database.GetSqlStringCommand(INSERT_SUBMISSION); Database.AddInParameter(command, TITLE, DbType.String, sub.Title); Database.AddInParameter(command, LINK, DbType.String, sub.Link); Database.AddInParameter(command, RATING, DbType.Int32, sub.Rating); Database.AddInParameter(command, USER_ID, DbType.Int32, sub.UserID); Database.AddInParameter(command, POST_TIME, DbType.DateTime, sub.PostTime); sID = Convert.ToInt32(Database.ExecuteScalar(command)); } catch(Exception e){ LogError("Something exploded while trying to insert a submission!", e); throw new Exception("Something exploded while trying to insert a submission!", e); } return GetSubmission(sID); }