Esempio n. 1
0
        public object All()
        {
            DateTime startTime = DateTime.Now;
            List<Ad> ads = new List<Ad>();
            var db = new Database();
            using (var result = db.View("vw_allAds"))
            {
                while (result.Read())
                {

                    ads.Add(new Ad
                    {
                        Id = result.GetInt32(0),
                        UniqueId = result.GetString(1),
                        Title = result.GetString(2),
                        Location = result.GetString(3),
                        AdId = result.GetString(4),
                        Price = result.GetString(5),
                        Seller = result.GetString(6),
                        SellerContact = result.GetString(7),
                        Description = result.GetString(8),
                        Type = result.GetString(9),
                        HasPictures = result.GetBoolean(10),
                        AddedOn = result.GetDateTime(11),
                        Url = result.GetString(12)
                    });
                }

            }
            db.Dispose();

            return new
            {
                TimeStamp = (int)Math.Truncate((DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds),
                TimeConsumed = (DateTime.Now - startTime).TotalMilliseconds,
                TotalRecords = ads.Count,
                Status = "Success",
                Result = ads.OrderBy(x => x.Id).ToList()
            };
        }