Exemplo n.º 1
0
 public static bool AuthenticateLoginTicket(string userName, string authenticationHash)
 {
     using (CuplexLib.Linq.DataContext db = CuplexLib.Linq.DataContext.Create())
     {
         return(db.Authentications.Where(a => a.UserName == userName && a.AuthenticationHash == authenticationHash && a.Expires > DateTime.Now).Any());
     }
 }
Exemplo n.º 2
0
 public static void DeleteMany(List <int> linkSuggestionRefList)
 {
     using (CLinq.DataContext db = CLinq.DataContext.Create())
     {
         db.LinkSuggestions.DeleteBatch(ls => linkSuggestionRefList.Contains(ls.LinkSuggestionRef));
     }
 }
Exemplo n.º 3
0
    public static string RateLink(int LinkRef, int rating)
    {
        CuplexLib.User user = HttpContext.Current.Session["User"] as CuplexLib.User;
        if (user == null || rating < 1 || rating > 5)
        {
            return("");
        }

        using (CLinq.DataContext db = CLinq.DataContext.Create())
        {
            if (!db.UserToLinks.Where(utl => utl.LinkRef == LinkRef && utl.UserRef == user.UserRef).Any() && db.Links.Where(l => l.LinkRef == LinkRef).Any())
            {
                CLinq.UserToLink userToLink = new CuplexLib.Linq.UserToLink();
                userToLink.UserRef = user.UserRef;
                userToLink.LinkRef = LinkRef;
                userToLink.Rating  = rating;
                db.UserToLinks.InsertOnSubmit(userToLink);
                db.SubmitChanges();

                //Recalculate rating on Link
                var linkRatingQuery =
                    from utl in db.UserToLinks
                    where utl.LinkRef == LinkRef
                    select utl.Rating;

                var linkToUpdate = db.Links.Where(l => l.LinkRef == LinkRef).Single();
                linkToUpdate.Rating = (double)linkRatingQuery.Sum() / (double)linkRatingQuery.Count();
                db.SubmitChanges();
            }
        }
        return("");
    }
Exemplo n.º 4
0
        public void Save()
        {
            try
            {
                using (CLinq.DataContext db = CLinq.DataContext.Create())
                {
                    if (this.CommentRef == 0)
                    {
                        CLinq.Comment comment = new CuplexLib.Linq.Comment();
                        comment.CommentDate = this.CommentDate;
                        comment.CommentText = this.CommentText;
                        comment.LinkRef     = this.LinkRef;
                        comment.UserRef     = this.UserRef;

                        db.Comments.InsertOnSubmit(comment);
                    }
                    else
                    {
                        CLinq.Comment comment = db.Comments.Where(c => c.CommentRef == this.CommentRef).SingleOrDefault();
                        if (comment == null)
                        {
                            return;
                        }

                        comment.CommentDate = this.CommentDate;
                        comment.CommentText = this.CommentText;
                        comment.LinkRef     = this.LinkRef;
                        comment.UserRef     = this.UserRef;
                    }
                    db.SubmitChanges();
                }
            }
            catch { }
        }
Exemplo n.º 5
0
        public static void CreateLinksFromLinkSuggestionList(List <int> linkSuggestionRefList, bool useLinkSuggestionDate)
        {
            using (CLinq.DataContext db = CLinq.DataContext.Create())
            {
                var linkSuggestionList = db.LinkSuggestions.Where(ls => linkSuggestionRefList.Contains(ls.LinkSuggestionRef)).ToList();

                foreach (var linkSuggestion in linkSuggestionList)
                {
                    CLinq.Link link = new CuplexLib.Linq.Link();
                    link.CategoryRef = linkSuggestion.CategoryRef;
                    if (useLinkSuggestionDate)
                    {
                        link.LinkDate = linkSuggestion.LinkSuggestionDate;
                    }
                    else
                    {
                        link.LinkDate = DateTime.Now;
                    }
                    link.LinkName = linkSuggestion.Description;
                    link.LinkUrl  = linkSuggestion.LinkUrl;
                    link.UserRef  = linkSuggestion.UserRef;

                    db.Links.InsertOnSubmit(link);
                }
                db.SubmitChanges();
            }
        }
