Example #1
0
        /// <summary>Method create new project.</summary>
        /// <param name="newProject">Model of project to save.</param>
        /// <exception cref="ArgumentNullException"/>
        /// <exception cref="ArgumentException"/>
        /// <exception cref="InvalidOperationException"/>
        /// <exception cref="InsertDbDataException"/>
        public void CreateProject(ProjectModel newProject)
        {
            CheckProjectModelArgs(newProject);

            IEnumerable <User> users = GetUsersByIds(newProject.Users.Select(u => u.Id));
            Project            proj  = newProject.ProjectDetails.ToDbProject();

            using (var context = _ContextGenerator.GenerateContext())
            {
                SaveNewProjectInDB(proj, context);
                newProject.ProjectDetails.Id = proj.ID_Project;
                //Hardcoded load the admin
                Project_Role prRole = (from pr in context.Project_Role
                                       where pr.Is_Admin
                                       select pr).FirstOrDefault();
                if (prRole == null)
                {
                    throw new InvalidOperationException("An admin role for project not found.");
                }

                foreach (User user in users)
                {
                    User_Project usProj = new User_Project()
                    {
                        ID_Project      = proj.ID_Project,
                        ID_User         = user.ID_User,
                        ID_Project_Role = prRole.ID_Project_Role
                    };
                    KeepUserProject(proj.ID_Project, usProj, context);
                }
            }
        }
Example #2
0
        public void CreateProject(EProject newProject)
        {
            CheckTheEProjectData(newProject);
            Project proj = newProject.ToDbProject();

            if (proj.Date_Create == default(DateTime))
            {
                proj.Date_Create = DateTime.Now;
            }

            using (var context = _ContextGenerator.GenerateContext())
            {
                SaveNewProjectInDB(proj, context);
                newProject.Id = proj.ID_Project;
                //Hardcoded load the admin
                Project_Role prRole = (from pr in context.Project_Role
                                       where pr.Is_Admin
                                       select pr).FirstOrDefault();
                if (prRole == null)
                {
                    throw new InvalidOperationException("An admin role for project not found.");
                }

                foreach (decimal userId in newProject.UserIds)
                {
                    User_Project usProj = new User_Project()
                    {
                        ID_Project      = proj.ID_Project,
                        ID_User         = userId,
                        ID_Project_Role = prRole.ID_Project_Role
                    };
                    KeepUserProject(proj.ID_Project, usProj, context);
                }
            }
        }
Example #3
0
        private EUserProject FillUserFromDbUserProject(decimal projectId, User_Project dbUser)
        {
            EUserProject userP = new EUserProject()
            {
                ProjectId     = projectId,
                UserId        = dbUser.ID_User,
                ProjectRoleId = dbUser.ID_Project_Role,
            };

            userP.Role = new EProjectRole()
            {
                ID              = dbUser.Project_Role.ID_Project_Role,
                IsAdmin         = dbUser.Project_Role.Is_Admin,
                Name            = dbUser.Project_Role.Role_Name,
                AccessToProject =
                    (ProjectAccessFunction)dbUser.Project_Role.Role_Access_Functions
            };
            userP.UserDescription = dbUser.User.ToEUser();
            return(userP);
        }
Example #4
0
 private void KeepUserProject(decimal projectId, User_Project usProj, DragonflyEntities context)
 {
     try
     {
         context.User_Project.Add(usProj);
         context.SaveChanges();
     }
     catch (DbEntityValidationException ex)
     {
         context.User_Project.Remove(usProj);
         List <ValidationError> validationErrors = ex.RetrieveValidationsErrors();
         DeleteProject(projectId);
         throw new InsertDbDataException(validationErrors);
     }
     catch (DbUpdateException ex)
     {
         context.User_Project.Remove(usProj);
         DeleteProject(projectId);
         throw new InvalidOperationException("Unable to save user-project relation", ex);
     }
 }