public async Task<ActionResult> RedirectShortUrl(string hash) { var svc = new ShortUrlService(); var shortUrl = svc.GetShortUrlByHash(hash); return new RedirectResult(shortUrl.Original); }
public async Task<ActionResult> Register(string url) { var svc = new ShortUrlService(); var shortUrl = svc.RegisterUrl(url); return PartialView(shortUrl); }
// 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; }
// 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; }
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(); } }