Пример #1
0
        public int updateAd(int id, AdViewModel model)
        {
            Database s = new Database();

            model = extractData(model);
            s.updateAd(id, model.Title, model.Description, model.Category, model.Color,
                       DateTime.Parse(model.Date).ToString("dd-MM-yyyy"), model.ImageName, model.Organization, model.Reward, model.Type, model.City);
            return(0);
        }
Пример #2
0
 public AdViewModel extractData(AdViewModel model)
 {
     if (model.Organization == null)
     {
         model.Organization = "-";
     }
     if (model.Reward.ToString() == "0")
     {
         model.Reward = 0;
     }
     return(model);
 }
Пример #3
0
        public AdViewModel getAd(int id)
        {
            Database s = new Database();

            if (s.getAd(id).Tables["myTable"].Rows.Count > 0)
            {
                AdViewModel ad = createData(s.getAd(id).Tables["myTable"].Rows[0]);
                return(ad);
            }
            else
            {
                return(null);
            }
        }
Пример #4
0
        public List <AdViewModel> getSimilarAds(int id, string type)
        {
            Database    db    = new Database();
            AdViewModel model = getAd(id);
            Similarity  s     = new Similarity();

            s.currentAd = model;
            int response = s.getAllAds(type);

            if (response == -1)
            {
                return(null);
            }
            else
            {
                return(s.getMatches());
            }
        }
Пример #5
0
        public AdViewModel createData(DataRow r)
        {
            AdViewModel ad = new AdViewModel();

            ad.Title        = r["Title"].ToString();
            ad.Description  = r["description"].ToString();
            ad.ImageName    = r["ImageName"].ToString();
            ad.Reward       = int.Parse(r["Reward"].ToString());
            ad.City         = r["City"].ToString();
            ad.Date         = r["date"].ToString();
            ad.Id           = int.Parse(r["id"].ToString());
            ad.Location     = "{lat:" + r["locationlat"].ToString() + ", lng:" + r["locationlong"].ToString() + "}";
            ad.Type         = r["type"].ToString();
            ad.PostedBy     = r["postedby"].ToString();
            ad.Category     = r["category"].ToString();
            ad.Color        = r["color"].ToString();
            ad.Organization = r["org"].ToString();
            return(ad);
        }
Пример #6
0
        public bool Blocked(string email, AdViewModel ad)
        {
            if (ad.Organization == "-")
            {
                return(false);
            }

            Database  s     = new Database();
            DataTable dt    = s.getOrganizationID(ad.Organization, ad.City).Tables["myTable"];
            int       orgID = int.Parse(dt.Rows[0]["id"].ToString());

            dt = s.checkBlocked(email, orgID).Tables["myTable"];
            if (dt.Rows.Count > 0 && dt.Rows[0] != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #7
0
        public int insertNewAd(AdViewModel model, string postedby)
        {
            Database s = new Database();

            model = extractData(model);
            string latlng = model.Location.Trim('(', ')');

            string[] trimmed = latlng.Split(',');
            string   lat     = trimmed[0];
            string   lng     = trimmed[1].Remove(0, 1);

            if (model.Organization != null)
            {
                model.Organization = s.getOrganizationID(model.Organization, model.City).Tables["myTable"].Rows[0]["id"].ToString();
            }
            int response = s.insertNewAd(model.Title, model.Description, model.Category, model.Color,
                                         DateTime.Parse(model.Date).ToString("dd-MM-yyyy"),
                                         lat, lng, model.ImageName, model.Organization,
                                         model.Reward, model.Type, model.City, postedby);

            return(response);
        }
Пример #8
0
        public List <AdViewModel> getAds(AdViewModel model, string type)
        {
            Database  s  = new Database();
            DataTable dt = s.getAds(model.Id, model.Category, model.Date,
                                    model.Organization, type, model.City).Tables["myTable"];

            if (dt.Rows.Count > 0)
            {
                List <AdViewModel> list = new List <AdViewModel>();
                foreach (DataRow r in dt.Rows)
                {
                    AdViewModel ad = createData(r);
                    list.Add(ad);
                }

                return(list);
            }
            else
            {
                return(null);
            }
        }
Пример #9
0
        public List <AdViewModel> getAllAds(string type, string organization, string category, string color, string city, string q)
        {
            Database           s = new Database();
            List <AdViewModel> ads;
            DataTable          dt = s.getAllAds(type, organization, category, color, city, q).Tables["myTable"];

            if (dt != null)
            {
                ads = new List <AdViewModel>();

                foreach (DataRow r in dt.Rows)
                {
                    AdViewModel ad = createData(r);
                    ads.Add(ad);
                }

                return(ads);
            }
            else
            {
                return(null);
            }
        }
Пример #10
0
        public List <AdViewModel> getAllAds(string type)
        {
            Database           s = new Database();
            List <AdViewModel> ads;
            DataTable          dt = s.getAllAds(type).Tables["myTable"];

            if (dt != null)
            {
                ads = new List <AdViewModel>();
                foreach (DataRow r in dt.Rows)
                {
                    AdViewModel ad = createData(r);
                    ads.Add(ad);
                }

                return(ads);
            }

            else
            {
                return(null);
            }
        }