Exemplo n.º 1
0
 // DELETE api/link/5
 public bool Delete(Link link)
 {
     //var g = Uow.Links.GetById(link.LinkId);
     //Uow.Links.Delete(g);
     //Uow.Commit();
     return true;
 }
Exemplo n.º 2
0
        public Link InsertLink(Guid appId, string secKey, string url)
        {
            var userApplication= Uow.UserApplications.GetById(appId);
            if (userApplication == null) return null;

            if (!CheckSecuretyKey(userApplication, secKey, url)) return null;

            var longUrlHash = _linkCreator.CreateMD5Hash(url);

            //checking if exist
            if (Uow.Links.GetAll().Any(item => item.LongUrlHash == longUrlHash)) return null;

            // New entity
            var info = _linkCreator.AcquireHTML(url);

            var link = new Link()
                {
                    LinkId = Guid.NewGuid(),
                    ShortUrl = string.Format("{0}/{1}", _linkCreator.GetRedirectDomainName(),_linkCreator.CreateShortcut(longUrlHash)),
                    Created = DateTime.Now,
                    Description = _linkCreator.GetMetaDescription(info),
                    Title = _linkCreator.GetMetaTitle(info),
                    LongUrl = url,
                    LongUrlHash = longUrlHash,
                    Group = 0,
                };

            if (userApplication.Links == null)
                userApplication.Links = new List<Link>();
            userApplication.Links.Add(link);

            Uow.Commit();
            return link;
        }
Exemplo n.º 3
0
        // PUT api/link/5
        public void Put(Link link)
        {
            link.LongUrlHash = _linkCreator.CreateMD5Hash(link.LongUrl);

            var g = Uow.Links.GetLinkById(link.LinkId);
            if (g!=null)
            {
                g.Title = link.Title;
            }

            //checking if exist
            if (Uow.Links.GetAll().Any(item => item.LongUrlHash == link.LongUrlHash))
            {
                // Existing entity
                link.IsBroken = !_linkCreator.CheckLinkStatus(new Uri(link.LongUrl));
                link.Created = DateTime.Now;

                //_context.Entry(link).State = EntityState.Modified;
            }
            else
            {
                // New entity
                link.LinkId = Guid.NewGuid();
                link.ShortUrl = string.Format("{0}/{1}", _linkCreator.GetRedirectDomainName(),
                                              _linkCreator.CreateShortcut(link.LongUrlHash));
                link.Created = DateTime.Now;
                string info = _linkCreator.AcquireHTML(link.LongUrl);
                link.Description = _linkCreator.GetMetaDescription(info);
                link.Title = _linkCreator.GetMetaTitle(info);

                Uow.Links.Add(link);
            }
            Uow.Commit();
        }