Exemple #1
0
        public string GetShortLink(string fullLink)
        {
            string cutLink;

            if (IsLinkExist(GetLinkWithProtocol(fullLink), out Link outputLink))
            {
                return(outputLink.CutLink);
            }

            do
            {
                cutLink = GetShortLink();
            } while (Db.IsShortLinkExist(cutLink));

            var newLink = new Link()
            {
                CreateTime = DateTime.Now,
                FullLink   = GetLinkWithProtocol(fullLink),
                CutLink    = cutLink,
                ViewCount  = 0
            };

            Db.AddLink(newLink);

            return(newLink.CutLink);
        }
Exemple #2
0
 public IActionResult Index(Link link)
 {
     if (ModelState.IsValid)
     {
         _linkRepository.AddLink(link);
         return(RedirectToAction("LinkComplete"));
     }
     return(View());
 }
Exemple #3
0
        public void AddLinkTest()
        {
            var beforeCount = repo.GetAllLinks().Count;

            repo.AddLink(mock.mockLink);
            var afterCount = repo.GetAllLinks().Count;

            Assert.AreEqual(beforeCount + 1, afterCount);
        }
Exemple #4
0
 public HttpResponseMessage Post(Link link)
 {
     if (base.ModelState.IsValid)
     {
         _linkRepo.AddLink(link);
         return(new HttpResponseMessage(HttpStatusCode.OK));
     }
     return(base.Request.CreateErrorResponse(HttpStatusCode.BadRequest, base.ModelState));
 }
Exemple #5
0
 public async Task <ActionResult> Index(string link)
 {
     if (await _linkRepository.AddLink(link))
     {
         return(View(await _linkRepository.GetLinks()));
     }
     else
     {
         //Logger.Log();
         return(View(await _linkRepository.GetLinks()));
     }
 }
 public void AddLink(LinkModel link)
 {
     link.Url = validateUrl(link.Url);
     _linkRepository.AddLink((LinkEntity)link);
 }
Exemple #7
0
        public MutationObject(
            ILinkRepository linkRepository,
            IUserRepository userRepository,
            IVoteRepository voteRepository)
        {
            this.Name        = "Mutation";
            this.Description = "The mutation type, represents all updates we can make to our data.";

            this.FieldAsync <LinkType, Link>(
                "createLink",
                "Create a new link.",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <LinkInputObject> >()
            {
                Name        = "link",
                Description = "The link you want to create.",
            }),
                resolve: context =>
            {
                var link = context.GetArgument <Link>("link");
                return(linkRepository.AddLink(link));
            });

            this.FieldAsync <LinkType, Link>(
                "deleteLink",
                "Delete an existent link.",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IntGraphType> >()
            {
                Name        = "id",
                Description = "The id of the link to delete.",
            }),
                resolve: context => linkRepository.DeleteLink(context.GetArgument <int>("id")));

            this.FieldAsync <UserType, User>(
                "createUser",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <UserInputObject> > {
                Name = "user"
            }
                    ),
                resolve: context =>
            {
                var user = context.GetArgument <User>("user");
                return(userRepository.AddUser(user));
            });

            this.FieldAsync <SigninUserPayloadType, SigninUserPayload>(
                "signinUser",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <SigninUserInputObject> > {
                Name = "signinUser"
            }
                    ),
                resolve: context =>
            {
                var signinUser = context.GetArgument <SigninUser>("signinUser");
                return(userRepository.SigninUser(signinUser));
            });

            this.FieldAsync <VoteType, Vote>(
                "createVote",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "userId"
            },
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "linkId"
            }
                    ),
                resolve: context =>
            {
                int userId = context.GetArgument <int>("userId");
                int linkId = context.GetArgument <int>("linkId");
                return(voteRepository.AddVote(userId, linkId, context.CancellationToken));
            });
        }
Exemple #8
0
 public IActionResult Create(Link link)
 {
     repository.AddLink(link);
     return(Redirect("Index"));
 }
Exemple #9
0
 public void AddLink(Link link)
 {
     _linkRepository.AddLink(link);
 }
 public IActionResult Post([FromBody] CreateLinkRequest createLink)
 {
     return(Ok(repository.AddLink(createLink.GetLink())));
 }