public void Get(string pretty) { _logger.LogInformation($"Shortlink name: {pretty} requested at {DateTime.Now}."); if (!string.IsNullOrWhiteSpace(pretty)) { Shortlink sl = AkaHelper.GetShortlinkFromDb(_context, pretty); Response.Redirect(sl.Destination.ToString()); } else { AkaHelper.RedirectToLinkManagement(); } }
public void TestShortlinkModel() { List <Owner> testOwners = new List <Owner>(); testOwners.Add(new Owner("one")); testOwners.Add(new Owner("two")); Uri testUri1 = new Uri("https://tacobell.com/"); Shortlink testLink1 = new Shortlink(1, "tb", testUri1, testOwners); Assert.Equal(1, testLink1.LinkId); Assert.Equal("tb", testLink1.PrettyName); Assert.Equal("https://tacobell.com/", testLink1.Destination.ToString()); Assert.Equal(testOwners, testLink1.Owners); }
public async Task <ActionResult <Shortlink> > PostShortlink([FromForm] ShortlinkRequest?request) { if (request == null) { _logger.LogError($"Received a failed shortlink add/post @ {DateTime.Now}"); return(BadRequest("Shortlink is null.")); } _logger.LogInformation($"Received shortlink creation request: {request}."); // if doesn't exist Shortlink fromDb = AkaHelper.GetShortlinkFromDb(_context, request.PrettyName); if (fromDb == null) { await _context.Shortlinks.AddAsync(new Shortlink(request, _context)); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(Get), new { pretty = request.PrettyName }, request)); } return(Unauthorized(fromDb)); }
public override int GetHashCode() { return(Shortlink?.GetHashCode() ?? -1); }