Пример #1
0
        public async Task<ActionResult> RedirectShortUrl(string hash)
        {
            var svc = new ShortUrlService();
            var shortUrl = svc.GetShortUrlByHash(hash);

            return new RedirectResult(shortUrl.Original);
        }
Пример #2
0
        public async Task<ActionResult> Register(string url)
        {
            var svc = new ShortUrlService();
            var shortUrl = svc.RegisterUrl(url);

            return PartialView(shortUrl);
        }
Пример #3
0
 // GET api/Shortner/5
 public ShortUrl Get(string id)
 {
     var svc = new ShortUrlService();
     var shortUrl = svc.GetShortUrlByHash(id);
     if (shortUrl == null)
     {
         throw new HttpResponseException(HttpStatusCode.NotFound);
     }
     return shortUrl;
 }
Пример #4
0
        // POST api/Shortner
        public ShortUrl Post([FromBody]PostShortUrlRequest model)
        {
            if (model == null || model.Url.IsNullOrWhiteSpace())
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            var svc = new ShortUrlService();
            var shortUrl = svc.RegisterUrl(model.Url);

            return shortUrl;
        }
Пример #5
0
        public void SetUp()
        {
            sut = new ShortUrlService();

            using (var db = new AppDbContext())
            {

                db.ShortUrls.RemoveRange(db.ShortUrls.ToList());

                db.ShortUrls.Add(new ShortUrl()
                {
                    Original = "http://nakaji.hatenablog.com/",
                    Short = "http://nkd.jp/129f5f",
                    Hash = "129f5f"
                });
                db.SaveChanges();
            }
        }