Beispiel #1
0
        public ServiceSingleResult <bool> AddProject(Project project)
        {
            var result = new ServiceSingleResult <bool>();

            if (project != null)
            {
                //check permission to create
                int nCreatedProjects = GetProjectsUserCreated(project.CreatorId).Count();
                if (!Inspector.CanUserCreateProject(nCreatedProjects))
                {
                    result.HandleError(ErrorMessagesDict.TooMuchProjectsCreated);
                    return(result);
                }

                //create user-project reference
                project.ProjectUsers.Add(
                    new ProjectUserAccess
                {
                    UserId         = project.CreatorId,
                    ProjectAccess  = ProjectAccess.ProjectCreator,
                    CanGrantAccess = true
                }
                    );

                //add project
                _context.Projects.Add(project);
                try
                {
                    _context.SaveChanges();
                    result.TargetObject = true;
                }
                catch (Exception exc)
                {
                    result.HandleError(exc.Message);
                }
                return(result);
            }

            result.HandleError(ErrorMessagesDict.NullInstance);
            return(result);
        }