Exemplo n.º 1
0
 protected void reqlist_ItemCommand(object source, RepeaterCommandEventArgs e)
 {
     if (e.CommandName == "viewprofile")
     {
         Response.Redirect("~/Views/profile/view.aspx?uid=" + e.CommandArgument.ToString());
     }
     if (e.CommandName == "pay")
     {
         string   idList = e.CommandArgument.ToString();
         string[] ids    = idList.Split(',');
         Response.Redirect("~/Views/service/payment.aspx?sid=" + ids[0] + "&jid=" + ids[1]);
     }
     if (e.CommandName == "cancel")
     {
         string   idList = e.CommandArgument.ToString();
         string[] ids    = idList.Split(',');
         User     curr   = new User().SelectById(LblUid.Value);
         List <BL.service.Service> service = new BL.service.Service().SelectById(ids[2]);
         int result = new Jobs().UpdateStatus(ids[0], "cancelled");
         if (result == 0)
         {
             Toast.error(this, "An error occured while cancelling request");
         }
         else
         {
             Notification notif = new Notification(int.Parse(LblUid.Value), curr.username, int.Parse(ids[2]), service[0].name, ids[1], "job_cancel");
             notif.AddNotif();
             List <Jobs> jobs = new Jobs().SelectByCid(LblUid.Value);
             reqlist.DataSource = jobs;
             reqlist.DataBind();
             Toast.success(this, "Request cancelled");
         }
     }
 }
Exemplo n.º 2
0
        protected void btn_Share_Click(object sender, EventArgs e)
        {
            string fileId = "";

            foreach (RepeaterItem item in files.Items)
            {
                CheckBox chkbox = item.FindControl("checkFile") as CheckBox;
                if (chkbox.Checked && chkbox != null)
                {
                    fileId = chkbox.Attributes["CommandArgument"];
                }
            }
            BL.file.File file        = new BL.file.File().SelectById(fileId);
            User         currUser    = new User().SelectById(currUserId);
            User         targetShare = new User().SelectByEmail(share_user_input.Value);

            if (!string.IsNullOrEmpty(share_user_input.Value) && share_user_input.Value.Contains("@"))
            {
                if (targetShare != null)
                {
                    if (share_user_input.Value != currUser.email)
                    {
                        int result = file.UpdateShares(fileId, file.shareId + "," + targetShare.Id);
                        if (result == 0)
                        {
                            Toast.error(this, "An error occured while sharing file");
                        }
                        else
                        {
                            string fileName = file.fileName;
                            if (file.fileName.Length > 31)
                            {
                                fileName = file.fileName.Substring(0, 30) + "...";
                            }
                            Notification notif = new Notification(int.Parse(currUserId), currUser.username, file.Id, fileName, targetShare.Id.ToString(), "file");
                            notif.AddNotif();
                            bindSharedUsers(file.Id.ToString());
                            Toast.success(this, "File shared successfully");
                        }
                    }
                    else
                    {
                        Toast.error(this, "You cannot share a file to yourself");
                    }
                }
                else
                {
                    Toast.error(this, "User not found, please try again");
                }
            }
            else
            {
                Toast.error(this, "Please enter a valid email");
            }
        }
Exemplo n.º 3
0
        protected void serviceview_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "request")
            {
                string freelancerId = e.CommandArgument.ToString();
                string serviceId    = Request.QueryString["id"].ToString();
                List <BL.service.Service> service = new BL.service.Service().SelectById(serviceId);
                User curruser   = new User().SelectById(LblUid.Value);
                User freelancer = new User().SelectById(freelancerId);
                Jobs existjob   = new Jobs().SelectByCidSid(curruser.Id.ToString(), service[0].Id.ToString());

                if (int.Parse(freelancerId) == curruser.Id)
                {
                    Session["error"] = "You cannot purchase your own service";
                    Response.Redirect("~/Views/service/servicelist.aspx");
                }

                if (curruser.type == "freelancer")
                {
                    Session["error"] = "Only clients are able to request services";
                    Response.Redirect("~/Views/service/servicelist.aspx");
                }

                if (existjob == null)
                {
                    TextBox tbRemark = (TextBox)e.Item.FindControl("tbRemarks");
                    Jobs    job      = new Jobs(int.Parse(LblUid.Value), int.Parse(freelancerId), int.Parse(serviceId), service[0].name, curruser.username, freelancer.username, tbRemark.Text, service[0].price);
                    int     result   = job.AddJob();

                    if (result == 0)
                    {
                        Session["error"] = "An error occured while requesting the service";
                        Response.Redirect("~/Views/service/servicelist.aspx");
                    }
                    else
                    {
                        Notification notif = new Notification(int.Parse(LblUid.Value), curruser.username, int.Parse(serviceId), service[0].name, freelancer.Id.ToString(), "job");
                        notif.AddNotif();
                        Session["success"] = "Service requested successfully, please wait for " + freelancer.username + "\\'s response";
                        Response.Redirect("~/Views/service/servicelist.aspx");
                    }
                }
                else
                {
                    Session["error"] = "You cannot request for this service until completion of previous request";
                    Response.Redirect("~/Views/service/servicelist.aspx");
                }
            }
            if (e.CommandName == "viewprofile")
            {
                Response.Redirect("~/Views/profile/view.aspx?id=" + e.CommandArgument.ToString());
            }
        }
