Beispiel #1
0
        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);
        }
Beispiel #2
0
        private SubmissionVO GetSubmission(DbCommand command)
        {
            SubmissionVO sub    = null;
            IDataReader  reader = null;

            try {
                reader = Database.ExecuteReader(command);
                LogDebug("DataReader created, retrieving sbumission VO...");

                if (reader.Read())
                {
                    sub = FillInSubmissionVO(ref reader);
                }

                LogDebug("Submission VO retrieved!");
            }
            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);
            }

            if (sub == null)
            {
                throw new Exception("No submission found under submission ID!");
            }

            return(sub);
        }
Beispiel #3
0
        public void AdjustRating(int subID, int rating)
        {
            SubmissionVO vo = GetSubmission(subID);

            vo.Rating += rating;

            UpdateSubmission(vo);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        protected void GenerateSubmissionDetails()
        {
            CommentManagementBO    comBO  = new CommentManagementBO();
            SubmissionManagementBO bo     = new SubmissionManagementBO();
            SubmissionVO           sub    = bo.GetSubmission(submissionID);
            UserManagementBO       userBO = new UserManagementBO();
            UserVO vo = userBO.GetUser(sub.UserID);

            submissionRating.Text      = sub.Rating.ToString();
            submissionCommentLink.Text = (comBO.GetListOfSubmissionComments(submissionID).Count + " comments");

            Uri url;

            try {
                url = new Uri(sub.Link);
            }
            catch (Exception e) {
                try {
                    url = new Uri("http://" + sub.Link);
                }
                catch (Exception exc) {
                    url = new Uri("http://CouldntParseUrl");
                }
            }

            submissionTitle.Text = "<a href=\"" + url + "\">" + sub.Title + "</a> (" + url.Host.ToString() + ")";

            submissionDetails.Text = bo.FormatePostTime(sub.PostTime);

            userLink.Text = vo.Username;

            //Change arrow based on voting
            if (Session["login"] != null)
            {
                int i = userBO.CheckIfVoted(submissionID, userBO.GetUser(Session["login"].ToString()).UserID);
                if (i == 1)
                {
                    upArrow.ImageUrl = "~/Images/uparrow_voted.png";
                }
                else if (i == -1)
                {
                    downArrow.ImageUrl = "~/Images/downarrow_voted.png";
                }
            }
        }
Beispiel #6
0
        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);
            }
        }
Beispiel #7
0
        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!");
            }
        }
Beispiel #8
0
        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));
        }
Beispiel #9
0
        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);
        }