Exemple #1
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();
            }
        }
Exemple #2
0
 protected void managelist_ItemCommand(object source, RepeaterCommandEventArgs e)
 {
     if (e.CommandName == "viewprofile")
     {
         Response.Redirect("~/Views/profile/index.aspx");
     }
     if (e.CommandName == "edit")
     {
         Response.Redirect("~/Views/service/edit.aspx?id=" + e.CommandArgument.ToString());
     }
     if (e.CommandName == "delete")
     {
         int result = new BL.service.Service().Delete(e.CommandArgument.ToString());
         if (result == 1)
         {
             Toast.success(this, "Service deleted successfully");
         }
         else
         {
             Toast.error(this, "An error occured while deleting service");
         }
         List <BL.service.Service> services = new BL.service.Service().SelectByUid(LblUid.Text);
         managelist.DataSource = services;
         managelist.DataBind();
     }
     if (e.CommandName == "view")
     {
         Response.Redirect("~/Views/service/index.aspx?id=" + e.CommandArgument.ToString());
     }
     if (e.CommandName == "favourite")
     {
         string serviceId = e.CommandArgument.ToString();
         List <BL.service.Service> service  = new BL.service.Service().SelectById(serviceId);
         BL.service.Service        curr     = new BL.service.Service();
         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)
             {
                 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 <BL.service.Service> services = new BL.service.Service().SelectByUid(LblUid.Text);
         managelist.DataSource = services;
         managelist.DataBind();
     }
 }