Exemplo n.º 1
0
        public ActionResult Edit(int id)
        {
            // get user by id
            EditSessionViewModel editSessionVM;

            using (WSADDbContext context = new WSADDbContext())
            {
                //get user from DB
                Session sessionDTO = context.Sessions.Find(id);

                //create a editviewmodel
                if (sessionDTO == null)
                {
                    return(Content("Invalid Id"));
                }
                //send viewmodel to the view
                editSessionVM = new EditSessionViewModel()
                {
                    Title       = sessionDTO.Title,
                    Description = sessionDTO.Description,
                    Presenter   = sessionDTO.Presenter,
                    Id          = sessionDTO.Id,
                    Room        = sessionDTO.Room,
                    Time        = sessionDTO.Time,
                    Occupancy   = sessionDTO.Occupancy
                };
            }

            //send viewmodel to the view
            return(View(editSessionVM));
        }
        public ActionResult Edit(EditSessionViewModel editSessionVM)
        {
            if (!ModelState.IsValid)
            {
                return(View(editSessionVM));
            }

            using (WSADDbContext context = new WSADDbContext())
            {
                Session sessionDTO = context.Sessions.Find(editSessionVM.SessionId);
                if (sessionDTO == null)
                {
                    return(Content("Inavid Session ID"));
                }

                sessionDTO.SessionTitle          = editSessionVM.SessionTitle;
                sessionDTO.SessionDescription    = editSessionVM.SessionDescription;
                sessionDTO.SessionPresenter      = editSessionVM.SessionPresenter;
                sessionDTO.SessionAddress        = editSessionVM.SessionAddress;
                sessionDTO.SessionRoom           = editSessionVM.SessionRoom;
                sessionDTO.SessionSeatsAvailable = editSessionVM.SessionSeatsAvailable;

                context.SaveChanges();
            }

            // Toast to show the session edited
            return(View());
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create(int eventId, int?sectionId)
        {
            var evt = await _dbContext.Events.FindAsync(eventId);

            if (evt == null)
            {
                // TODO: Diplay error
                return(RedirectToAction("Index", "Events"));
            }

            //Section section = null;
            //if (sectionId.HasValue)
            //{
            //    section = await _dbContext.Sections.FindAsync(sectionId.Value);
            //    if (section == null || section.EventId != eventId)
            //    {
            //        return RedirectToAction("Details", "Events", new { id = eventId });
            //    }
            //}

            var model = new EditSessionViewModel();

            model.EventId        = evt.Id;
            model.EventName      = evt.Name;
            model.SectionId      = sectionId ?? 0;
            model.SectionOptions = await GetEventSectionOptions(eventId);

            model.UserOptions = await GetUserOptions();

            // Defaults
            model.AllowRegistrations = true;
            model.EnableWaitList     = evt.EnableWaitLists;

            return(View(model));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Session session = await _context.Sessions
                              .Include(s => s.SessionPlayers)
                              .Include(a => a.Adventure.AdventurePlayers)
                              .SingleOrDefaultAsync(x => x.SessionID == id);


            if (session == null)
            {
                return(NotFound());
            }

            EditSessionViewModel viewModel = new EditSessionViewModel
            {
                Session                = session,
                Adventures             = new SelectList(_context.Adventures, "AdventureID", "Title"),
                SessionPlayers         = new SelectList(_context.Players, "PlayerID", "Name"),
                SelectedSessionPlayers = session.SessionPlayers.Select(sp => sp.PlayerID)
            };

            return(View(viewModel));
        }
Exemplo n.º 5
0
        protected override DriverResult Editor(SessionPart part, IUpdateModel updater, dynamic shapeHelper)
        {
            return(ContentShape("Parts_Session_Edit", () => {
                var allSpeakers = _contentManager.Query <SpeakerPart>("Speaker").List().ToArray();
                var currentSpeakers = _conferenceService.GetSpeakersBySession(part.Id);
                var viewModel = new EditSessionViewModel {
                    AllSpeakers = allSpeakers,
                    SelectedSpeakers = currentSpeakers.Select(x => new SpeakerViewModel {
                        Id = x.Id, Name = x.As <TitlePart>().Title
                    }).ToList()
                };

                if (updater != null)
                {
                    if (updater.TryUpdateModel(viewModel, Prefix, null, new[] { "AllSpeakers" }))
                    {
                        var selectedSpeakerIds = viewModel.SelectedSpeakers.Where(x => x.Id > 0).Select(x => x.Id).ToArray();
                        _conferenceService.RemoveSpeakersFromSession(part.Id, selectedSpeakerIds);
                        _conferenceService.AddSpeakersToSession(part.Id, selectedSpeakerIds);
                    }
                }

                return shapeHelper.EditorTemplate(TemplateName: "Parts.Session", Model: viewModel, Prefix: Prefix);
            }));
        }
        public ActionResult Edit(int id)
        {
            EditSessionViewModel editSessionVM;

            using (WSADDbContext context = new WSADDbContext())
            {
                Session sessionDTO = context.Sessions.Find(id);
                if (sessionDTO == null)
                {
                    return(Content("Invalid Session ID"));
                }

                editSessionVM = new EditSessionViewModel()
                {
                    SessionId             = sessionDTO.SessionId,
                    SessionTitle          = sessionDTO.SessionTitle,
                    SessionDescription    = sessionDTO.SessionDescription,
                    SessionPresenter      = sessionDTO.SessionPresenter,
                    SessionAddress        = sessionDTO.SessionAddress,
                    SessionRoom           = sessionDTO.SessionRoom,
                    SessionSeatsAvailable = sessionDTO.SessionSeatsAvailable,
                };
            }
            //passing the viewModel data to the view with edit template
            return(View(editSessionVM));
        }
        public void Add()
        {
            EditSessionViewModel editSessionViewModel = _resolutionRoot.Get <EditSessionViewModel>();

            ((ISupportParentViewModel)editSessionViewModel).ParentViewModel = this;
            DialogService.ShowDialog("Schedule Editor", editSessionViewModel);
            Refresh();
        }
        public void Edit()
        {
            EditSessionViewModel editSessionViewModel = _resolutionRoot.Get <EditSessionViewModel>(new ConstructorArgument("session", SelectedSession));

            ((ISupportParentViewModel)editSessionViewModel).ParentViewModel = this;
            DialogService.ShowDialog("Film Editor", editSessionViewModel);
            Refresh();
        }
        public ActionResult Edit(EditSessionViewModel view)
        {
            Session session = db.Sessions.Find(view.ID);

            if (ModelState.IsValid)
            {
                session.Name            = view.Name;
                session.Ended           = view.Ended;
                db.Entry(session).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index", new { courseID = session.CourseID }));
            }
            return(View(view));
        }
Exemplo n.º 10
0
        public ActionResult EditSessionPost(EditSessionViewModel inputVm)
        {
            if (inputVm == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var sessionToUpdate = _sessionManager.GetSessionByIdWithIncludes(inputVm.SessionId);

            try
            {
                int?location = _utilitiesManager.GetIdForLocationOrCreateIfNotExists(inputVm.NameOfLocation);
                int?hrPerson = inputVm.HrPerson;

                sessionToUpdate.Name        = inputVm.NameOfSession;
                sessionToUpdate.ActivityId  = inputVm.Activity.Id;
                sessionToUpdate.StartDate   = inputVm.StartDate;
                sessionToUpdate.EndDate     = inputVm.EndDate;
                sessionToUpdate.Description = inputVm.Description;
                sessionToUpdate.IsOpenForExpressionOfInterest = inputVm.IsOpenForExpressionOfInterest;
                sessionToUpdate.LocationId = location;
                sessionToUpdate.HrPersonId = hrPerson;

                _sessionManager.EditSession(sessionToUpdate);

                return(RedirectToAction("SessionForActivity", "ActivitySummary", new { id = sessionToUpdate.Id }));

                //ModelState.AddModelError("NameOfSession", "Aktiviteten existerar redan.");
            }
            catch (RetryLimitExceededException /* dex */)
            {
                ModelState.AddModelError("",
                                         "Det går inte att spara ändringarna. Försök igen, och om problemet kvarstår se systemadministratören .");
            }

            ViewBag.AllHrPersons = new SelectList(_personManager.GetAllHrPersons().OrderBy(n => n.FirstName), "Id",
                                                  "FullName", sessionToUpdate.HrPersonId);
            ViewBag.AllActivities = new SelectList(_activityManager.GetAllActivities().OrderBy(n => n.Name), "Id",
                                                   "Name", sessionToUpdate.ActivityId);

            ViewBag.NameOfLocation = inputVm.NameOfLocation;
            inputVm.AddedTags      = _utilitiesManager.GetAllTagsForSessionById(inputVm.SessionId).ToList();
            return(View("EditSession", inputVm));
        }
Exemplo n.º 11
0
        public ActionResult EditSession(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var session = _sessionManager.GetSessionByIdWithIncludes((int)id);

            if (session == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var activity = _activityManager.GetActivityById(session.ActivityId);

            // Get Tags for session
            var allTagsForSession =
                _utilitiesManager.GetAllTagsForSessionById((int)id).ToList();

            var viewModel = new EditSessionViewModel()
            {
                SessionId = session.Id,
                NameOfSessionWithActivity = session.NameWithActivity,
                Activity      = activity,
                NameOfSession = session.Name,
                StartDate     = session.StartDate,
                EndDate       = session.EndDate,
                Description   = session.Description,
                IsOpenForExpressionOfInterest = session.IsOpenForExpressionOfInterest,
                HrPerson       = session.HrPersonId,
                NameOfLocation = (session.Location == null) ? string.Empty : session.Location.Name,
                AddedTags      = allTagsForSession
            };

            ViewBag.NameOfLocation = viewModel.NameOfLocation;

            ViewBag.AllHrPersons = new SelectList(_personManager.GetAllHrPersons().OrderBy(n => n.FirstName), "Id",
                                                  "FullName", session.HrPersonId);
            ViewBag.AllActivities = new SelectList(_activityManager.GetAllActivities().OrderBy(n => n.Name), "Id",
                                                   "Name", session.ActivityId);

            return(View(viewModel));
        }
Exemplo n.º 12
0
        public async Task <IActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            EditSessionViewModel viewModel = new EditSessionViewModel();

            viewModel.Session = await _context.Sessions
                                .Include(s => s.Adventure)
                                .FirstOrDefaultAsync(m => m.SessionID == id);

            if (viewModel.Session == null)
            {
                return(NotFound());
            }

            return(View(viewModel));
        }
Exemplo n.º 13
0
 public ActionResult Edit(Guid id, EditSessionViewModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var session = this.mapper.Map <Session>(model);
             this.repositoryWrapper.Session.Update(session);
             this.repositoryWrapper.Save();
             this.loggerManager.LogInfo($"{User.Identity.Name}  access Edit(Post) page (Dashboard.SesionController.Edit)");
         }
         return(RedirectToAction(nameof(Index)));
     }
     catch (Exception ex)
     {
         var speakers = this.mapper.Map <IList <SpeakerViewModel> >(this.repositoryWrapper.Speaker.GetAllSpeakers());
         ViewBag.Speakers = speakers;
         ModelState.AddModelError("", ex.Message);
         this.loggerManager.LogInfo($"{User.Identity.Name}  access Create(Post) page (Dashboard.SesionController.Edit). Error: {ex.Message}");
         return(View(model));
     }
 }
