Exemplo n.º 1
0
        public async Task<RedirectToRouteResult> Promote(int id)
        {
            var conferenceId = ConferenceId;
            var cfpSpeaker = await dbContext.CfpSpeakers
                .SingleAsync(s => s.ConferenceId == conferenceId && s.Id == id);

            var speaker = new Speaker()
            {
                ConferenceId = conferenceId,
                Name = cfpSpeaker.Name,
                Company = cfpSpeaker.Company,
                Bio = cfpSpeaker.Bio,
                Slug = cfpSpeaker.Name.Slugify(),
                Web = cfpSpeaker.Web,
                Twitter = cfpSpeaker.Twitter,
                GitHub = cfpSpeaker.GitHub
            };
            cfpSpeaker.Speaker = speaker;

            dbContext.Entry(speaker).State = EntityState.Added;

            await dbContext.SaveChangesAsync();

            return RedirectToAction("Speaker", new { id });
        }
Exemplo n.º 2
0
        public async Task<ActionResult> Edit(int id, Speaker speaker)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    speaker.ConferenceId = ConferenceId;
					dbContext.Entry(speaker).State = EntityState.Modified;
                    await dbContext.SaveChangesAsync();

                    return RedirectToAction("Speaker", new { speaker.Id });
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("Updating", ex);
                }
            }
            return View(speaker);
        }
        public async Task<ActionResult> Import(int id, ConferenceImportModel conferenceImportModel)
        {
            using (var oldSwetugg = new SqlConnection(conferenceImportModel.ConnectionString))
            {
                var oldSponsors = oldSwetugg.Query("SELECT * FROM Sponsors");
                foreach (var oldSponsor in oldSponsors)
                {
                    var sponsor = new Sponsor()
                    {
                        ConferenceId = id,
                        Name = oldSponsor.Name,
                        Description = oldSponsor.Description,
                        Web = oldSponsor.Web,
                        Twitter = oldSponsor.Twitter,
                        Priority = oldSponsor.Priority,
                        Published = oldSponsor.Published,
                        Slug = ((string)oldSponsor.Name).Slugify()
                    };
                    _dbContext.Sponsors.Add(sponsor);
                }
                await _dbContext.SaveChangesAsync();

                var oldSpeakers = oldSwetugg.Query("SELECT * FROM Speakers");
                foreach (var oldSpeaker in oldSpeakers)
                {
                    var speaker = new Speaker()
                    {
                        ConferenceId = id,
                        Name = oldSpeaker.Name,
                        Company = oldSpeaker.Company,
                        Bio = oldSpeaker.Bio,
                        GitHub = oldSpeaker.GitHub,
                        Twitter = oldSpeaker.Twitter,
                        Priority = oldSpeaker.Priority,
                        Published = oldSpeaker.Published,
                        Slug = ((string)oldSpeaker.Name).Slugify()
                    };
                    _dbContext.Speakers.Add(speaker);
                }
                await _dbContext.SaveChangesAsync();

                var oldSessions = oldSwetugg.Query(
                    "SELECT s.Id, s.Name, s.Description, s.EmbeddedVideoLink, s.Priority, s.Deleted, ssp.SpeakerId, sp.Name AS SpeakerName " +
                    "FROM Sessions AS s LEFT OUTER JOIN SessionSpeakers AS ssp " +
                    "ON s.Id = ssp.SessionId " +
                    "JOIN Speakers AS sp ON ssp.SpeakerId = sp.Id " +
                    "ORDER BY s.Id");
                int lastId = 0;
                Session session = null;
                foreach (var oldSession in oldSessions)
                {
                    if (lastId != oldSession.Id)
                    {
                        lastId = oldSession.Id;
                        session = new Session()
                        {
                            ConferenceId = id,
                            Name = oldSession.Name,
                            Description = oldSession.Description,
                            VideoUrl = oldSession.EmbeddedVideoLink,
                            VideoPublished = !string.IsNullOrEmpty(oldSession.EmbeddedVideoLink),

                            Priority = oldSession.Priority,
                            Published = !(oldSession.Deleted),
                            Speakers = new List<SessionSpeaker>(),
                            Slug = ((string)oldSession.Name).Slugify()
                        };
                        _dbContext.Sessions.Add(session);
                    }
                    if (oldSession.SpeakerId != null && session != null)
                    {
                        var speakerSlug = ((string) oldSession.SpeakerName).Slugify();
                        var speaker = await _dbContext.Speakers.SingleOrDefaultAsync(s => s.Slug == speakerSlug);
                        if (speaker != null)
                        {
                            session.Speakers.Add(new SessionSpeaker() { Session = session, Speaker = speaker});
                        }
                    }
                }
                await _dbContext.SaveChangesAsync();

                var oldRooms = oldSwetugg.Query("SELECT * FROM Rooms");
                foreach (var oldRoom in oldRooms)
                {
                    var room = new Room()
                    {
                        ConferenceId = id,
                        Name = oldRoom.Name,
                        Description = oldRoom.Description,
                        Priority = oldRoom.Priority,
                        Slug = ((string)oldRoom.Name).Slugify()
                    };
                    _dbContext.Rooms.Add(room);
                }
                await _dbContext.SaveChangesAsync();

                var oldSlots = oldSwetugg.Query("SELECT * FROM Slots");
                foreach (var oldSlot in oldSlots)
                {
                    var slot = new Slot()
                    {
                        ConferenceId = id,
                        Start = oldSlot.Start,
                        End = oldSlot.End,
                        Title = oldSlot.Description
                    };
                    _dbContext.Slots.Add(slot);
                }
                await _dbContext.SaveChangesAsync();

                var allRooms = await _dbContext.Rooms.Where(r => r.ConferenceId == id).ToListAsync();
                var allSessions = await _dbContext.Sessions.Where(r => r.ConferenceId == id).ToListAsync();
                foreach (var slot in await _dbContext.Slots.Where(s => s.ConferenceId == id).ToListAsync())
                {
                    foreach (var room in allRooms)
                    {
                        var oldRoomSlot = oldSwetugg.Query("SELECT rs.SessionId, se.Id, se.Name " +
                                                           "FROM RoomSlots rs " +
                                                           "JOIN Slots s ON rs.SlotId = s.Id " +
                                                           "JOIN Rooms r ON rs.RoomId = r.Id " +
                                                           "JOIN Sessions se ON se.Id = rs.SessionId " +
                                                           "WHERE s.Start = @SlotStart " +
                                                           "AND r.Name = @RoomName", 
                                                           new { SlotStart = slot.Start, RoomName = room.Name}).SingleOrDefault();
                        if (oldRoomSlot != null)
                        {
                            var sessionSlug = ((string) oldRoomSlot.Name).Slugify();
                            session = allSessions.SingleOrDefault(s => s.Slug == sessionSlug);
                            if (slot.RoomSlots == null)
                            {
                                slot.RoomSlots = new List<RoomSlot>();
                            }
                            slot.RoomSlots.Add(new RoomSlot()
                            {
                                Room = room,
                                Slot = slot,
                                AssignedSession = session
                            });
                        }
                    }
                }
                await _dbContext.SaveChangesAsync();
            }

            return RedirectToAction("Conference", new {id});

        }