Exemplo n.º 4
0
        protected void followButton_Click(object sender, EventArgs e)
        {
            User currUser   = new User().SelectById(currUserId);
            User viewedUser = new User().SelectById(targetUserId);

            currUser.UpdateFollowing(currUser.Id.ToString(), currUser.following + 1);
            viewedUser.UpdateFollower(viewedUser.Id.ToString(), viewedUser.followers + 1);
            Follow follow = new Follow(currUser.Id, viewedUser.Id);

            follow.Insert();
            Notification notif = new Notification(viewedUser.Id, viewedUser.username, currUser.Id, currUser.username, viewedUser.Id.ToString(), "follow");

            notif.AddNotif();
            Session["success"] = viewedUser.username + " followed";
            Response.Redirect("~/Views/profile/view.aspx?id=" + viewedUser.Id);
        }
Exemplo n.º 5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["uid"] == null)
            {
                Session["error"] = "Unauthorized";
                Response.Redirect("~/Views/index.aspx");
            }
            else
            {
                StripeConfiguration.ApiKey = "sk_test_51Hnjg6K2AIXSM7wrvlwz0S8eQSrtxjb7irpnIhvWGSKSsbWJzUymiC3tHbwxYQCumbmK5gC06kRIw7wr1eHEpj6D00CDgHmOpO";
                currUserId = Session["uid"].ToString();
                User user       = new User().SelectById(currUserId);
                User freelancer = new User().SelectById(Request.QueryString["fid"].ToString());
                List <BL.service.Service> service = new BL.service.Service().SelectById(Request.QueryString["sid"].ToString());
                Customer        cust      = new Customer();
                Customer        freelance = new Customer();
                CustomerService serv      = new CustomerService();

                cust      = serv.Get(user.stripeId);
                freelance = serv.Get(freelancer.stripeId);

                string token      = Request.QueryString["token"].ToString();
                bool   tokenValid = new User().CheckTokenValid("payment", token, currUserId);

                if (tokenValid)
                {
                    Payment.pay(cust, freelance, service[0].price.ToString());
                    new Jobs().UpdateStatus(Request.QueryString["jid"].ToString(), "paid");
                    Notification notif = new Notification(user.Id, user.username, int.Parse(Request.QueryString["sid"].ToString()), service[0].name, freelancer.Id.ToString(), "job_paid");
                    notif.AddNotif();
                    Transaction trans = null;
                    trans = new Transaction(freelancer.username, service[0].name, "SGD", service[0].price, user.Id);
                    trans.AddTrans();
                    trans = new Transaction(user.username, service[0].name, "SGD", service[0].price, freelancer.Id);
                    trans.AddTrans();
                    Session["success"] = "Transaction successful";
                    Response.Redirect("~/Views/service/paymentList.aspx");
                }
                else
                {
                    Session["error"] = "Payment token is invalid or has expired";
                    Response.Redirect("~/Views/index.aspx");
                }
            }
        }
