예제 #1
0
        //Error	1	Type 'Ticker.Controllers.PlaylistItemsController' already defines a member called 'GetPlaylistItems' with the same parameter types	C:\Users\areich\Documents\Visual Studio 2012\Projects\Ticker\Ticker.Web\Controllers\PlaylistItemsController.cs	358	37	Ticker.Web
        //public IEnumerable<dynamic> GetPlaylistItems(int entryID, string ObjectType)
        //{
        //    return GetPlaylistItems(0, entryID, ObjectType);
        //}

        public IEnumerable <dynamic> GetPlaylistItems(int cid, int ID, string ObjectType)//,[ModelBinder(typeof(Ticker.ModelBinders.DataSourceRequestModelBinder))] DataSourceRequest request)
        {
            Utilities.LoadClientShares(db, cid);

            var ret       = new List <dynamic>();
            var retGroups = new List <dynamic>();

            switch (ObjectType)
            {
            case "Group":
                return(db.Notes.Where(gn => gn.GroupID == ID).OrderBy(on => on.SortOrder)
                       .Select(on => new { on.ID, on.Note1, on.UserID, on.LastUpdated, on.GroupID, on.SortOrder })  //first trip is pure ef and can't convert dt to string (See also http://stackoverflow.com/questions/5370402/entity-framework-4-linq-how-to-convert-from-datetime-to-string-in-a-query)
                       .AsEnumerable()
                       .Select(n => new
                {
                    n.ID,
                    Name = n.Note1,
                    Note = (n.UserID != null && n.UserID != 0 && db.Users.Where(u => u.UserID == n.UserID).Count() != 0 ? "last updated by " + db.Users.Where(u => u.UserID == n.UserID).FirstOrDefault().FirstName + " " + db.Users.Where(u => u.UserID == n.UserID).FirstOrDefault().LastName + ", " + n.LastUpdated.ToString() : ""),
                    ParentID = n.GroupID,
                    n.SortOrder,
                    ObjectType = "GroupNote"
                }));

            case "Game":
            {
                foreach (Client c in db.Clients.Single(s => s.ID == cid).Clients)
                {
                    retGroups = retGroups.Concat(db.spTICK_GameNotes_GetByGameID(gameID: ID, clientID: c.ID)
                                                 .Select(on => new { on.ID, on.Note, on.UserID, on.LastUpdated, on.GameID, on.SortOrder }) //first trip is pure ef and can't convert dt to string (See also http://stackoverflow.com/questions/5370402/entity-framework-4-linq-how-to-convert-from-datetime-to-string-in-a-query)
                                                 .AsEnumerable()
                                                 .Select(n => new
                        {
                            // Skip the EntityState and EntityKey properties inherited from EF. It would break model binding.
                            //n.Group,
                            //n.GroupID,
                            //n.Header,
                            n.ID,
                            //n.Imported,
                            //n.LastUpdated,
                            //n.Note1,
                            //Name = n.Note//Utilities.ConvertToHTML(n.NoteColor)
                            Name     = n.Note,
                            Note     = (n.UserID != null && n.UserID != 0 && db.Users.Where(u => u.UserID == n.UserID).Count() != 0 ? "last updated by " + db.Users.Where(u => u.UserID == n.UserID).FirstOrDefault().FirstName + " " + db.Users.Where(u => u.UserID == n.UserID).FirstOrDefault().LastName + ", " + n.LastUpdated : ""),
                            ParentID = n.GameID,
                            n.SortOrder,
                            ObjectType = "GameNote"
                                         //n.TeamID,
                                         //n.UserID
                        })).ToList();
                }
                return(retGroups.Concat(db.spTICK_GameNotes_GetByGameID(gameID: ID, clientID: cid)
                                        .Select(on => new { on.ID, on.Note, on.UserID, on.LastUpdated, on.GameID, on.SortOrder }) //first trip is pure ef and can't convert dt to string (See also http://stackoverflow.com/questions/5370402/entity-framework-4-linq-how-to-convert-from-datetime-to-string-in-a-query)
                                        .AsEnumerable()
                                        .Select(n => new
                    {
                        // Skip the EntityState and EntityKey properties inherited from EF. It would break model binding.
                        //n.Group,
                        //n.GroupID,
                        //n.Header,
                        n.ID,
                        //n.Imported,
                        //n.LastUpdated,
                        //n.Note1,
                        //Name = n.Note//Utilities.ConvertToHTML(n.NoteColor)
                        Name = n.Note,
                        Note = (n.UserID != null && n.UserID != 0 && db.Users.Where(u => u.UserID == n.UserID).Count() != 0 ? "last updated by " + db.Users.Where(u => u.UserID == n.UserID).FirstOrDefault().FirstName + " " + db.Users.Where(u => u.UserID == n.UserID).FirstOrDefault().LastName + ", " + n.LastUpdated : ""),
                        ParentID = n.GameID,
                        n.SortOrder,
                        ObjectType = "GameNote"
                                     //n.TeamID,
                                     //n.UserID
                    })));
            }

            case "Sports":
                dynamic expando = new ExpandoObject();
                expando = new { ID = 0, Name = "Today", ObjectType = "Game", SortOrder = -1, hasChildren = false };
                ret.Add(expando);

                expando = new { ID = 0, Name = "Previous", ObjectType = "Game", SortOrder = -1, hasChildren = false };
                ret.Add(expando);

                foreach (Client c in db.Clients.Single(s => s.ID == cid).Clients)
                {
                    ret = ret.Concat(db.spTICK_Games_Get(c.ID, ID, null, null, null).Select(g => new
                    {
                        g.ID,
                        Name       = g.Matchup,
                        ObjectType = "Game",
                        g.SortOrder,
                        hasChildren = db.spTICK_GameNotes_GetByGameID(gameID: g.ID, clientID: c.ID).Any()
                    })).ToList();
                }

                return(ret.Concat(db.spTICK_Games_Get(cid, ID, null, null, null).Select(g => new
                {
                    g.ID,
                    Name = g.Matchup,
                    ObjectType = "Game",
                    g.SortOrder,
                    hasChildren = db.spTICK_GameNotes_GetByGameID(gameID: g.ID, clientID: cid).Any()
                })));

            //return ret.Concat;
            //return db.spTICK_Games_Get(id, entryID, null, null, null).Select(g => new
            //{
            //    g.ID,
            //    Name = g.Matchup,
            //    ObjectType = "Game",
            //    hasChildren = db.spTICK_GameNotes_GetByGameID(gameID: g.ID, clientID: id).Any()
            //});
            default:
                return(null);
            }

            //return db.Notes.Where(gw => gw.ID == id).Single(n => new
            //{
            //    // Skip the EntityState and EntityKey properties inherited from EF. It would break model binding.
            //    //n.Group,
            //    //n.GroupID,
            //    //n.Header,
            //    n.ID,
            //    //n.Imported,
            //    //n.LastUpdated,
            //    //n.Note1,
            //    Name = n.Note1,// Utilities.ConvertToHTML(n.NoteColor),
            //    //n.SortOrder,
            //    //n.TeamID,
            //    n.UserID
            //});
        }