Exemplo n.º 1
0
        private bool IsProjectAvailable(ExtendedProjectViewModel projectViewModel, string currentUser, ICollection <string> currentUserRoles)
        {
            try
            {
                var visibleTo = _objectSerializer.Deserialize <IList <UserRole> >(projectViewModel.VisibleTo);
                if (visibleTo.Count == 0 || projectViewModel.CreatedBy.Equals(currentUser))
                {
                    return(true);
                }

                foreach (var userRole in visibleTo)
                {
                    if (userRole.ReviewerType == ApprovalDefinitionReviewerType.User && userRole.Name == currentUser)
                    {
                        return(true);
                    }

                    if (currentUserRoles.Contains(userRole.Name))
                    {
                        return(true);
                    }
                }

                return(false);
            }
            catch
            {
                return(true);
            }
        }
Exemplo n.º 2
0
        public virtual ActionResult Post(ExtendedProjectViewModel projectViewModel)
        {
            // If no project data is given then it is a bad request.
            if (projectViewModel == null)
            {
                return(new RestStatusCodeResult(HttpStatusCode.BadRequest));
            }

            try
            {
                var project = Create(_viewModelConverter.ToProject(projectViewModel));
                projectViewModel.Id = project.ID;

                SaveProjectSettings(projectViewModel);
                return(new RestStatusCodeResult(HttpStatusCode.Created)
                {
                    Data = projectViewModel
                });
            }
            catch (EPiServerException e)
            {
                return(new RestStatusCodeResult(HttpStatusCode.Conflict, e.Message)
                {
                    Data = new
                    {
                        Message = e.Message
                    }
                });
            }
        }
Exemplo n.º 3
0
        public virtual ActionResult Put(int?id, ExtendedProjectViewModel projectViewModel)
        {
            // If no project data is given then it is a bad request.
            if (!id.HasValue || projectViewModel == null)
            {
                return(new RestStatusCodeResult(HttpStatusCode.BadRequest));
            }

            // Ensure the ID is set on the project data to ensure an update occurs.
            projectViewModel.Id = id.Value;
            var project = _projectRepository.Get(projectViewModel.Id);

            if (project == null)
            {
                return(new RestStatusCodeResult(HttpStatusCode.NotFound, "The project doesn't exist.")
                {
                    Data = new
                    {
                        Message = "The project doesn't exist."
                    }
                });
            }

            SaveProjectSettings(projectViewModel);

            _projectRepository.Save(_viewModelConverter.ToProject(projectViewModel));
            project = _projectRepository.Get(projectViewModel.Id);
            var extendedProjectViewModel = _viewModelConverter.ToViewModel(project);

            AddExtendedFields(extendedProjectViewModel);
            return(new RestStatusCodeResult(HttpStatusCode.OK)
            {
                Data = extendedProjectViewModel
            });
        }
Exemplo n.º 4
0
 public Project ToProject(ExtendedProjectViewModel extendedProjectViewModel)
 {
     return(new Project
     {
         ID = extendedProjectViewModel.Id,
         Name = extendedProjectViewModel.Name
     });
 }
Exemplo n.º 5
0
        private void SaveProjectSettings(ExtendedProjectViewModel projectViewModel)
        {
            var projectSettings = new ProjectSettings
            {
                Description = projectViewModel.Description,
                Categories  = projectViewModel.Categories,
                VisibleTo   = projectViewModel.VisibleTo
            };

            projectSettings.UpdateProjectEditInfo();
            _projectEnhancementsStore.Save(projectViewModel.Id, projectSettings);
        }
Exemplo n.º 6
0
        private void AddExtendedFields(ExtendedProjectViewModel projectViewModel)
        {
            var projectSettings = _projectEnhancementsStore.Load(projectViewModel.Id);

            if (projectSettings == null)
            {
                return;
            }

            projectViewModel.Description = projectSettings.Description;
            projectViewModel.Categories  = projectSettings.Categories;
            projectViewModel.VisibleTo   = projectSettings.VisibleTo;
        }