예제 #1
0
        public ActionResult Create(CreateProjectViewModelPost create)
        {
            Request.ThrowIfDifferentReferrer();

            var currentUser = _userManager.FindById(User.Identity.GetUserId());

            if (ModelState.IsValid && currentUser != null &&
                PathNameValidation.CheckContainsNoForbiddenPathCharacters(ModelState, nameof(create.Name), create.Name) &&
                CheckProjectNameAlreadyInUse(nameof(create.Name), create.Name, currentUser) &&
                SessionDefinitionValidation.CheckDefinitionTemplateJson(ModelState, nameof(create.SessionDefinitionTemplate), create.SessionDefinitionTemplate))
            {
                var command = new CreateProjectCommand()
                {
                    Owner = currentUser,
                    SessionDefinitionTemplate = create.SessionDefinitionTemplate,
                    Name        = create.Name,
                    Description = create.Description
                };

                _dispatcher.Dispatch(command);

                return(RedirectToAction(nameof(Details), new { projectId = command.NewId }));
            }

            var newCreate = Mapper.Map <CreateProjectViewModel>(create);

            newCreate.SessionDefinitionTemplates = GetSessionTemplatesList();

            return(View(newCreate));
        }
예제 #2
0
        public ActionResult Edit(int projectId, EditProjectViewModelPost edit)
        {
            Request.ThrowIfDifferentReferrer();

            var project = _database.Projects
                          .FilterById(projectId)
                          .AsDbQuery()
                          .Include(p => p.Owner)
                          .SingleOrDefault();

            var currentUser = _userManager.FindById(User.Identity.GetUserId());

            if (project != null && currentUser != null &&
                (project.Owner == currentUser || User.IsInRole(UserRoles.ADMIN)))
            {
                if (ModelState.IsValid &&
                    PathNameValidation.CheckContainsNoForbiddenPathCharacters(ModelState, nameof(edit.Name), edit.Name) &&
                    CheckProjectNameAlreadyInUse(nameof(edit.Name), edit.Name, project.Owner, project.Id) &&
                    SessionDefinitionValidation.CheckDefinitionTemplateJson(ModelState, nameof(edit.SessionDefinitionTemplate), edit.SessionDefinitionTemplate))
                {
                    string nameBeforeEdit = project.Name;

                    var command = new EditProjectCommand()
                    {
                        Project     = project,
                        Name        = edit.Name,
                        Description = edit.Description,
                        SessionDefinitionTemplate = edit.SessionDefinitionTemplate
                    };

                    _dispatcher.Dispatch(command);

                    if (project.Name != nameBeforeEdit)
                    {
                        _recordings.UpdateProjectDataLocation(project, nameBeforeEdit);
                    }

                    return(RedirectToAction(nameof(Details), new { projectId = project.Id }));
                }

                var newEdit = Mapper.Map <EditProjectViewModel>(edit);

                newEdit.OriginalName = project.Name;
                newEdit.SessionDefinitionTemplates = GetSessionTemplatesList();

                return(View(newEdit));
            }

            return(HttpNotFound());
        }
예제 #3
0
        public ActionResult Create(int?projectId, CreateSessionViewModelPost create)
        {
            Request.ThrowIfDifferentReferrer();

            if (projectId.HasValue)
            {
                var project = _database.Projects
                              .FilterById(projectId.Value)
                              .SingleOrDefault();

                var currentUser = _userManager.FindById(User.Identity.GetUserId());

                if (CheckProjectAccessRights(nameof(projectId), project, currentUser))
                {
                    if (ModelState.IsValid &&
                        PathNameValidation.CheckContainsNoForbiddenPathCharacters(ModelState, nameof(create.Name), create.Name) &&
                        CheckSessionNameIsAlreadyInUse(nameof(create.Name), project, create.Name) &&
                        (create.UseProjectDefinitionTemplate ||
                         SessionDefinitionValidation.CheckDefinitionTemplateJson(ModelState, nameof(create.Definition), create.Definition)))
                    {
                        var command = new CreateSessionCommand()
                        {
                            Name       = create.Name,
                            StartTime  = create.StartTime,
                            Length     = create.Length,
                            Definition = create.UseProjectDefinitionTemplate ? null : create.Definition,
                            Project    = project,
                        };

                        _dispatcher.Dispatch(command);

                        return(RedirectToAction(nameof(ProjectController.Details), ProjectController.ControllerName, new { projectId = projectId }));
                    }

                    var newCreate = Mapper.Map <CreateSessionViewModel>(create);

                    newCreate.ProjectId = project.Id;

                    return(View(newCreate));
                }

                return(HttpNotFound());
            }

            return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
        }
