コード例 #1
0
        public async Task NotifyAboutNewServiceRequestAsync(CreatedServiceRequestDto createdServiceRequest)
        {
            var newServiceRequest = await _serviceRequestDbSet.SingleAsync(s => s.Id == createdServiceRequest.ServiceRequestId);

            var organizationName = await GetOrganizationNameAsync(newServiceRequest.OrganizationId);

            var emails = await _usersDbSet
                         .Where(x => x.ServiceRequestCategoriesAssigned.Any(y => y.Name == newServiceRequest.CategoryName))
                         .Where(x => x.Id != newServiceRequest.EmployeeId)
                         .Select(x => x.Email)
                         .ToListAsync();

            var subject = Resources.Models.ServiceRequest.ServiceRequest.EmailMessageSubject;
            var userNotificationSettingsUrl = _appSettings.UserNotificationSettingsUrl(organizationName);
            var serviceRequestUrl           = _appSettings.ServiceRequestUrl(organizationName, newServiceRequest.Id);

            var emailTemplateViewModel = new ServiceRequestEmailTemplateViewModel(userNotificationSettingsUrl,
                                                                                  newServiceRequest.Title,
                                                                                  await GetUserFullNameAsync(newServiceRequest.EmployeeId),
                                                                                  serviceRequestUrl);

            var body = _mailTemplate.Generate(emailTemplateViewModel, EmailPremiumTemplateCacheKeys.ServiceRequest);

            await _mailingService.SendEmailAsync(new EmailDto(emails, subject, body));
        }
コード例 #2
0
        public async Task CreateNewServiceRequestAsync(ServiceRequestDto newServiceRequestDto, UserAndOrganizationDto userAndOrganizationDto)
        {
            await ValidateServiceRequestForCreateAsync(newServiceRequestDto);

            var serviceRequestStatusId = await _serviceRequestStatusDbSet
                                         .Where(x => x.Title.Equals("Open"))
                                         .Select(x => x.Id)
                                         .FirstAsync();

            var serviceRequestCategory = await _serviceRequestCategoryDbSet
                                         .FirstOrDefaultAsync(x => x.Id == newServiceRequestDto.ServiceRequestCategoryId);

            if (serviceRequestCategory == null)
            {
                throw new ValidationException(ErrorCodes.ContentDoesNotExist, "Service request category does not exist");
            }

            var timestamp = DateTime.UtcNow;

            var serviceRequest = new ServiceRequest
            {
                Description    = newServiceRequestDto.Description,
                Title          = newServiceRequestDto.Title,
                CreatedBy      = userAndOrganizationDto.UserId,
                ModifiedBy     = userAndOrganizationDto.UserId,
                EmployeeId     = userAndOrganizationDto.UserId,
                KudosAmmount   = newServiceRequestDto.KudosAmmount,
                OrganizationId = userAndOrganizationDto.OrganizationId,
                CategoryName   = serviceRequestCategory.Name,
                StatusId       = serviceRequestStatusId,
                PriorityId     = newServiceRequestDto.PriorityId,
                Created        = timestamp,
                Modified       = timestamp,
                PictureId      = newServiceRequestDto.PictureId
            };

            if (newServiceRequestDto.KudosShopItemId != null)
            {
                serviceRequest.KudosShopItemId = newServiceRequestDto.KudosShopItemId;
            }

            _serviceRequestsDbSet.Add(serviceRequest);
            await _uow.SaveChangesAsync(false);

            var srqDto = new CreatedServiceRequestDto {
                ServiceRequestId = serviceRequest.Id
            };

            _asyncRunner.Run <IServiceRequestNotificationService>(async notifier => await notifier.NotifyAboutNewServiceRequestAsync(srqDto), _uow.ConnectionName);
        }