Пример #1
0
        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();
            }
        }
Пример #2
0
        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);
        }
Пример #3
0
        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));
        }
Пример #4
0
 public override int GetHashCode()
 {
     return(Shortlink?.GetHashCode() ?? -1);
 }