예제 #4
0
        public ActionResult Edit(int sessionId, EditSessionViewModelPost edit)
        {
            Request.ThrowIfDifferentReferrer();

            var session = _database.Sessions
                          .FilterById(sessionId)
                          .AsDbQuery()
                          .Include(s => s.Project.Owner)
                          .SingleOrDefault();

            var currentUser = _userManager.FindById(User.Identity.GetUserId());

            if (session?.Project != null && currentUser != null &&
                (session.Project.Owner == currentUser || User.IsInRole(UserRoles.ADMIN)))
            {
                Project project;
                if (edit.ProjectId != session.ProjectId)
                {
                    project = _database.Projects
                              .FilterById(edit.ProjectId)
                              .AsDbQuery()
                              .Include(p => p.Sessions)
                              .Include(p => p.Owner)
                              .SingleOrDefault();
                }
                else
                {
                    project = session.Project;
                }

                if (ModelState.IsValid &&
                    CheckProjectAccessRights(nameof(edit.ProjectId), project, currentUser) &&
                    PathNameValidation.CheckContainsNoForbiddenPathCharacters(ModelState, nameof(edit.Name), edit.Name) &&
                    CheckSessionNameIsAlreadyInUse(nameof(edit.Name), project, edit.Name, session.Id) &&
                    (edit.UseProjectDefinitionTemplate ||
                     SessionDefinitionValidation.CheckDefinitionTemplateJson(ModelState, nameof(edit.Definition), edit.Definition)))
                {
                    var nameBeforeEdit    = session.Name;
                    var projectBeforeEdit = session.Project;

                    var command = new EditSessionCommand()
                    {
                        Session    = session,
                        Project    = project,
                        Name       = edit.Name,
                        StartTime  = edit.StartTime,
                        Length     = edit.Length,
                        Definition = edit.UseProjectDefinitionTemplate ? null : edit.Definition
                    };

                    _dispatcher.Dispatch(command);

                    if (session.Project != projectBeforeEdit || session.Name != nameBeforeEdit)
                    {
                        _recordings.UpdateSessionDataLocation(session, projectBeforeEdit.Owner.Email, projectBeforeEdit.Name, nameBeforeEdit);
                    }

                    return(RedirectToAction(nameof(ProjectController.Details), ProjectController.ControllerName, new { projectId = session.ProjectId }));
                }
                else
                {
                    // return again
                    // Prevent changing of the headline in the view using the name from viewmodel

                    var newEdit = Mapper.Map <EditSessionViewModel>(edit);

                    newEdit.OriginalName = session.Name;

                    var projects = GetProjectSelection(currentUser.Id, User.IsInRole(UserRoles.ADMIN));
                    newEdit.ResetProjectSelection(projects);

                    //List<RecordingViewModel> recordings = _recordings.GetSessionRecordings(session)
                    //                                                 .Select(Mapper.Map<RecordingViewModel>)
                    //                                                 .ToList();

                    //edit.SelectableRecordings = new SelectableRecordingsViewModel(recordings);

                    return(View(newEdit));
                }
            }

            return(HttpNotFound());
        }