Exemplo n.º 14
0
        public ActionResult Edit(EditSessionViewModel editSessionVM)
        {
            //validate Model
            if (!ModelState.IsValid)
            {
                return(View(editSessionVM));
            }



            //get our user from DB
            using (WSADDbContext context = new WSADDbContext())

            {
                Session sessionDTO = context.Sessions.Find(editSessionVM.Id);
                if (sessionDTO == null)
                {
                    return(Content("Invalid user Id"));
                }


                //set update values from viewmodel
                sessionDTO.Title       = editSessionVM.Title;
                sessionDTO.Description = editSessionVM.Description;
                sessionDTO.Presenter   = editSessionVM.Presenter;
                sessionDTO.Time        = editSessionVM.Time;
                sessionDTO.Room        = editSessionVM.Room;
                sessionDTO.Occupancy   = editSessionVM.Occupancy;



                //save changes
                context.SaveChanges();
            }


            return(RedirectToAction("index"));
        }
Exemplo n.º 15
0
        // GET: /Session/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Session session = db.Sessions.Find(id);

            db.Entry(session).Reference(c => c.Course).Load();
            if (session == null)
            {
                return(HttpNotFound());
            }
            EditSessionViewModel view = new EditSessionViewModel()
            {
                CourseID = session.Course.ID,
                ID       = (int)id,
                Name     = session.Name,
                Ended    = session.Ended
            };

            return(View(view));
        }