Exemplo n.º 6
0
        protected void favList_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "view")
            {
                string serviceId = e.CommandArgument.ToString();
                List <BL.service.Service> service = new BL.service.Service().SelectById(serviceId);
                BL.service.Service        curr    = new BL.service.Service();
                curr.UpdateViews(serviceId, service[0].views + 1);
                Response.Redirect("~/Views/service/index.aspx?id=" + serviceId);
            }
            if (e.CommandName == "favourite")
            {
                if (string.IsNullOrEmpty(LblUid.Text))
                {
                    Session["error"] = "Please log in to favourite a service";
                    Response.Redirect("~/Views/auth/login.aspx");
                }

                string serviceId = e.CommandArgument.ToString();
                List <BL.service.Service> service = new BL.service.Service().SelectById(serviceId);
                BL.service.Service        curr    = new BL.service.Service();
                User curruser   = getCurrUser();
                User freelancer = new User().SelectById(service[0].uid.ToString());

                List <string> userfavs = new Fav().SelectUserFavs(LblUid.Text);

                if (!userfavs.Contains(serviceId))
                {
                    int servres = curr.Favourite(serviceId, service[0].favs + 1);
                    Fav fav     = new Fav(int.Parse(LblUid.Text), int.Parse(serviceId));
                    int favres  = fav.Add();
                    if (favres == 1 && servres == 1)
                    {
                        Notification notif = new Notification(int.Parse(LblUid.Text), curruser.username, service[0].Id, service[0].name, freelancer.Id.ToString(), "fav");
                        notif.AddNotif();
                        Toast.success(this, "Service favourited");
                    }
                    else
                    {
                        Toast.error(this, "An error occured while favouriting the service");
                    }
                }
                else
                {
                    int servres = curr.Favourite(serviceId, service[0].favs - 1);
                    Fav fav     = new Fav();
                    int favres  = fav.Remove(int.Parse(LblUid.Text), int.Parse(serviceId));
                    if (favres == 1 && servres == 1)
                    {
                        Toast.success(this, "Service unfavourited");
                    }
                    else
                    {
                        Toast.error(this, "An error occured while unfavouriting the service");
                    }
                }
                List <string>             userFavs = new Fav().SelectUserFavs(LblUid.Text);
                List <BL.service.Service> servFavs = new List <BL.service.Service>();
                foreach (string favs in userFavs)
                {
                    List <BL.service.Service> serv = new BL.service.Service().SelectById(favs);
                    servFavs.Add(serv[0]);
                }
                favList.DataSource = servFavs;
                favList.DataBind();
            }
        }
Exemplo n.º 7
0
        protected void joblist_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "viewprofile")
            {
                Response.Redirect("~/Views/profile/view.aspx?id=" + e.CommandArgument.ToString());
            }

            if (e.CommandName == "accept")
            {
                string   idList     = e.CommandArgument.ToString();
                string[] ids        = idList.Split(',');
                User     freelancer = new User().SelectById(LblUid.Text);
                List <BL.service.Service> service = new BL.service.Service().SelectById(ids[1]);
                int result = new Jobs().UpdateStatus(ids[0], "accepted");
                if (result == 0)
                {
                    Toast.error(this, "An error occured while accepting job");
                }
                else
                {
                    Notification notif = new Notification(int.Parse(LblUid.Text), freelancer.username, int.Parse(ids[1]), service[0].name, ids[2], "request");
                    notif.AddNotif();
                    bind();
                    Toast.success(this, "Job accepted");
                }
            }

            if (e.CommandName == "reject")
            {
                string   idList     = e.CommandArgument.ToString();
                string[] ids        = idList.Split(',');
                User     freelancer = new User().SelectById(LblUid.Text);
                List <BL.service.Service> service = new BL.service.Service().SelectById(ids[1]);
                int result = new Jobs().UpdateStatus(ids[0], "cancelled");
                if (result == 0)
                {
                    Toast.error(this, "An error occured while cancelling job");
                }
                else
                {
                    Notification notif = new Notification(int.Parse(LblUid.Text), freelancer.username, int.Parse(ids[1]), service[0].name, ids[2], "req_cancel");
                    notif.AddNotif();
                    bind();
                    Toast.success(this, "Job cancelled");
                }
            }

            if (e.CommandName == "submit")
            {
                string   idList     = e.CommandArgument.ToString();
                string[] ids        = idList.Split(',');
                User     freelancer = new User().SelectById(LblUid.Text);
                List <BL.service.Service> service = new BL.service.Service().SelectById(ids[1]);
                int result = new Jobs().UpdateStatus(ids[0], "done");
                if (result == 0)
                {
                    Toast.error(this, "An error occured while completing job");
                }
                else
                {
                    Notification notif = new Notification(int.Parse(LblUid.Text), freelancer.username, int.Parse(ids[1]), service[0].name, ids[2], "complete");
                    notif.AddNotif();
                    bind();
                    Toast.success(this, "Job completed");
                }
            }
        }
Exemplo n.º 8
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();
         }
     }
 }