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); }
public IActionResult Index(Link link) { if (ModelState.IsValid) { _linkRepository.AddLink(link); return(RedirectToAction("LinkComplete")); } return(View()); }
public void AddLinkTest() { var beforeCount = repo.GetAllLinks().Count; repo.AddLink(mock.mockLink); var afterCount = repo.GetAllLinks().Count; Assert.AreEqual(beforeCount + 1, afterCount); }
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)); }
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); }
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)); }); }
public IActionResult Create(Link link) { repository.AddLink(link); return(Redirect("Index")); }
public void AddLink(Link link) { _linkRepository.AddLink(link); }
public IActionResult Post([FromBody] CreateLinkRequest createLink) { return(Ok(repository.AddLink(createLink.GetLink()))); }