Exemplo n.º 6
0
    public void LoadDataFromSearch(string searchText, List <CLinq.Link> linkList, CLinq.DataContext db)
    {
        CuplexLib.User user = HttpContext.Current.Session["User"] as CuplexLib.User;

        foreach (var lnk in linkList)
        {
            LinkDataItem linkDataItem = new LinkDataItem();
            linkDataItem.LinkRef  = lnk.LinkRef;
            linkDataItem.Category = lnk.Category.CategoryName;
            linkDataItem.Clicks   = lnk.Clicks;
            linkDataItem.LinkName = lnk.LinkName;
            linkDataItem.LinkUrl  = lnk.LinkUrl;
            linkDataItem.Rating   = lnk.Rating;
            if (lnk.UserRef != null)
            {
                linkDataItem.UserName = lnk.User.UserName;
            }

            if (user != null)
            {
                linkDataItem.HasVoted = db.UserToLinks.Where(utl => utl.LinkRef == lnk.LinkRef && utl.UserRef == user.UserRef).Any();
            }

            linkDataItem.NumberOfComments = lnk.Comments.Count;

            linkDataItemList.Add(linkDataItem);
        }
        IsDisplayingSearchResult = true;
        SearchString             = searchText;
    }
Exemplo n.º 7
0
        public static Link GetOne(int linkRef)
        {
            Link link = new Link();

            using (CLinq.DataContext db = CLinq.DataContext.Create())
            {
                CLinq.Link dbLink = db.Links.Where(l => l.LinkRef == linkRef).SingleOrDefault();
                if (dbLink == null)
                {
                    return(null);
                }

                link.LinkRef     = dbLink.LinkRef;
                link.CategoryRef = dbLink.CategoryRef;
                link.Clicks      = dbLink.Clicks;
                link.LinkDate    = dbLink.LinkDate;
                link.LinkName    = dbLink.LinkName;
                link.LinkUrl     = dbLink.LinkUrl;
                link.Rating      = dbLink.Rating;
                link.UserRef     = dbLink.UserRef;
                if (link.UserRef != null)
                {
                    link.UserName = dbLink.User.UserName;
                }
            }
            return(link);
        }
Exemplo n.º 8
0
    protected void SaveButton_Clicked(object sender, EventArgs e)
    {
        Table settingsTable = GetPageControlById(this.Page, "SettingsTable") as Table;

        if (settingsTable == null)
        {
            return;
        }

        using (CuplexLib.Linq.DataContext db = CuplexLib.Linq.DataContext.Create())
        {
            List <Control> textBoxList  = GetPageControlsByType(settingsTable, typeof(TextBox));
            List <Control> checkBoxList = GetPageControlsByType(settingsTable, typeof(CheckBox));
            Dictionary <string, CuplexLib.Linq.Setting> dbSettingsDictionary = db.Settings.ToDictionary(s => s.KeyType);
            List <string> KeyTypeList = new List <string>();

            foreach (Control ctrl in textBoxList)
            {
                TextBox settingsTextBox = ctrl as TextBox;
                if (settingsTextBox != null && settingsTextBox.Attributes["KeyType"] != null)
                {
                    string keyType = settingsTextBox.Attributes["KeyType"];
                    if (dbSettingsDictionary.ContainsKey(keyType))
                    {
                        //Verify that the correct data type is used
                        if (Settings.IsCorrectDataType(settingsTextBox.Text, dbSettingsDictionary[keyType].DataType))
                        {
                            dbSettingsDictionary[keyType].Value = settingsTextBox.Text;
                            KeyTypeList.Add(keyType);
                        }
                        else
                        {
                            settingsTextBox.Text = dbSettingsDictionary[keyType].Value;
                        }
                    }
                }
            }
            foreach (Control ctrl in checkBoxList)
            {
                CheckBox settingsCheckBox = ctrl as CheckBox;
                if (settingsCheckBox != null && settingsCheckBox.Attributes["KeyType"] != null)
                {
                    string keyType = settingsCheckBox.Attributes["KeyType"];
                    if (dbSettingsDictionary.ContainsKey(keyType))
                    {
                        //Verify that the correct data type is used
                        if (dbSettingsDictionary[keyType].DataType.HasValue && dbSettingsDictionary[keyType].DataType.Value == SettingsDataType.Boolean)
                        {
                            dbSettingsDictionary[keyType].Value = (settingsCheckBox.Checked ? "1" : "0");
                            KeyTypeList.Add(keyType);
                        }
                    }
                }
            }
            db.SubmitChanges();
            Settings.ClearCache(KeyTypeList);
        }
    }