Exemplo n.º 16
0
        public NewSessionView(INavigation navigation, UserModel user, bool modify, SessionModel session)
        {
            InitializeComponent();

            BindingContext = new EditSessionViewModel(navigation, user, modify, session);
        }
Exemplo n.º 17
0
 public EditSessionView(TrainingSessionViewModel sessionToEdit, TrainingSessionService sessionService, CourseService courseService) : this()
 {
     _sessionToEdit = new EditSessionViewModel(sessionService, courseService, sessionToEdit);
     DataContext    = _sessionToEdit;
 }
Exemplo n.º 18
0
        public async Task <IActionResult> Create(int eventId, int?sectionId, EditSessionViewModel model)
        {
            var evt = await _dbContext.Events.FindAsync(eventId);

            if (evt == null)
            {
                // TODO: Diplay error
                return(RedirectToAction("Index", "Events"));
            }

            model.SectionOptions = await GetEventSectionOptions(eventId);

            model.UserOptions = await GetUserOptions();

            model.EnableWaitList = evt.EnableWaitLists;

            var section = await _dbContext.Sections.FindAsync(model.SectionId);

            if (section == null)
            {
                ModelState.AddModelError(nameof(model.SectionId), "A valid section is required");
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            try
            {
                var session = new Session
                {
                    Event              = evt,
                    Section            = section,
                    Name               = model.Name,
                    Description        = model.Description,
                    Address            = model.Address,
                    City               = model.City,
                    State              = model.State,
                    PostalCode         = model.PostalCode,
                    AllowRegistrations = model.AllowRegistrations,
                    MaxSpots           = model.MaxSpots,
                    ReservedSpots      = model.ReservedSpots,
                    AllowWaitList      = evt.EnableWaitLists && model.AllowWaitList,
                    HostUserId         = model.HostUserId,
                    LastUpdatedOn      = DateTime.Now
                };

                if (!session.HostUserId.HasValue)
                {
                    session.HostName = model.HostName;
                }

                _dbContext.Sessions.Add(session);
                await _dbContext.SaveChangesAsync();

                return(RedirectToAction("Details", "Events", new { slug = evt.Slug }));
            }
            catch (Exception ex)
            {
                _logger.LogError(2, ex, "Error creating session");

                ModelState.AddModelError("", "There was an error creating the session.  Try again.");
                return(View(model));
            }
        }
Exemplo n.º 19
0
        public async Task <IActionResult> Edit(int id, EditSessionViewModel viewModel)
        {
            if (id != viewModel.Session.SessionID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                Session session = await _context.Sessions
                                  .Include(s => s.SessionPlayers)
                                  .Include(a => a.Adventure.AdventurePlayers)
                                  .SingleOrDefaultAsync(x => x.SessionID == id);

                session.AdventureID       = viewModel.Session.AdventureID;
                session.Date              = viewModel.Session.Date;
                session.Duration          = viewModel.Session.Duration;
                session.IsPlayed          = viewModel.Session.IsPlayed;
                session.Recap             = viewModel.Session.Recap;
                session.SessionGamemaster = viewModel.Session.SessionGamemaster;

                if (viewModel.SelectedSessionPlayers == null)
                {
                    viewModel.SelectedSessionPlayers = new List <int>();
                }

                List <SessionPlayer>   playersInSession   = new List <SessionPlayer>();
                List <AdventurePlayer> playersInAdventure = new List <AdventurePlayer>();

                foreach (int playerID in viewModel.SelectedSessionPlayers)
                {
                    //Wie speelt mee in de session
                    SessionPlayer sessionPlayer = new SessionPlayer();
                    sessionPlayer.PlayerID  = playerID;
                    sessionPlayer.SessionID = viewModel.Session.SessionID;

                    //Welke spelers spelen het avontuur mee
                    AdventurePlayer adventurePlayer = new AdventurePlayer();
                    adventurePlayer.PlayerID    = playerID;
                    adventurePlayer.AdventureID = viewModel.Session.AdventureID;

                    playersInSession.Add(sessionPlayer);
                    playersInAdventure.Add(adventurePlayer);
                }

                session.SessionPlayers
                .RemoveAll(sp => !playersInSession.Contains(sp));
                session.SessionPlayers
                .AddRange(
                    playersInSession.Where(p => !session.SessionPlayers.Contains(p)));

                session.Adventure.AdventurePlayers
                .RemoveAll(ap => !playersInAdventure.Contains(ap));
                session.Adventure.AdventurePlayers
                .AddRange(
                    playersInAdventure.Where(p => !session.Adventure.AdventurePlayers.Contains(p)));

                _context.Update(session);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(viewModel));
        }