Ejemplo n.º 1
0
        protected void projects_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            User        currUser    = getCurrUser();
            HiddenField projIdField = e.Item.FindControl("projectId") as HiddenField;

            string projectCoverUrl = "~/Content/uploads/profile/" + currUser.Id.ToString() + "/projects/" + projIdField.Value + ".png";
            string pathToFile      = Server.MapPath(projectCoverUrl);

            if (System.IO.File.Exists(pathToFile))
            {
                Image projImg = e.Item.FindControl("projCover") as Image;
                projImg.ImageUrl = Page.ResolveUrl(projectCoverUrl);
                projImg          = e.Item.FindControl("projModalCover") as Image;
                projImg.ImageUrl = Page.ResolveUrl(projectCoverUrl);
            }

            string profilePicUrl = "~/Content/uploads/profile/" + currUser.Id.ToString() + "/profilePic.png";

            pathToFile = Server.MapPath(profilePicUrl);
            if (System.IO.File.Exists(pathToFile))
            {
                Image profilePic = e.Item.FindControl("profilePic") as Image;
                profilePic.ImageUrl = Page.ResolveUrl(profilePicUrl);
                profilePic          = e.Item.FindControl("modal_profilePic") as Image;
                profilePic.ImageUrl = Page.ResolveUrl(profilePicUrl);
            }

            Label LblUsername = e.Item.FindControl("modal_username") as Label;

            LblUsername.Text = currUser.username;
            LblUsername      = e.Item.FindControl("modal_username2") as Label;
            LblUsername.Text = currUser.username;
            LblUsername      = e.Item.FindControl("formUsername") as Label;
            LblUsername.Text = currUser.username;

            Repeater servicerepeater = e.Item.FindControl("userServices") as Repeater;
            List <BL.service.Service> userServices = new BL.service.Service().SelectByUid(currUser.Id.ToString());

            servicerepeater.DataSource = userServices;
            servicerepeater.DataBind();
            if (userServices.Count < 1)
            {
                e.Item.FindControl("noService").Visible = true;
            }

            Repeater           commentrepeater = e.Item.FindControl("comments") as Repeater;
            List <PortComment> comments        = new PortComment().SelectByPid(int.Parse(projIdField.Value));

            commentrepeater.DataSource = comments;
            commentrepeater.DataBind();
            if (comments.Count < 1)
            {
                e.Item.FindControl("noComments").Visible = true;
            }
        }
Ejemplo n.º 2
0
 protected void projects_ItemCommand(object source, RepeaterCommandEventArgs e)
 {
     if (e.CommandName == "delete")
     {
         int result = new Portfolio().Delete(e.CommandArgument.ToString());
         if (result == 0)
         {
             Toast.error(this, "An error occured while deleteing project");
         }
         else
         {
             Toast.success(this, "Project deleted successfully");
             List <Portfolio> ports = new Portfolio().SelectByUid(int.Parse(LblUid.Text));
             projects.DataSource = ports;
             projects.DataBind();
         }
     }
     if (e.CommandName == "edit")
     {
         Response.Redirect("~/Views/profile/editProject.aspx?id=" + e.CommandArgument.ToString());
     }
     if (e.CommandName == "comment")
     {
         TextBox tbcomment = e.Item.FindControl("tbComment") as TextBox;
         if (!string.IsNullOrEmpty(tbcomment.Text))
         {
             string      pid     = e.CommandArgument.ToString();
             User        user    = new User().SelectById(LblUid.Text);
             PortComment comment = new PortComment(user.Id, user.username, tbcomment.Text, int.Parse(pid));
             int         result  = comment.AddComment();
             if (result == 0)
             {
                 Toast.error(this, "An error occured while adding comment");
             }
             else
             {
                 Toast.success(this, "Comment added");
                 Portfolio currPort = new Portfolio().SelectById(int.Parse(pid));
                 new Portfolio().UpdateComm(pid, currPort.comments + 1);
                 List <Portfolio> portfolios = new Portfolio().SelectByUid(getCurrUser().Id);
                 projects.DataSource = portfolios;
                 projects.DataBind();
                 Repeater           commentrepeater = e.Item.FindControl("comments") as Repeater;
                 List <PortComment> comments        = new PortComment().SelectByPid(int.Parse(pid));
                 commentrepeater.DataSource = comments;
                 commentrepeater.DataBind();
             }
         }
         else
         {
             Toast.error(this, "Please enter a comment");
         }
     }
 }
Ejemplo n.º 3
0
        public int Insert(PortComment comment)
        {
            string        DBConnect = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
            SqlConnection conn      = new SqlConnection(DBConnect);

            string sqlStmt = "INSERT INTO PortComment (uid, username, content, date, pid)" +
                             "VALUES (@paraUID, @paraName, @paraContent, @paraDate, @paraPID)";

            int        result = 0;
            SqlCommand sqlCmd = new SqlCommand(sqlStmt, conn);

            sqlCmd.Parameters.AddWithValue("@paraUID", comment.uid);
            sqlCmd.Parameters.AddWithValue("@paraName", comment.username);
            sqlCmd.Parameters.AddWithValue("@paraContent", comment.content);
            sqlCmd.Parameters.AddWithValue("@paraDate", comment.date);
            sqlCmd.Parameters.AddWithValue("@paraPID", comment.pid);

            conn.Open();
            result = sqlCmd.ExecuteNonQuery();
            conn.Close();

            return(result);
        }