Exemplo n.º 9
0
 public static void DeleteMany(List <int> linkRefList)
 {
     using (CLinq.DataContext db = CLinq.DataContext.Create())
     {
         db.UserToLinks.DeleteBatch(utl => linkRefList.Contains(utl.LinkRef));
         db.Comments.DeleteBatch(c => linkRefList.Contains(c.LinkRef));
         db.Links.DeleteBatch(l => linkRefList.Contains(l.LinkRef));
     }
 }
Exemplo n.º 10
0
        public static List <Category> GetCategoryList()
        {
            using (CLinq.DataContext db = CLinq.DataContext.Create())
            {
                var categoryQuery =
                    from c in db.Categories
                    orderby c.CategoryName
                    select new Category {
                    CategoryRef = c.CategoryRef, CategoryName = c.CategoryName
                };

                return(categoryQuery.ToList());
            }
        }
Exemplo n.º 11
0
    public static void LogoutUser()
    {
        string userName = HttpContext.Current.Request.Cookies["UserId"].Value;

        HttpContext.Current.Response.Cookies.Remove("UserId");
        HttpContext.Current.Response.Cookies.Remove("CuplexAuthCookie");
        HttpContext.Current.Session.Clear();

        using (CuplexLib.Linq.DataContext db = CuplexLib.Linq.DataContext.Create())
        {
            var authList = db.Authentications.Where(a => a.UserName == userName).ToList();
            db.Authentications.DeleteAllOnSubmit(authList);
            db.SubmitChanges();
        }
    }
Exemplo n.º 12
0
    private static string CreateAuthenticationTicket(string userName)
    {
        string hashData       = Utils.GetMd5Hash("NA5ps2hRjxMcEaQJwpw4QXZVGJP4MOxf" + DateTime.Now.Ticks + userName);
        int    autoLoginHours = GetAutoLoginTime();

        using (CuplexLib.Linq.DataContext db = CuplexLib.Linq.DataContext.Create())
        {
            CuplexLib.Linq.Authentication auth = new CuplexLib.Linq.Authentication();
            auth.AuthenticationHash = hashData;
            auth.UserName           = userName;
            auth.Expires            = DateTime.Now.AddHours(autoLoginHours);
            db.Authentications.InsertOnSubmit(auth);
            db.SubmitChanges();

            return(hashData);
        }
    }
Exemplo n.º 13
0
        public static void SaveToEventLog(string eventText, EventLogType eventLogType, int?userRef)
        {
            try
            {
                using (CLinq.DataContext db = CLinq.DataContext.Create())
                {
                    CLinq.EventLog eventLog = new CuplexLib.Linq.EventLog();
                    eventLog.EventLogDate = DateTime.Now;
                    eventLog.EventText    = eventText;
                    eventLog.EventType    = (int)eventLogType;
                    eventLog.UserRef      = userRef;

                    db.EventLogs.InsertOnSubmit(eventLog);
                    db.SubmitChanges();
                }
            }
            catch { }
        }
Exemplo n.º 14
0
        public static List <Comment> GetCommentListForLink(int linkRef)
        {
            using (CLinq.DataContext db = CLinq.DataContext.Create())
            {
                var commentQuery =
                    from c in db.Comments
                    where c.LinkRef == linkRef
                    orderby c.CommentDate
                    select new Comment
                {
                    CommentRef  = c.CommentRef,
                    CommentDate = c.CommentDate,
                    CommentText = c.CommentText,
                    LinkRef     = c.LinkRef,
                    UserRef     = c.UserRef,
                    UserName    = c.User.UserName
                };

                return(commentQuery.ToList());
            }
        }
Exemplo n.º 15
0
        public static LinkSuggestion GetOne(int linkSuggestionRef)
        {
            LinkSuggestion linkSuggestion = new LinkSuggestion();

            using (CLinq.DataContext db = CLinq.DataContext.Create())
            {
                CLinq.LinkSuggestion li = db.LinkSuggestions.Where(l => l.LinkSuggestionRef == linkSuggestionRef).SingleOrDefault();
                if (li == null)
                {
                    return(null);
                }

                linkSuggestion.LinkSuggestionRef  = li.LinkSuggestionRef;
                linkSuggestion.CategoryRef        = li.CategoryRef;
                linkSuggestion.Description        = li.Description;
                linkSuggestion.LinkSuggestionDate = li.LinkSuggestionDate;
                linkSuggestion.LinkUrl            = li.LinkUrl;
                linkSuggestion.UserRef            = li.UserRef;
            }

            return(linkSuggestion);
        }
