Exemplo n.º 1
0
        public async Task <IActionResult> ShareContent(ShareContentViewModel viewModel)
        {
            var userId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            viewModel.UserId = userId;
            var isSuccess = await _meetingContentManager.ShareContentAsync(viewModel);

            if (!isSuccess)
            {
                return(BadRequest());
            }
            return(Ok());
        }
        public async Task <bool> ShareContentAsync(ShareContentViewModel viewModel)
        {
            var query = from c in UnitOfWork.MeetingContentRepository
                        .GetQuery(x => x.Id == viewModel.ContentId)
                        .Include(x => x.MeetingAgenda)
                        .ThenInclude(x => x.MeetingTime)
                        .ThenInclude(x => x.MeetingTopic)
                        .ThenInclude(x => x.MeetingType)
                        join note in UnitOfWork.MeetingNoteRepository
                        .GetQuery(x => x.UserId == viewModel.UserId && !x.IsRemoved)
                        on c.Id equals note.MeetingContentId into lj
                        from note in lj.DefaultIfEmpty()
                        select new
            {
                Id         = c.Id,
                Ordinal    = c.Ordinal,
                FileBase64 = note == null ? c.FileBase64 : note.Note,
                AgendaName = c.MeetingAgenda.Name,
                Time       = c.MeetingAgenda.MeetingTime,
                TopicName  = c.MeetingAgenda.MeetingTime.MeetingTopic.Name,
                TypeName   = c.MeetingAgenda.MeetingTime.MeetingTopic.MeetingType.Name
            };

            var content = await query.FirstOrDefaultAsync();

            if (content == null)
            {
                return(false);
            }
            var attachment = new Attachment(new MemoryStream(content.FileBase64), $"{content.AgendaName}_{content.Ordinal}.jpg");

            _emailManager.SendEmail(new EmailViewModel
            {
                EmailTo    = viewModel.Email,
                Subject    = $"ข้อมูลการประชุม{content.TopicName}",
                Body       = $@"
                ประเภทการประชุม: {content.TypeName}
                ชื่อหัวข้อวาระการประชุม: {content.TopicName}
                ครั้งที่การประชุม: {content.Time.Count}/{content.Time.FiscalYear}
                ชื่อระเบียบวาระการประชุม​: {content.AgendaName}",
                Attachment = attachment
            });
            return(true);
        }