예제 #1
0
        public ActionResult List()
        {
            var account = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
            var context = new UrlDataServiceContext(account.TableEndpoint.ToString(), account.Credentials);

            return View(context.Urls);
        }
예제 #2
0
        public ActionResult Redir(string urlKey)
        {
            var account = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
            var context = new UrlDataServiceContext(account.TableEndpoint.ToString(), account.Credentials)
                              {
                                  ResolveType = s => typeof (Url)
                              };

            var url = (from u in context.Urls
                      where urlKey.Equals(u.Key, StringComparison.InvariantCultureIgnoreCase)
                      select u).SingleOrDefault();

            if (url != null)
                return RedirectPermanent(url.Address);

            return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        }
예제 #3
0
        public ActionResult Add(Url url)
        {
            if (!ModelState.IsValid)
            {
                return View();
            }

            try
            {
                var account = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
                var context = new UrlDataServiceContext(account.TableEndpoint.ToString(), account.Credentials);

                context.AddUrl(url);
            }
            catch (Exception e)
            {
                ModelState.AddModelError("Exception", e.Message);
                return View();
            }

            return RedirectToAction("List");
        }