Ejemplo n.º 4
0
        public List <PortComment> SelectByPid(int PID)
        {
            string        DBConnect = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
            SqlConnection conn      = new SqlConnection(DBConnect);

            string sqlStmt = "SELECT * FROM PortComment WHERE pid = @paraPID";

            SqlDataAdapter da = new SqlDataAdapter(sqlStmt, conn);

            da.SelectCommand.Parameters.AddWithValue("@paraPID", PID);

            DataSet ds = new DataSet();

            da.Fill(ds);
            int rec_cnt = ds.Tables[0].Rows.Count;

            PortComment        obj      = null;
            List <PortComment> comments = new List <PortComment>();

            if (rec_cnt > 0)
            {
                for (int i = 0; i < rec_cnt; i++)
                {
                    DataRow row      = ds.Tables[0].Rows[i];
                    int     Id       = int.Parse(row["Id"].ToString());
                    int     uid      = int.Parse(row["uid"].ToString());
                    string  username = row["username"].ToString();
                    string  content  = row["content"].ToString();
                    string  date     = row["date"].ToString();
                    obj = new PortComment(uid, username, content, PID, date, Id);

                    comments.Add(obj);
                }
            }

            return(comments);
        }
Ejemplo n.º 5
0
 protected void projects_ItemCommand(object source, RepeaterCommandEventArgs e)
 {
     if (e.CommandName == "comment")
     {
         TextBox tbcomment = e.Item.FindControl("tbComment") as TextBox;
         if (!string.IsNullOrEmpty(tbcomment.Text))
         {
             string      pid     = e.CommandArgument.ToString();
             User        user    = new User().SelectById(currUserId);
             PortComment comment = new PortComment(user.Id, user.username, tbcomment.Text, int.Parse(pid));
             int         result  = comment.AddComment();
             if (result == 0)
             {
                 Toast.error(this, "An error occured while adding comment");
             }
             else
             {
                 Toast.success(this, "Comment added");
                 Portfolio currPort = new Portfolio().SelectById(int.Parse(pid));
                 new Portfolio().UpdateComm(pid, currPort.comments + 1);
                 if (currPort.uid.ToString() != currUserId)
                 {
                     Notification notif = new Notification(int.Parse(currUserId), user.username, int.Parse(pid), currPort.title, targetUserId, "project");
                     notif.AddNotif();
                 }
                 List <Portfolio> portfolios = new Portfolio().SelectByUid(int.Parse(targetUserId));
                 projects.DataSource = portfolios;
                 projects.DataBind();
                 Repeater           commentrepeater = e.Item.FindControl("comments") as Repeater;
                 List <PortComment> comments        = new PortComment().SelectByPid(int.Parse(pid));
                 commentrepeater.DataSource = comments;
                 commentrepeater.DataBind();
             }
         }
         else
         {
             Toast.error(this, "Please enter a comment");
         }
     }
     if (e.CommandName == "like")
     {
         Portfolio currPort = new Portfolio().SelectById(int.Parse(e.CommandArgument.ToString()));
         User      currUser = new User().SelectById(currUserId);
         int       result   = new Portfolio().UpdateLikes(currPort.likes + 1, currPort.likeslist + currUserId + ",", currPort.Id.ToString());
         if (result == 0)
         {
             Toast.error(this, "An error occured while liking project");
         }
         else
         {
             Toast.success(this, "Project liked");
             Notification notif = new Notification(int.Parse(currUserId), currUser.username, currPort.Id, currPort.title, targetUserId, "project_like");
             notif.AddNotif();
             List <Portfolio> projs = new Portfolio().SelectByUid(int.Parse(targetUserId));
             projects.DataSource = projs;
             projects.DataBind();
         }
     }
     if (e.CommandName == "unlike")
     {
         Portfolio     currPort   = new Portfolio().SelectById(int.Parse(e.CommandArgument.ToString()));
         List <string> usersLiked = new List <string>(currPort.likeslist.Split(','));
         usersLiked.Remove(currUserId);
         string final  = string.Join(",", usersLiked);
         int    result = new Portfolio().UpdateLikes(currPort.likes - 1, final, currPort.Id.ToString());
         if (result == 0)
         {
             Toast.error(this, "An error occured while unliking project");
         }
         else
         {
             Toast.success(this, "Project unliked");
             List <Portfolio> projs = new Portfolio().SelectByUid(int.Parse(targetUserId));
             projects.DataSource = projs;
             projects.DataBind();
         }
     }
 }