コード例 #1
0
ファイル: KudosService.cs プロジェクト: VismaLietuva/simoona
        private async Task <AddKudosDto> GenerateLogForKudosMinusOperationAsync(AddKudosDto kudos)
        {
            var minusKudosType = await _kudosTypesDbSet.AsNoTracking().FirstAsync(n => n.Type == KudosTypeEnum.Minus);

            var kudosLogForMinusKudos = new AddKudosLogDto
            {
                PointsTypeId   = minusKudosType.Id,
                Comment        = kudos.KudosLog.Comment,
                MultiplyBy     = kudos.KudosLog.MultiplyBy,
                OrganizationId = kudos.KudosLog.OrganizationId,
                UserId         = kudos.KudosLog.UserId
            };

            var minusKudos = new AddKudosDto
            {
                KudosLog              = kudosLogForMinusKudos,
                ReceivingUser         = kudos.SendingUser,
                SendingUser           = kudos.ReceivingUser,
                TotalKudosPointsInLog = kudos.TotalKudosPointsInLog,
                KudosType             = MapKudosTypesToDto(minusKudosType),
                PictureId             = kudos.PictureId
            };

            return(minusKudos);
        }
コード例 #2
0
ファイル: KudosService.cs プロジェクト: VismaLietuva/simoona
        private async Task SendKudosAsync(AddKudosDto kudos)
        {
            await ValidateSendKudosAsync(kudos);
            await InsertSendKudosLogAsync(kudos);

            kudos.TotalPointsSent += kudos.TotalKudosPointsInLog;
        }
コード例 #3
0
ファイル: KudosService.cs プロジェクト: VismaLietuva/simoona
        private async Task InsertSendKudosLogAsync(AddKudosDto kudos)
        {
            InsertKudosLog(kudos, KudosStatus.Approved);

            var minusKudos = await GenerateLogForKudosMinusOperationAsync(kudos);

            InsertKudosLog(minusKudos, KudosStatus.Approved);
        }
コード例 #4
0
ファイル: KudosService.cs プロジェクト: VismaLietuva/simoona
        private async Task ValidateSendKudosAsync(AddKudosDto kudos)
        {
            _kudosServiceValidator.ValidateSendingToSameUserAsReceiving(kudos.SendingUser.Id, kudos.ReceivingUser.Id);

            _kudosServiceValidator.ValidateUserAvailableKudos(kudos.SendingUser.RemainingKudos, kudos.TotalKudosPointsInLog * kudos.KudosLog.ReceivingUserIds.Count());

            await ValidateAvailableKudosThisMonthAsync(kudos, kudos.TotalKudosPointsInLog);
        }
コード例 #5
0
ファイル: KudosService.cs プロジェクト: VismaLietuva/simoona
        private async Task MinusKudosAsync(AddKudosDto kudos)
        {
            var hasKudosAdminPermission = await HasKudosAdministratorPermissionAsync(kudos.KudosLog);

            var hasKudosServiceRequestCategoryPermission = await HasKudosServiceRequestCategoryPermissionsAsync();

            _kudosServiceValidator.ValidateKudosMinusPermission(hasKudosAdminPermission || hasKudosServiceRequestCategoryPermission);

            InsertKudosLog(kudos, KudosStatus.Pending);
        }
コード例 #6
0
ファイル: KudosService.cs プロジェクト: VismaLietuva/simoona
        private async Task ValidateAvailableKudosThisMonthAsync(AddKudosDto kudos, decimal totalKudosPointsInLog)
        {
            var timestamp = DateTime.UtcNow;

            var currentMonthSum = await _kudosLogsDbSet
                                  .Where(l => l.CreatedBy == kudos.SendingUser.Id &&
                                         l.Created.Month == timestamp.Month &&
                                         l.Created.Year == timestamp.Year &&
                                         l.KudosSystemType == KudosTypeEnum.Send &&
                                         l.OrganizationId == kudos.KudosLog.OrganizationId)
                                  .Select(p => p.Points)
                                  .DefaultIfEmpty(0)
                                  .SumAsync();

            currentMonthSum += kudos.TotalPointsSent;

            _kudosServiceValidator.ValidateUserAvailableKudosToSendPerMonth(totalKudosPointsInLog, BusinessLayerConstants.KudosAvailableToSendThisMonth - currentMonthSum);
        }
コード例 #7
0
ファイル: KudosService.cs プロジェクト: VismaLietuva/simoona
        private async Task ChooseKudosifyTypeAsync(AddKudosDto kudos)
        {
            switch (kudos.KudosType.Type)
            {
            case KudosTypeEnum.Minus:
                await MinusKudosAsync(kudos);

                break;

            case KudosTypeEnum.Send:
                await SendKudosAsync(kudos);

                break;

            default:
                AddNewKudos(kudos);
                break;
            }
        }
コード例 #8
0
        public async Task NotifyAboutKudosSentAsync(AddKudosDto kudosDto)
        {
            var organizationName = (await GetOrganizationNameAsync(kudosDto.KudosLog.OrganizationId)).ShortName;

            var recipient = _usersDbSet
                            .Where(u => kudosDto.ReceivingUser.Id.Contains(u.Id))
                            .Select(u => u.Email);

            var userNotificationSettingsUrl = _appSettings.UserNotificationSettingsUrl(organizationName);
            var kudosProfileUrl             = _appSettings.KudosProfileUrl(organizationName, kudosDto.ReceivingUser.Id);
            var subject = Resources.Models.Kudos.Kudos.EmailSubject;

            var emailTemplateViewModel = new KudosSentEmailTemplateViewModel(userNotificationSettingsUrl,
                                                                             kudosDto.SendingUser.FullName,
                                                                             kudosDto.TotalKudosPointsInLog,
                                                                             kudosDto.KudosLog.Comment,
                                                                             kudosProfileUrl);

            var body = _mailTemplate.Generate(emailTemplateViewModel, EmailTemplateCacheKeys.KudosSent);
            await _mailingService.SendEmailAsync(new EmailDto(recipient, subject, body));
        }
コード例 #9
0
ファイル: KudosService.cs プロジェクト: VismaLietuva/simoona
        private void InsertKudosLog(AddKudosDto kudos, KudosStatus status)
        {
            var log = new KudosLog
            {
                CreatedBy       = kudos.KudosLog.UserId,
                EmployeeId      = kudos.ReceivingUser.Id,
                ModifiedBy      = kudos.KudosLog.UserId,
                MultiplyBy      = kudos.KudosLog.MultiplyBy,
                KudosTypeName   = kudos.KudosType.Name,
                KudosTypeValue  = kudos.KudosType.Value,
                KudosSystemType = kudos.KudosType.Type,
                Status          = status,
                Comments        = kudos.KudosLog.Comment,
                Created         = DateTime.UtcNow,
                Modified        = DateTime.UtcNow,
                OrganizationId  = kudos.KudosLog.OrganizationId,
                Points          = kudos.TotalKudosPointsInLog,
                PictureId       = kudos.PictureId
            };

            _kudosLogsDbSet.Add(log);
        }
コード例 #10
0
ファイル: KudosService.cs プロジェクト: VismaLietuva/simoona
 private void AddNewKudos(AddKudosDto kudos)
 {
     InsertKudosLog(kudos, KudosStatus.Pending);
 }