Exemplo n.º 1
0
        public async Task <Unit> Handle(MoveDepartmentCommand request, CancellationToken cancellationToken)
        {
            var userId = Guid.Parse(_userAccessor.GetUser().FindFirst(ClaimTypes.NameIdentifier).Value);

            foreach (var item in request.DepartmentIds)
            {
                var department = await _context.Departments.FindAsync(item);

                if (department == null)
                {
                    throw new IdNullOrEmptyException();
                }

                var notDeletableUnitId = _context.BusinessUnits.First(x => !x.IsDeletable).Id;

                if (request.BusinessUnitId == null || request.BusinessUnitId == Guid.Empty)
                {
                    department.BusinessUnitId = notDeletableUnitId;

                    _context.Departments.Update(department);

                    await _context.SaveChangesAsync(cancellationToken);

                    return(Unit.Value);
                }

                department.BusinessUnitId = request.BusinessUnitId;

                _context.Departments.Update(department);
            }

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
Exemplo n.º 2
0
        public async Task <Unit> Handle(UpdateUserReportGuidsCommand <Guid> request, CancellationToken cancellationToken)
        {
            var businessUseCaseExceptions = new List <string>();

            var report = await _context.Reports.FindAsync(request.ReportId);

            if (report == null)
            {
                businessUseCaseExceptions.Add($"The object {nameof(Report<Guid>)} has no {request.ReportId} key!");
            }

            var user = await _context.ApplicationUsers.FindAsync(request.UserId);

            if (user == null)
            {
                businessUseCaseExceptions.Add($"The object {nameof(ApplicationUser)} has no {request.UserId} key!");
            }

            if (businessUseCaseExceptions.Any())
            {
                throw new BusinessUseCaseException(businessUseCaseExceptions);
            }

            var guids =
                await _context.UserGuidFilters.Where(x =>
                                                     x.ReportId == request.ReportId && x.UserId == request.UserId && x.FilterType == request.FilterType)
                .Select(x => x.EntityId)
                .ToListAsync(cancellationToken);

            var exceptGuids        = guids.Except(request.GuidList).ToList();
            var filtersToEliminate = _context.UserGuidFilters
                                     .Where(x => exceptGuids.Contains(x.EntityId) &&
                                            x.ReportId == request.ReportId && x.UserId == request.UserId &&
                                            x.FilterType == request.FilterType).ToList();

            _context.UserGuidFilters.RemoveRange(filtersToEliminate);

            await _context.SaveChangesAsync(cancellationToken);

            var userReportGuids = request.GuidList.Distinct()
                                  .Where(x => !exceptGuids.Contains(x))
                                  .Select(guid => new UserGuidFilter <Guid>
            {
                Id         = Guid.NewGuid(),
                EntityId   = guid,
                ReportId   = request.ReportId,
                UserId     = request.UserId,
                FilterType = request.FilterType
            }).ToList();

            if (_context.UserGuidFilters != null)
            {
                await _context.UserGuidFilters.AddRangeAsync(userReportGuids, cancellationToken);
            }

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
Exemplo n.º 3
0
        public async Task <Unit> Handle(ProjectAddOrRemoveUserCommand request, CancellationToken cancellationToken)
        {
            var user     = _userAccessor.GetUser();
            var userName = _context.ApplicationUsers
                           .Find(Guid.Parse(user.FindFirst(ClaimTypes.NameIdentifier).Value)).UserName;
            var project = await _context.Projects.FindAsync(request.ProjectId);


            if (request.IncludeUser)
            {
                var exists = _context.ProjectMembers.First(x => x.UserId == request.ApplicationUserId);
                if (exists == null)
                {
                    _context.ProjectMembers.Add(new ProjectMember()
                    {
                        ProjectId = request.ProjectId,
                        UserId    = request.ApplicationUserId
                    });
                    await _context.SaveChangesAsync(cancellationToken);

                    var userEmail = _context.ApplicationUsers.Find(request.ApplicationUserId).Email;
                    await _mediator.Publish(new UserAddedRemovedToProject()
                    {
                        PrimaryEntityId = project.Id,
                        GroupEntityName = project.Name,
                        Message         = "You were added to the team who works on this project.",
                        UserName        = user.Identity.Name,
                        Recipients      = new List <string> {
                            userEmail
                        }
                    }, cancellationToken);
                }
            }
            else
            {
                var exists = _context.ProjectMembers.First(x => x.UserId == request.ApplicationUserId);
                if (exists != null)
                {
                    _context.ProjectMembers.Remove(exists);
                    await _context.SaveChangesAsync(cancellationToken);

                    var userEmail = _context.ApplicationUsers.Find(request.ApplicationUserId).Email;
                    await _mediator.Publish(new UserAddedRemovedToProject()
                    {
                        PrimaryEntityId = project.Id,
                        GroupEntityName = project.Name,
                        Message         = "You were removed from the team who works on this project",
                        UserName        = user.Identity.Name,
                        Recipients      = new List <string> {
                            userEmail
                        }
                    }, cancellationToken);
                }
            }
            return(Unit.Value);
        }
Exemplo n.º 4
0
        public async Task <Unit> Handle(AddTeamToDepartmentCommand request, CancellationToken cancellationToken)
        {
            var checkDepartment = await _context.Departments.AnyAsync(x => x.Id == request.DepartmentId, cancellationToken);

            var existingTeams          = _context.DepartmentTeams.Where(x => x.DepartmentId == request.DepartmentId).ToList();
            var notDeletableDepartment = _context.Departments.First(x => x.IsDeletable == false);


            if (request.DepartmentTeamIds == null)
            {
                foreach (var item in existingTeams)
                {
                    item.DepartmentId = notDeletableDepartment.Id;
                    _context.DepartmentTeams.Update(item);
                }

                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }

            if (checkDepartment && request.DepartmentTeamIds != null)
            {
                var teamsToAdd    = request.DepartmentTeamIds.Except(existingTeams.Select(x => x.Id)).ToList();
                var teamsToRemove = existingTeams.Select(x => x.Id).Except(request.DepartmentTeamIds).ToList();

                if (teamsToRemove.Count != 0)
                {
                    foreach (var item in teamsToRemove)
                    {
                        var teamRemove = _context.DepartmentTeams.First(x => x.Id == item);
                        teamRemove.DepartmentId = notDeletableDepartment.Id;
                        _context.DepartmentTeams.Update(teamRemove);
                    }
                }

                if (teamsToAdd.Count != 0)
                {
                    foreach (var item in teamsToAdd)
                    {
                        var teamAdd = _context.DepartmentTeams.First(x => x.Id == item);
                        teamAdd.DepartmentId = request.DepartmentId;

                        _context.DepartmentTeams.Update(teamAdd);
                    }
                }

                await _context.SaveChangesAsync(cancellationToken);
            }
            return(Unit.Value);
        }
Exemplo n.º 5
0
        public async Task <Unit> Handle(UpdateUserReportActivityStatusesCommand <Guid> request, CancellationToken cancellationToken)
        {
            var businessUseCaseExceptions = new List <string>();

            var report = await _context.Reports.FindAsync(request.ReportId);

            if (report == null)
            {
                businessUseCaseExceptions.Add($"The object {nameof(Report<Guid>)} has no {request.ReportId} key!");
            }

            var user = await _context.ApplicationUsers.FindAsync(request.UserId);

            if (user == null)
            {
                businessUseCaseExceptions.Add($"The object {nameof(ApplicationUser)} has no {request.UserId} key!");
            }

            if (businessUseCaseExceptions.Any())
            {
                throw new BusinessUseCaseException(businessUseCaseExceptions);
            }

            await Task.Run(() =>
            {
                var activityStatuses =
                    _context.UserActivityStatusFilters.Where(x =>
                                                             x.ReportId == request.ReportId && x.UserId == request.UserId);

                _context.UserActivityStatusFilters.RemoveRange(activityStatuses);
            }, cancellationToken);

            await _context.SaveChangesAsync(cancellationToken);

            var userReportActivityStatuses = request.ActivityStatuses.Distinct()
                                             .Select(activityStatus => new UserActivityStatusFilter <Guid>
            {
                Id             = Guid.NewGuid(),
                ActivityStatus = activityStatus,
                ReportId       = request.ReportId,
                UserId         = request.UserId
            }).ToList();

            await _context.UserActivityStatusFilters.AddRangeAsync(userReportActivityStatuses, cancellationToken);

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
Exemplo n.º 6
0
        public async Task <Unit> Handle(DeleteJobPositionCommand request, CancellationToken cancellationToken)
        {
            foreach (var item in request.Ids)
            {
                var entity = await _context.JobPositions.FindAsync(item);

                if (entity == null)
                {
                    throw new NotFoundException(nameof(JobPosition), item);
                }

                var hasUsers = _context.ApplicationUsers.Any(x => x.JobPositionId == item);

                if (hasUsers)
                {
                    throw new DeleteFailureException(nameof(JobPosition), item,
                                                     "There are existing entities associated with this job position.");
                }

                _context.JobPositions.Remove(entity);
            }

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
Exemplo n.º 7
0
        public async Task <Unit> Handle(DeleteProjectGroupCommand request, CancellationToken cancellationToken)
        {
            var entity = await _context.ProjectGroups.FindAsync(request.Id);

            if (entity == null)
            {
                throw new NotFoundException(nameof(ProjectGroup), request.Id);
            }

            if (!entity.IsDeletable)
            {
                throw new DeleteFailureException(nameof(ProjectGroup), request.Id, DeleteFailureMessages.EntityNotDeletable.ToString());
            }

            var groupProjects = _context.Projects.Where(p => p.ProjectGroupId == entity.Id);

            if (groupProjects.Any())
            {
                var projectUpdateList = new List <Project>();
                foreach (var project in groupProjects)
                {
                    project.ProjectGroupId = _context.ProjectGroups.First(pg => !pg.IsDeletable).Id;
                    projectUpdateList.Add(project);
                }

                _context.Projects.UpdateRange(projectUpdateList);
            }

            _context.ProjectGroups.Remove(entity);

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
Exemplo n.º 8
0
        public async Task <Unit> Handle(CreateActivityListCommand request, CancellationToken cancellationToken)
        {
            var user   = _userAccessor.GetUser();
            var entity = new ActivityList(request.Id)
            {
                Name               = request.Name,
                ProjectId          = request.ProjectId,
                ActivityListStatus = request.ActivityListStatus,
                SprintId           = request.SprintId,
                Description        = request.Description,
                StartDate          = request.StartDate,
                DueDate            = request.DueDate,
                Project            = await _context.Projects.FindAsync(request.ProjectId),
                Sprint             = await _context.Sprints.FindAsync(request.SprintId)
            };

            await _context.ActivityLists.AddAsync(entity, cancellationToken);

            await _context.SaveChangesAsync(cancellationToken);

            var notification = new ActivityListCreated()
            {
                PrimaryEntityId   = entity.Id,
                PrimaryEntityName = entity.Name,
                GroupEntityName   = entity.Project.Name,
                GroupEntityId     = entity.ProjectId,
                Recipients        = _context.ProjectMembers.Include(x => x.User)
                                    .Where(x => x.ProjectId == entity.ProjectId).Select(x => x.User.Email).ToList(),
                UserName = user.Identity.Name
            };

            await _mediator.Publish(notification, cancellationToken);

            return(Unit.Value);
        }
Exemplo n.º 9
0
        public async Task <Unit> Handle(SetActivitiesStatusCommand request, CancellationToken cancellationToken)
        {
            var activities = new List <Activity>();

            foreach (var id in request.ActivitiesById)
            {
                var activity = await _context.Activities.FindAsync(id);

                if (activity == null)
                {
                    throw new NotFoundException(nameof(Activity), id);
                }

                activity.ActivityStatus = request.Status;

                activities.Add(activity);
            }

            if (activities.Any())
            {
                _context.Activities.UpdateRange(activities);
            }

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
Exemplo n.º 10
0
        public async Task <Unit> Handle(UpdateSubCommentCommand request, CancellationToken cancellationToken)
        {
            var subComment = await _context.SubComments.FindAsync(request.Id);

            subComment.UpdateComment(subComment, request.Message);

            _context.SubComments.Update(subComment);

            await _context.SaveChangesAsync(cancellationToken);

            // ------------------------------
            // Send email to mentioned users
            var emails = request.Message.FindEmails();

            if (emails.Count == 0)
            {
                return(Unit.Value);
            }

            var mainComment = await _context.MainComments.FindAsync(subComment.MainCommentId);

            var notification = new SendCommentEmail()
            {
                PrimaryEntityId = mainComment.RecordId,
                UserName        = subComment.AuthorName,
                Recipients      = emails,
                AuthorName      = subComment.AuthorName,
                Message         = subComment.Message
            };

            await _mediator.Publish(notification);

            return(Unit.Value);
        }
Exemplo n.º 11
0
        public async Task <Unit> Handle(DeleteTrackerTypeCommand request, CancellationToken cancellationToken)
        {
            var trackers = new List <TrackerType>();

            foreach (var item in request.Ids)
            {
                var entity = await _context.TrackerTypes.FindAsync(item);

                if (entity == null)
                {
                    throw new NotFoundException(nameof(TrackerType), item);
                }

                trackers.Add(entity);
            }



/*
 *          var hasLoggedTime = _context.LoggedTimes.Any(x => x.TrackerId == entity.Id);
 *
 *          if (hasLoggedTime)
 *          {
 *              throw new DeleteFailureException(nameof(TrackerType), request.Id,
 *                  "There are existing entities associated with this tracker type.");
 *          }
 */

            _context.TrackerTypes.RemoveRange(trackers);

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
Exemplo n.º 12
0
        public async Task <Unit> Handle(CreateHeadlineCommand request, CancellationToken cancellationToken)
        {
            var currentUserId = Guid.Parse(_userAccessor.GetUser().FindFirst(ClaimTypes.NameIdentifier).Value);

            var entity = new Headline
            {
                ProjectId = request.ProjectId
            };

            entity.CreateEnd(request.Id, request.Title, currentUserId);

            await _context.WikiHeadlines.AddAsync(entity, cancellationToken);

            if (!string.IsNullOrEmpty(request.SectionBody) || !string.IsNullOrEmpty(request.SectionName))
            {
                var section = new Section
                {
                    HeadlineId = entity.Id,
                    Content    = request.SectionBody
                };

                section.CreateEnd(Guid.NewGuid(), request.SectionName, currentUserId);

                await _context.Sections.AddAsync(section, cancellationToken);
            }

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
Exemplo n.º 13
0
        public async Task <Unit> Handle(CreateBusinessUnitCommand request, CancellationToken cancellationToken)
        {
            var user   = _userAccessor.GetUser();
            var userId = Guid.Parse(user.FindFirst(ClaimTypes.NameIdentifier).Value);

            var businessUnit = new BusinessUnit
            {
                Description        = request.Description,
                BusinessUnitLeadId = request.BusinessUnitLeadId,
                Address            = request.Address
            };

            businessUnit.CreateEnd(Guid.NewGuid(), request.Name, userId);

            if (request.Active)
            {
                businessUnit.Activate();
            }
            else
            {
                businessUnit.Deactivate();
            }

            await _context.BusinessUnits.AddAsync(businessUnit, cancellationToken);

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
Exemplo n.º 14
0
        public async Task <Unit> Handle(CreateRecruitingPipelineCommand request, CancellationToken cancellationToken)
        {
            var user = _userAccessor.GetUser();

            var entity = new RecruitmentPipeline()
            {
                Name        = request.Name,
                Description = request.Description
            };

            await _context.RecruitingPipelines.AddAsync(entity, cancellationToken);

            await _context.SaveChangesAsync(cancellationToken);

            // Notifications
            var notification = new RecruitingPipelineCreated
            {
                PrimaryEntityId   = entity.Id,
                PrimaryEntityName = entity.Name,
                UserName          = user.Identity.Name
            };
            await _mediator.Publish(notification, cancellationToken);

            return(Unit.Value);
        }
Exemplo n.º 15
0
        public async Task <Unit> Handle(UpdateJobPositionCommand request, CancellationToken cancellationToken)
        {
            var user = _userAccessor.GetUser();

            var userId = Guid.Parse(user.FindFirst(ClaimTypes.NameIdentifier).Value);

            var entity = _context.JobPositions.Find(request.Id);

            entity.Name         = request.Name;
            entity.HourlySalary = request.HourlySalary;
            entity.Description  = request.Description;
            entity.Abbreviation = request.Abbreviation;

            if (request.Active)
            {
                entity.Activate();
            }
            else
            {
                entity.Deactivate();
            }

            _context.JobPositions.Update(entity);

            await _context.SaveChangesAsync(cancellationToken);

            await _mediator.Publish(new JobPositionUpdated
            {
                PrimaryEntityId   = entity.Id,
                PrimaryEntityName = entity.Name,
                UserName          = user.Identity.Name
            }, cancellationToken);

            return(Unit.Value);
        }
Exemplo n.º 16
0
        public async Task <Unit> Handle(RemoveDepartmentTeamCommand request, CancellationToken cancellationToken)
        {
            var userId = Guid.Parse(_userAccessor.GetUser().FindFirst(ClaimTypes.NameIdentifier).Value);

            var invisibleDepartment = _context.Departments.FirstOrDefault(x => x.IsDeletable == false);
            var teamsToRemove       = new List <DepartmentTeam>();

            foreach (var item in request.DepartmentTeamIds)
            {
                var team = _context.DepartmentTeams
                           .First(x => x.Id == item);

                team.DepartmentId = invisibleDepartment.Id;
                team.Deactivate();

                teamsToRemove.Add(team);
            }


            _context.DepartmentTeams.UpdateRange(teamsToRemove);

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
Exemplo n.º 17
0
        public async Task <Unit> Handle(ActivateActivityTypeCommand request, CancellationToken cancellationToken)
        {
            Guid userId = Guid.Parse(_userAccessor.GetUser().FindFirst(ClaimTypes.NameIdentifier).Value);

            ActivityType entity = _context.ActivityTypes.Find(request.Id);

            if (entity == null)
            {
                throw new NotFoundException("Not exist an entity with this id", nameof(ActivityType));
            }

            if (request.Active)
            {
                entity.Activate();
            }
            else
            {
                entity.Deactivate();
            }

            _context.ActivityTypes.Update(entity);

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
Exemplo n.º 18
0
        public async Task <Unit> Handle(ActivateTrackerTypeCommand request, CancellationToken cancellationToken)
        {
            var userId = Guid.Parse(_userAccessor.GetUser().FindFirst(ClaimTypes.NameIdentifier).Value);

            var trackers = new List <TrackerType>();

            foreach (var item in request.Ids)
            {
                var entity = await _context.TrackerTypes.FindAsync(item);

                if (entity == null)
                {
                    throw new NotFoundException(nameof(TrackerType), item);
                }

                if (request.Active)
                {
                    entity.Activate();
                }
                else
                {
                    entity.Deactivate();
                }

                trackers.Add(entity);
            }

            _context.TrackerTypes.UpdateRange(trackers);

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
Exemplo n.º 19
0
        public async Task <Unit> Handle(MoveActivitiesToListCommand request, CancellationToken cancellationToken)
        {
            var user       = _userAccessor.GetUser();
            var activities = new List <Activity>();

            foreach (var id in request.ActivitiesById)
            {
                var activity = await _context.Activities.FindAsync(id);

                if (activity == null)
                {
                    throw new NotFoundException(nameof(Activity), id);
                }

                activity.ActivityListId = request.ActivityListId;


                activities.Add(activity);
            }

            if (activities.Any())
            {
                _context.Activities.UpdateRange(activities);
            }

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
Exemplo n.º 20
0
        public async Task <Unit> Handle(DeleteActivitiesCommand request, CancellationToken cancellationToken)
        {
            var activitiesToDelete = new List <Activity>();

            foreach (var id in request.ActivitiesById)
            {
                var activity = await _context.Activities.FindAsync(id);

                if (activity == null)
                {
                    throw new NotFoundException(nameof(Activity), id);
                }

                activitiesToDelete.Add(activity);
            }

            if (activitiesToDelete.Any())
            {
                _context.Activities.RemoveRange(activitiesToDelete);

                await _context.SaveChangesAsync(cancellationToken);
            }

            return(Unit.Value);
        }
Exemplo n.º 21
0
        public async Task <Unit> Handle(UpdateRecruitmentStageCommand request, CancellationToken cancellationToken)
        {
            var user = _userAccessor.GetUser();

            var entity = await _context.RecruitmentStages.FindAsync(request.Id);

            entity.Name = request.Name;

            //TODO: Check for pipeline switch use case
            //entity.PipelineId = request.RecruitingPipelineId;

            _context.RecruitmentStages.Update(entity);

            await _context.SaveChangesAsync(cancellationToken);

            // Notifications
            var notification = new RecruitmentStageUpdated
            {
                PrimaryEntityId   = entity.Id,
                PrimaryEntityName = entity.Name,
                UserName          = user.Identity.Name
            };

            await _mediator.Publish(notification, cancellationToken);

            return(Unit.Value);
        }
Exemplo n.º 22
0
        public async Task <Unit> Handle(QuickAddCandidateCommand request, CancellationToken cancellationToken)
        {
            var user = _userAccessor.GetUser();

            var job = await _context.JobPositions.FindAsync(request.JobPositionId);

            var entity = new Candidate(CompoundName.Create(request.FirstName, request.LastName).Value, job,
                                       ContactInfo.Create(request.PhoneNumber, request.Email).Value);
            var stage = await _context.RecruitmentStages.FindAsync(request.RecruitmentStageId);

            stage.AddCandidate(entity);


            _context.RecruitmentStages.Update(stage);
            await _context.SaveChangesAsync(cancellationToken);

            // Notifications
            var notification = new CandidateCreated
            {
                PrimaryEntityId   = entity.Id,
                PrimaryEntityName = entity.Name.GetFullName,
                UserName          = user.Identity.Name
            };
            await _mediator.Publish(notification, cancellationToken);

            return(Unit.Value);
        }
Exemplo n.º 23
0
        public async Task <Unit> Handle(DeleteCheckItemCommand request, CancellationToken cancellationToken)
        {
            var entity = await _context.CheckItems.FindAsync(request.CheckItemId);

            if (entity.LoggedTimeId != null)
            {
                var loggedTime = await _context.LoggedTimes.FindAsync(entity.LoggedTimeId);

                var activity = await _context.Activities
                               .Include(a => a.LoggedTimes)
                               .FirstOrDefaultAsync(a => a.Id == entity.ActivityId, cancellationToken);

                if (activity != null)
                {
                    var estimatedTime           = activity.EstimatedHours ?? 0;
                    var totalActivityLoggedTime = activity.LoggedTimes.Sum(lt => lt.Time) - loggedTime.Time;
                    var actualPercentage        = (totalActivityLoggedTime * 100) / estimatedTime;

                    activity.Progress = (int)actualPercentage;

                    _context.Activities.Update(activity);
                }

                _context.LoggedTimes.Remove(loggedTime);
            }

            _context.CheckItems.Remove(entity);
            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
Exemplo n.º 24
0
        public async Task <Unit> Handle(CreateRecruitmentStageCommand request, CancellationToken cancellationToken)
        {
            var user     = _userAccessor.GetUser();
            var pipeline = await _context.RecruitingPipelines.FindAsync(request.RecruitingPipelineId);

            var operation = pipeline.AddStage(request.Name);

            if (operation.IsFailure)
            {
                throw new InvalidOperationException(operation.Error);
            }

            _context.RecruitingPipelines.Update(pipeline);
            await _context.SaveChangesAsync(cancellationToken);

            // Notifications
            var notification = new RecruitmentStageCreated
            {
                PrimaryEntityId   = pipeline.Id,
                PrimaryEntityName = pipeline.Name,
                UserName          = user.Identity.Name
            };
            await _mediator.Publish(notification, cancellationToken);

            return(Unit.Value);
        }
Exemplo n.º 25
0
        public async Task <Unit> Handle(MoveTrackerTypeCommand request, CancellationToken cancellationToken)
        {
            var checkActivity = await _context.ActivityTypes.FindAsync(request.ActivityTypeId);

            if (checkActivity == null)
            {
                throw new NotFoundException(nameof(ActivityType), request.ActivityTypeId);
            }

            foreach (var item in request.TrackersIds)
            {
                var tracker = await _context.TrackerTypes.FindAsync(item);

                if (tracker == null)
                {
                    throw new NotFoundException(nameof(TrackerType), item);
                }

                tracker.ActivityTypeId = request.ActivityTypeId;
                _context.TrackerTypes.Update(tracker);
            }

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
Exemplo n.º 26
0
        public async Task <Unit> Handle(BulkMoveCandidateToEmployeeCommand request, CancellationToken cancellationToken)
        {
            foreach (var id in request.CandidatesId)
            {
                var candidate = await _context.Candidates.FindAsync(id);

                var operation = candidate.ChangeStatus(Domain.HrmEntities.Enums.CandidateStatus.Won);

                _context.Candidates.Update(candidate);

                var employee = new ApplicationUser
                {
                    FirstName   = candidate.Name.FirstName,
                    LastName    = candidate.Name.LastName,
                    Email       = candidate.ContactInfo.Email,
                    JobPosition = candidate.JobPosition
                };

                await _context.ApplicationUsers.AddAsync(employee);
            }

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
Exemplo n.º 27
0
        public async Task <Unit> Handle(BulkDeleteRequestCommand request, CancellationToken cancellationToken)
        {
            var requestsToDelete = new List <ChangeRequest>();

            foreach (var id in request.Requests)
            {
                var changeRequest = await _context.ChangeRequests.FindAsync(id);

                if (changeRequest == null)
                {
                    throw new NotFoundException(nameof(ChangeRequest), id);
                }

                requestsToDelete.Add(changeRequest);
            }

            if (!requestsToDelete.Any())
            {
                return(Unit.Value);
            }

            _context.ChangeRequests.RemoveRange(requestsToDelete);

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
Exemplo n.º 28
0
        public async Task <Unit> Handle(UpdateActivityListStatusCommand request, CancellationToken cancellationToken)
        {
            var user   = _userAccessor.GetUser();
            var userId = Guid.Parse(user.FindFirst(ClaimTypes.NameIdentifier).Value);

            var entity = _context.ActivityLists.Find(request.Id);

            entity.ActivityListStatus = request.ActivityListStatus;



            _context.ActivityLists.Update(entity);

            await _context.SaveChangesAsync(cancellationToken);

            var notification = new ActivityListUpdated()
            {
                PrimaryEntityId   = entity.Id,
                PrimaryEntityName = entity.Name,
                GroupEntityId     = entity.ProjectId,
                GroupEntityName   = entity.Project?.Name ?? "",
                Recipients        = await _context.ProjectMembers.Include(x => x.User)
                                    .Where(x => x.ProjectId == entity.ProjectId).Select(x => x.User.Email).ToListAsync(cancellationToken),
                UserName = user.Identity.Name
            };

            await _mediator.Publish(notification, cancellationToken);

            return(Unit.Value);
        }
Exemplo n.º 29
0
        public async Task <Unit> Handle(BulkSetProjectPriorityCommand request, CancellationToken cancellationToken)
        {
            var user     = _userAccessor.GetUser();
            var projects = new List <Project>();

            foreach (var id in request.Projects)
            {
                var project = await _context.Projects.FindAsync(id);

                if (project == null)
                {
                    throw new NotFoundException(nameof(Project), id);
                }

                project.Priority = request.Priority;

                projects.Add(project);
            }

            if (projects.Any())
            {
                _context.Projects.UpdateRange(projects);

                await _context.SaveChangesAsync(cancellationToken);
            }

            return(Unit.Value);
        }
Exemplo n.º 30
0
        public async Task <Unit> Handle(UpdateTrackerTypeCommand request, CancellationToken cancellationToken)
        {
            var user = _userAccessor.GetUser();

            var userId = Guid.Parse(user.FindFirst(ClaimTypes.NameIdentifier).Value);

            var entity = _context.TrackerTypes.Find(request.Id);

            entity.Name           = request.Name;
            entity.ActivityTypeId = request.ActivityTypeId;

            if (request.Active)
            {
                entity.Activate();
            }
            else
            {
                entity.Deactivate();
            }

            _context.TrackerTypes.Update(entity);

            await _context.SaveChangesAsync(cancellationToken);

            // Notifications
            await _mediator.Publish(new TrackerTypeUpdated
            {
                PrimaryEntityId   = entity.Id,
                PrimaryEntityName = entity.Name,
                UserName          = user.Identity.Name,
            }, cancellationToken);

            return(Unit.Value);
        }