public IHttpActionResult GetAll()
        {
            using (DyreportalenContext context = new DyreportalenContext())
            {
                List <AdType> adType = context.AdTypes.ToList();

                if (adType.Count == 0)
                {
                    return(NotFound());
                }

                return(Ok(adType.ToList()));
            }
        }
Exemplo n.º 2
0
        public IHttpActionResult GetAll()
        {
            using (DyreportalenContext context = new DyreportalenContext())
            {
                List <Category> categories = context.Categories.ToList();

                if (categories.Count == 0)
                {
                    return(NotFound());
                }

                return(Ok(categories.ToList()));
            }
        }
Exemplo n.º 3
0
        public IHttpActionResult GetAll()
        {
            using (DyreportalenContext context = new DyreportalenContext())
            {
                var race = (from c in context.Races select new { c.Race_id, c.RaceName, c.Category }).ToList();

                if (race.Count == 0)
                {
                    return(NotFound());
                }

                return(Ok(race));
            }
        }
Exemplo n.º 4
0
        public IHttpActionResult GetWithId(int id)
        {
            using (DyreportalenContext context = new DyreportalenContext())
            {
                Category category =
                    (from f in context.Categories
                     where f.Category_id == id
                     select f).SingleOrDefault();

                if (category == null)
                {
                    return(NotFound());
                }

                return(Ok(category));
            }
        }
        public IHttpActionResult GetWithId(int id)
        {
            using (DyreportalenContext context = new DyreportalenContext())
            {
                var ads = context.Ads
                          .Where(x => x.Ad_id == id)
                          .Select(x => new { x.Ad_id, x.Created, x.Title, x.Text, x.City, x.ImageUrl, x.Price, x.Category.Category_Name, x.Race.RaceName, x.AdType.AdTypeName })
                          .SingleOrDefault();

                if (ads == null)
                {
                    return(NotFound());
                }

                return(Ok(ads));
            }
        }
        public IHttpActionResult GetWithId(int id)
        {
            using (DyreportalenContext context = new DyreportalenContext())
            {
                AdType adType =
                    (from f in context.AdTypes
                     where f.AdType_id == id
                     select f).SingleOrDefault();

                if (adType == null)
                {
                    return(NotFound());
                }

                return(Ok(adType));
            }
        }
Exemplo n.º 7
0
        public IHttpActionResult GetWithId(int id)
        {
            using (DyreportalenContext context = new DyreportalenContext())
            {
                var race = context.Races
                           .Where(x => x.Race_id == id)
                           .Select(x => new { x.Race_id, x.RaceName, x.Category })
                           .SingleOrDefault();

                if (race == null)
                {
                    return(NotFound());
                }

                return(Ok(race));
            }
        }
Exemplo n.º 8
0
        public IHttpActionResult GetWithCategoryId(int categoryId)
        {
            using (DyreportalenContext context = new DyreportalenContext())
            {
                var race = context.Races
                           .Where(x => x.Category.Category_id == categoryId)
                           .Select(x => new { x.Race_id, x.RaceName, x.Category.Category_Name })
                           .ToList();


                if (race.Count == 0)
                {
                    return(NotFound());
                }

                return(Ok(race.ToList()));
            }
        }
 public IHttpActionResult PostNew(Ad ad)
 {
     using (DyreportalenContext context = new DyreportalenContext())
     {
         context.Ads.Add(new Ad()
         {
             Ad_id    = ad.Ad_id,
             Created  = ad.Created,
             Title    = ad.Title,
             Text     = ad.Text,
             City     = ad.City,
             ImageUrl = ad.ImageUrl,
             Category = ad.Category,
             Race     = ad.Race,
             AdType   = ad.AdType
         });
         return(InjectTryCatch(context.SaveChanges));
     }
 }
Exemplo n.º 10
0
        public IHttpActionResult GetAll()
        {
            using (DyreportalenContext context = new DyreportalenContext())
            {
                var ads = context.Ads
                          .Select(x => new { x.Ad_id, x.Created, x.Title, x.Text, x.City, x.ImageUrl, x.Price, x.Category.Category_Name, x.Race.RaceName, x.AdType.AdTypeName, x.User })
                          .OrderByDescending(x => x.Created)
                          .ToList();



                if (ads.Count == 0)
                {
                    return(NotFound());
                }

                return(Ok(ads));
            }
        }