private AddKudosDTO GenerateLogForKudosMinusOperation(AddKudosDTO kudosDTO) { var minusKudosType = _kudosTypesDbSet .Where(n => n.Type == ConstBusinessLayer.KudosTypeEnum.Minus) .FirstOrDefault(); var kudosLogForMinusKudos = new AddKudosLogDTO { PointsTypeId = minusKudosType.Id, Comment = kudosDTO.KudosLog.Comment, MultiplyBy = kudosDTO.KudosLog.MultiplyBy, OrganizationId = kudosDTO.KudosLog.OrganizationId, UserId = kudosDTO.KudosLog.UserId }; var minusKudosDTO = new AddKudosDTO { KudosLog = kudosLogForMinusKudos, ReceivingUser = kudosDTO.SendingUser, SendingUser = kudosDTO.ReceivingUser, TotalKudosPointsInLog = kudosDTO.TotalKudosPointsInLog, KudosType = minusKudosType, PictureId = kudosDTO.PictureId }; return(minusKudosDTO); }
private void InsertSendKudosLog(AddKudosDTO kudosDTO) { InsertKudosLog(kudosDTO, KudosStatus.Approved); var minusKudosDTO = GenerateLogForKudosMinusOperation(kudosDTO); InsertKudosLog(minusKudosDTO, KudosStatus.Approved); }
private void MinusKudos(AddKudosDTO kudosDTO) { var hasKudosAdminPermission = HasKudosAdministratorPermission(kudosDTO.KudosLog); var hasKudosServiceRequestCategoryPermission = HasKudosServiceRequestCategoryPermissions(kudosDTO.KudosLog); _kudosServiceValidator.ValidateKudosMinusPermission(hasKudosAdminPermission || hasKudosServiceRequestCategoryPermission); InsertKudosLog(kudosDTO, KudosStatus.Pending); }
private void ValidateSendKudos(AddKudosDTO kudosDTO) { _kudosServiceValidator.ValidateSendingToSameUserAsReceiving( kudosDTO.SendingUser.Id, kudosDTO.ReceivingUser.Id); _kudosServiceValidator.ValidateUserAvailableKudos( kudosDTO.SendingUser.RemainingKudos, kudosDTO.TotalKudosPointsInLog * kudosDTO.KudosLog.ReceivingUserIds.Count()); ValidateAvailableKudosThisMonth(kudosDTO, kudosDTO.TotalKudosPointsInLog); }
private void ChooseKudosifyType(AddKudosDTO kudosDTO) { switch (kudosDTO.KudosType.Type) { case ConstBusinessLayer.KudosTypeEnum.Minus: MinusKudos(kudosDTO); break; case ConstBusinessLayer.KudosTypeEnum.Send: SendKudos(kudosDTO); break; default: AddNewKudos(kudosDTO); break; } }
private void ValidateAvailableKudosThisMonth(AddKudosDTO kudosDTO, decimal totalKudosPointsInLog) { var timestaps = DateTime.UtcNow; var currentMonthSum = _kudosLogsDbSet .Where(l => l.CreatedBy == kudosDTO.SendingUser.Id && l.Created.Month == timestaps.Month && l.Created.Year == timestaps.Year && l.KudosSystemType == ConstBusinessLayer.KudosTypeEnum.Send && l.OrganizationId == kudosDTO.KudosLog.OrganizationId) .Select(p => p.Points) .DefaultIfEmpty(0) .Sum(); currentMonthSum += kudosDTO.TotalPointsSent; _kudosServiceValidator.ValidateUserAvailableKudosToSendPerMonth(totalKudosPointsInLog, ConstBusinessLayer.KudosAvailableToSendThisMonth - currentMonthSum); }
public void NotifyAboutKudosSent(AddKudosDTO kudosDto) { var organizationName = GetOrganizationName(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); _mailingService.SendEmail(new EmailDto(recipient, subject, body)); }
private void InsertKudosLog(AddKudosDTO kudosDTO, KudosStatus status) { var log = new KudosLog { CreatedBy = kudosDTO.KudosLog.UserId, EmployeeId = kudosDTO.ReceivingUser.Id, ModifiedBy = kudosDTO.KudosLog.UserId, MultiplyBy = kudosDTO.KudosLog.MultiplyBy, KudosTypeName = kudosDTO.KudosType.Name, KudosTypeValue = kudosDTO.KudosType.Value, KudosSystemType = kudosDTO.KudosType.Type, Status = status, Comments = kudosDTO.KudosLog.Comment, Created = DateTime.UtcNow, Modified = DateTime.UtcNow, OrganizationId = kudosDTO.KudosLog.OrganizationId, Points = kudosDTO.TotalKudosPointsInLog, PictureId = kudosDTO.PictureId }; _kudosLogsDbSet.Add(log); }
private void AddNewKudos(AddKudosDTO kudosDTO) { InsertKudosLog(kudosDTO, KudosStatus.Pending); }
private void SendKudos(AddKudosDTO kudosDTO) { ValidateSendKudos(kudosDTO); InsertSendKudosLog(kudosDTO); kudosDTO.TotalPointsSent += kudosDTO.TotalKudosPointsInLog; }