Exemplo n.º 16
0
        public void Save()
        {
            using (CLinq.DataContext db = CLinq.DataContext.Create())
            {
                CLinq.Link link;
                if (this.LinkRef > 0)
                {
                    link = db.Links.Where(l => l.LinkRef == this.LinkRef).SingleOrDefault();
                    if (link == null)
                    {
                        return;
                    }

                    link.CategoryRef = this.CategoryRef;
                    link.Clicks      = this.Clicks;
                    link.LinkDate    = this.LinkDate;
                    link.LinkName    = this.LinkName;
                    link.LinkUrl     = this.LinkUrl;
                    link.Rating      = this.Rating;
                    link.UserRef     = this.UserRef;
                }
                else
                {
                    link             = new CuplexLib.Linq.Link();
                    link.CategoryRef = this.CategoryRef;
                    link.Clicks      = this.Clicks;
                    link.LinkDate    = this.LinkDate;
                    link.LinkName    = this.LinkName;
                    link.LinkUrl     = this.LinkUrl;
                    link.Rating      = this.Rating;
                    link.UserRef     = this.UserRef;

                    db.Links.InsertOnSubmit(link);
                }

                db.SubmitChanges();
            }
        }
Exemplo n.º 17
0
    public void LoadData(DateTime linkDate)
    {
        CuplexLib.User user = HttpContext.Current.Session["User"] as CuplexLib.User;
        LinkDataListDate = linkDate;
        using (CLinq.DataContext db = CLinq.DataContext.Create())
        {
            var linkQuery =
                from lnk in db.Links
                where lnk.LinkDate.Date == linkDate
                orderby lnk.LinkDate descending
                select lnk;

            List <CLinq.Link> linkList = linkQuery.ToList();
            foreach (var lnk in linkList)
            {
                LinkDataItem linkDataItem = new LinkDataItem();
                linkDataItem.LinkRef  = lnk.LinkRef;
                linkDataItem.Category = lnk.Category.CategoryName;
                linkDataItem.Clicks   = lnk.Clicks;
                linkDataItem.LinkName = lnk.LinkName;
                linkDataItem.LinkUrl  = lnk.LinkUrl;
                linkDataItem.Rating   = lnk.Rating;
                if (lnk.UserRef != null)
                {
                    linkDataItem.UserName = lnk.User.UserName;
                }

                if (user != null)
                {
                    linkDataItem.HasVoted = db.UserToLinks.Where(utl => utl.LinkRef == lnk.LinkRef && utl.UserRef == user.UserRef).Any();
                }

                linkDataItem.NumberOfComments = lnk.Comments.Count;

                linkDataItemList.Add(linkDataItem);
            }
        }
    }
Exemplo n.º 18
0
        public void Save()
        {
            try
            {
                using (CLinq.DataContext db = CLinq.DataContext.Create())
                {
                    if (this.LinkSuggestionRef == 0)
                    {
                        CLinq.LinkSuggestion link = new CuplexLib.Linq.LinkSuggestion();
                        link.CategoryRef        = this.CategoryRef;
                        link.Description        = this.Description;
                        link.LinkUrl            = this.LinkUrl;
                        link.UserRef            = this.UserRef;
                        link.LinkSuggestionDate = this.LinkSuggestionDate;

                        db.LinkSuggestions.InsertOnSubmit(link);
                    }
                    else
                    {
                        CLinq.LinkSuggestion link = db.LinkSuggestions.Where(l => l.LinkSuggestionRef == this.LinkSuggestionRef).SingleOrDefault();
                        if (link == null)
                        {
                            return;
                        }

                        link.CategoryRef        = this.CategoryRef;
                        link.Description        = this.Description;
                        link.LinkUrl            = this.LinkUrl;
                        link.UserRef            = this.UserRef;
                        link.LinkSuggestionDate = this.LinkSuggestionDate;
                    }
                    db.SubmitChanges();
                }
            }
            catch { }
        }
