Example #1
0
        public JsonResponse ViewAllAdvertisementsByClient(JsonRequest request)
        {
            try
            {
                var client = request.ClientCollection.FirstOrDefault();
                if(client == null)
                    return new JsonResponse { Message = "The client was not defined!", IsSuccessFull = false };

                var advertisementCollection = DatabaseContext.AdvertisementCollection.Include(x => x.Client).Include(x => x.Category).ToList();
                advertisementCollection.Where(x => x.Client.Id == client.Id).ToList();

                if (advertisementCollection.FirstOrDefault() == null)
                    return new JsonResponse { Message = string.Format("No Advertisements in the database for client {0}!", client.Name), IsSuccessFull = false };

                var response = new JsonResponse
                {
                    IsSuccessFull = true,
                    Message = string.Format("Found {0} entries in the database!", advertisementCollection.Count),
                    AdvertisementCollection = advertisementCollection
                };
                return response;
            }
            catch (Exception e)
            {
                return new JsonResponse { Message = e.Message, Exception = e };
            }
        }
Example #2
0
        /// <summary>
        /// Views all advertisements.
        /// </summary>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public JsonResponse ViewAllAdvertisements()
        {
            try
            {
                var advertisementCollection = DatabaseContext.AdvertisementCollection.Include(x => x.Client).Include(x => x.Category).ToList();

                if (advertisementCollection.FirstOrDefault() == null)
                    return new JsonResponse { Message = "No Advertisements in the database!", IsSuccessFull = false };

                var response = new JsonResponse
                {
                    IsSuccessFull = true,
                    Message = string.Format("Found {0} entries in the database!", advertisementCollection.Count),
                    AdvertisementCollection = advertisementCollection
                };
                return response;
            }
            catch (Exception e)
            {
                return new JsonResponse { Message = e.Message, Exception = e };
            }
        }