示例#1
0
        public ActionResult Index()
        {
            //Load data in recent URL in grid
            ShortenURLEntities ctx = new ShortenURLEntities();
            var data = ctx.HistoryURL.SqlQuery("SELECT TOP 100 * FROM HistoryURL ORDER BY DateCreated DESC");

            ViewBag.userdetails = data;

            return(View());
        }
示例#2
0
        public static void InsertData(string url, string shortUrl)
        {
            try
            {
                using (var ctx = new ShortenURLEntities())
                {
                    var param1 = new SqlParameter("@Url", url);
                    var param2 = new SqlParameter(@"Short", shortUrl);

                    var result = ctx.Database.ExecuteSqlCommand("usp_InsertUrl @Url, @Short", param1, param2);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#3
0
        public static IEnumerable <HistoryURL> UrlRecent()
        {
            try
            {
                using (var ctx = new ShortenURLEntities())
                {
                    List <HistoryURL> subquery = ctx.HistoryURL
                                                 .OrderByDescending(h => h.DateCreated)
                                                 .Take(100).ToList();

                    if (subquery != null)
                    {
                        return(subquery);
                    }
                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }