Exemple #1
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("");
    }
Exemple #2
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 { }
        }
Exemple #3
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();
            }
        }
    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);
        }
    }
    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();
        }
    }
    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);
        }
    }
Exemple #7
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 { }
        }
Exemple #8
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();
            }
        }
Exemple #9
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 { }
        }