Пример #1
0
        /// <summary>
        /// Maps a CodeCampService.Speaker to a Model.Speaker
        /// </summary>
        /// <param name="speaker">CodeCampService.Speaker</param>
        /// <returns>Model.Speaker</returns>
        public static Model.Speaker Map(Services.Speaker speaker)
        {
            var modelSpeaker = new Model.Speaker()
            {
                ImageUrl      = speaker.ImageUrl,
                Website       = speaker.Website,
                Email         = speaker.Email,
                Bio           = speaker.Bio,
                Twitter       = speaker.Twitter,
                Blog          = speaker.Blog,
                Title         = speaker.Title,
                FirstName     = speaker.FirstName,
                LastName      = speaker.LastName,
                IsAdmin       = speaker.IsAdmin,
                LoginProvider = speaker.LoginProvider
            };

            modelSpeaker.Sessions = (List <Model.Session>)speaker.Sessions.Map();
            return(modelSpeaker);
        }
Пример #2
0
        /// <summary>
        /// Maps the roles for a Person based on the existence
        /// of certain properties and flags
        /// </summary>
        /// <param name="p">Model.Person</param>
        /// <param name="speaker">Model.Speaker</param>
        public static void SetRolesForPerson(this Model.Person p, Services.Speaker speaker = null)
        {
            if (p != null)
            {
                if (p.IsAdmin)
                {
                    p.Roles.Add("Admin");
                }
            }

            if (speaker != null)
            {
                if (speaker.Sessions != null)
                {
                    if (speaker.Sessions.Any())
                    {
                        p.Roles.Add("Speaker");
                    }
                }
            }
        }
Пример #3
0
        public static Speaker AsSpeaker(this Data.Person p)
        {
            Speaker speaker = new Speaker()
            {
                ID = p.ID,
                Email = p.Email,
                FirstName = p.FirstName,
                LastName = p.LastName,
                Title = p.Title,
                Bio = p.Bio,
                Website = p.Website,
                Blog = p.Blog,
                Twitter = p.Twitter,
                ImageUrl = p.ImageUrl
            };

            foreach (var session in p.Sessions)
                speaker.Sessions.Add(session.Map());

            return speaker;
        }
Пример #4
0
        public Speaker GetSpeaker(int eventId, int speakerId)
        {
            using (var db = new CC.Data.CCDB())
            {
                var s = (from speaker in db.People.Include("Sessions")
                         where speaker.ID == speakerId
                         select speaker).FirstOrDefault();

                if (s == null) throw new ArgumentException("Speaker not found");

                // OLD: return s.AsSpeaker(); // ?? how to filter sessions by event id ??

                Speaker result = new Speaker()
                {
                    ID = s.ID,
                    Email = s.Email,
                    FirstName = s.FirstName,
                    LastName = s.LastName,
                    Title = string.IsNullOrEmpty(s.Title) ? string.Empty : s.Title,
                    Bio = string.IsNullOrEmpty(s.Bio) ? string.Empty : s.Bio,
                    Website = string.IsNullOrEmpty(s.Website) ? string.Empty : s.Website,
                    Blog = string.IsNullOrEmpty(s.Blog) ? string.Empty : s.Blog,
                    Twitter = string.IsNullOrEmpty(s.Twitter) ? string.Empty : s.Twitter,
                    ImageUrl = s.ImageUrl
                };

                foreach (var session in s.Sessions)
                    if (session.Event_ID == eventId)
                    {
                        var tSlot = (from timeslot in db.Timeslots
                                     where timeslot.ID == session.Timeslot_ID
                                     select timeslot);
                        var tRack = (from track in db.Tracks
                                     where track.ID == session.Track_ID
                                     select track);
                        if (tSlot != null)
                        {
                            session.Timeslot = tSlot.FirstOrDefault();
                        }
                        if (tRack != null)
                        {
                            session.Track = tRack.FirstOrDefault();
                        }

                        result.Sessions.Add(session.Map());
                    }

                return result;
            }
        }