Exemple #1
0
        public static List <Object> GetLastNotifications(long userId, string db, int offset = 1, int limit = 20)
        {
            List <object> notifications = new List <object>();
            SqlConnection myConnection  = new SqlConnection(db);

            try
            {
                myConnection.Open();
                string query = "EXEC [stp_SS_GetLastNotifications] @userId=" + userId + ",@offset=" + offset + ",@limit=" + limit;
                using (SqlDataAdapter adp = new SqlDataAdapter(query, myConnection))
                {
                    SqlCommand cmd = adp.SelectCommand;
                    cmd.CommandTimeout = 300000;
                    System.Data.SqlClient.SqlDataReader dr = cmd.ExecuteReader();

                    while (dr.Read())
                    {
                        NotificationType type = (NotificationType)int.Parse(dr["Type"].ToString());
                        if (type == NotificationType.Contest)
                        {
                            Contest contest = new Contest();
                            contest.Name  = dr["contestName"].ToString();
                            contest.TagId = int.Parse(dr["TagId"].ToString());
                            contest.Image = "https://s3-us-west-2.amazonaws.com/fkcontentpics/" + contest.Name + "_small.png";
                            contest.Type  = type;
                            DateTime CreateTime = DateTime.Parse(dr["CreateDate"].ToString());
                            contest.CreateTime = (CreateTime - new DateTime(1970, 1, 1)).TotalSeconds;
                            notifications.Add(contest);
                        }

                        else
                        {
                            Notification notification = new Notification();
                            notification.Type        = type;
                            notification.User.userId = userId;

                            notification.Subject.userId      = long.Parse(dr["SubjectId"].ToString());
                            notification.Subject.pic         = dr["Pic"].ToString();
                            notification.Subject.userName    = dr["UserName"].ToString();
                            notification.Subject.IsFollowing = int.Parse(dr["following"].ToString());

                            if (notification.Type != NotificationType.FollowUser)
                            {
                                long lookId = long.Parse(dr["LookId"].ToString());
                                notification.Look = Look.GetLookById(lookId, userId, db);
                            }

                            if (notification.Type == NotificationType.CreateLookTag)
                            {
                                notification.Tag.id   = long.Parse(dr["TagId"].ToString());
                                notification.Tag.name = dr["contestName"].ToString();
                            }

                            DateTime CreateTime = DateTime.Parse(dr["CreateDate"].ToString());
                            notification.CreateTime = (CreateTime - new DateTime(1970, 1, 1)).TotalSeconds;
                            notifications.Add(notification);
                        }
                    }
                }
            }
            finally
            {
                myConnection.Close();
            }

            return(notifications);
        }