Exemplo n.º 19
0
    protected override void OnPreRender(EventArgs e)
    {
        if (Session["SearchData"] is ContentList)
        {
            ContentList searchContentList = Session["SearchData"] as ContentList;
            this.Controls.Clear();
            this.Controls.Add(searchContentList);
            Session["SearchData"] = null;
            return;
        }

        int             pageId       = 1;
        List <DateTime> linkDateList = new List <DateTime>();

        //Try Parse PageId
        if (!string.IsNullOrEmpty(Request.QueryString["pageId"]))
        {
            int.TryParse(Request.QueryString["pageId"], out pageId);
            if (pageId < 1)
            {
                pageId = 1;
            }
        }


        using (CLinq.DataContext db = CLinq.DataContext.Create())
        {
            var dateQuery =
                from l in db.Links
                group l by l.LinkDate.Date into lg
                orderby lg.Key descending
                select lg.Key;

            int maxPage = Math.Max(dateQuery.Count() / 3, 1) + 1;

            if (pageId == 1)
            {
                linkDateList = dateQuery.Take(3).ToList();
            }
            else if (pageId > maxPage)
            {
                Response.Redirect(cms.Current.GetRootPath);
            }
            else
            {
                linkDateList = dateQuery.Take(3 * pageId).Skip((3 * pageId) - 3).ToList();
            }
        }

        this.Controls.Clear();
        foreach (DateTime linkDate in linkDateList)
        {
            ContentList contentList = new ContentList();
            contentList.LoadData(linkDate);
            this.Controls.Add(contentList);
        }

        if (this.ShowPageLinks)
        {
            if (pageId > 1)
            {
                this.Controls.Add(GetNavigationLink(false, pageId));
            }
            this.Controls.Add(GetNavigationLink(true, pageId));
        }
    }
Exemplo n.º 20
0
    private void RenderSettingsTable()
    {
        using (CuplexLib.Linq.DataContext db = CuplexLib.Linq.DataContext.Create())
        {
            List <CuplexLib.Linq.Setting> settingsList = db.Settings.ToList();

            Table settingsTable = new Table();
            settingsTable.ID          = "SettingsTable";
            settingsTable.CellPadding = 0;
            settingsTable.CellSpacing = 0;
            settingsTable.CssClass    = "settingsTable";
            SettingsPanel.Controls.Add(settingsTable);

            TableHeaderRow  headerRow  = new TableHeaderRow();
            TableHeaderCell headerCell = new TableHeaderCell();

            headerCell.Text = "KeyType";
            headerRow.Cells.Add(headerCell);

            headerCell      = new TableHeaderCell();
            headerCell.Text = "Description";
            headerRow.Cells.Add(headerCell);

            headerCell      = new TableHeaderCell();
            headerCell.Text = "Value";
            headerRow.Cells.Add(headerCell);

            settingsTable.Rows.Add(headerRow);

            foreach (var setting in settingsList)
            {
                TableRow  row  = new TableRow();
                TableCell cell = new TableCell();

                cell.CssClass = "settTblCellFixedData label";
                cell.Text     = setting.KeyType;
                row.Cells.Add(cell);

                cell          = new TableCell();
                cell.CssClass = "settTblCellFixedData";
                cell.Text     = setting.Description;
                row.Cells.Add(cell);

                cell = new TableCell();

                if (setting.DataType.HasValue && setting.DataType.Value == SettingsDataType.Boolean)
                {
                    CheckBox settingsCheckbox = new CheckBox();
                    settingsCheckbox.CssClass = "settTblChkBox";
                    settingsCheckbox.Attributes.Add("KeyType", setting.KeyType);
                    if (!IsPostBack)
                    {
                        settingsCheckbox.Checked = setting.Value == "1";
                    }
                    cell.Controls.Add(settingsCheckbox);
                }
                else
                {
                    TextBox settingsValueTextBox = new TextBox();
                    settingsValueTextBox.Style.Add(HtmlTextWriterStyle.Width, "96%");
                    settingsValueTextBox.Attributes.Add("KeyType", setting.KeyType);
                    if (!IsPostBack)
                    {
                        settingsValueTextBox.Text = setting.Value;
                    }
                    cell.Controls.Add(settingsValueTextBox);
                }

                row.Cells.Add(cell);
                settingsTable.Rows.Add(row);
            }
        }
    }