Example #1
0
        /// <summary>
        /// Add project
        /// </summary>
        /// <param name="project">Project to be added</param>
        /// <returns>Asynchronous task</returns>
        public async Task AddProject(ProjectDTO project)
        {
            TaskFacade.NormalizeTaskProjectId(project.Tasks);
            using var uow = uowProviderFunc().Create();
            var entity = mapper.Map <Project>(project);

            var repo = projectRepository();

            repo.Insert(entity);

            await uow.CommitAsync();

            project.Id = entity.Id;
        }
Example #2
0
        /// <summary>
        /// Update existing project
        /// </summary>
        /// <param name="project">Project to be updated</param>
        /// <returns>Asynchronous task</returns>
        /// <exception cref="UIException">Thrown when project to be updated not found or subproject tries to contain another subproject</exception>
        public async Task UpdateProject(ProjectDTO project)
        {
            // No need to get entity from DB
            if (project.ParentProjectId.HasValue && project.SubProjects != null && project.SubProjects.Any())
            {
                throw new UIException(ErrorMessages.SubProjectContaingProjects);
            }

            TaskFacade.NormalizeTaskProjectId(project.Tasks);
            using var uow = uowProviderFunc().Create();
            var repo = projectRepository();

            var entity = await repo.GetByIdAsync(project.Id, x => x.SubProjects);

            IsNotNull(entity, ErrorMessages.ProjectNotFound);
            mapper.Map(project, entity);

            if (entity.ParentProjectId.HasValue && entity.SubProjects.Any())
            {
                throw new UIException(ErrorMessages.SubProjectContaingProjects);
            }

            await uow.CommitAsync();
        }