Example #1
0
        public URL InsertNewURL(URL urldata)
        {
            if (IsAliasExistsForThisOriginalURL(urldata))
            {
                urldata.Status = Status.AliasExists;
            }
            else
            {
                if (IsAlreadyShortened(urldata))
                {
                    urldata.Status = Status.URLExists;
                    urldata.Id = GetIdByOriginalURL(urldata.Original).Id;
                }
                else
                {
                    urldata.Status = Status.NewURL;

                    if (urldata.Id == String.Empty)
                        urldata.Id = AlphabetTest.Encode(urlDataSet.GetNextId());

                    urlDataSet.PersistUrl(urldata);
                }
            }

            return urldata;
        }
Example #2
0
        public bool AliasExists(URL urldata)
        {
            if (String.IsNullOrEmpty(urldata.Id))
                return false;

            return (from element in urlDataSet.Descendants("url")
                    where element.Attribute("id").Value == urldata.Id
                    select element.Attribute("id").Value).Count() > 0;
        }
Example #3
0
 private bool IsAlreadyShortened(URL urldata)
 {
     return urlDataSet.OriginalUrlExists(urldata);
 }
Example #4
0
 private bool IsAliasExistsForThisOriginalURL(URL urldata)
 {
     return urlDataSet.AliasExists(urldata);
 }
 public ActionResult Default(URL url)
 {
     return View(url);
 }
 public ActionResult Create(URL url)
 {
     return View(url);
 }
 public ActionResult Copy(URL url)
 {
     return View(url);
 }
Example #8
0
        public void PersistUrl(URL urldata)
        {
            var doc = urlDataSet;
            var root = new XElement("url");
            root.Add(new XAttribute("original", urldata.Original));
            root.Add(new XAttribute("id", urldata.Id));
            root.Add(new XAttribute("created", urldata.Created));
            root.Add(new XAttribute("createdby", urldata.CreatedBy));
            root.Add(new XAttribute("hits", urldata.Hits));
            doc.Element("root").Add(root);

            var nextIdValue = GetNextId() + 1;
            doc.Root.SetAttributeValue("nextIdValue", nextIdValue);

            doc.Save(xmlFile);
        }
Example #9
0
 public bool OriginalUrlExists(URL urldata)
 {
     return (from element in urlDataSet.Descendants("url")
             where element.Attribute("original").Value == urldata.Original
             select element.Attribute("original").Value).Count() > 0;
 }