コード例 #1
0
 public async Task <IActionResult> GetIssueDetails([FromBody] SearchIssueDetailFormModel searchIssueDetailForm)
 {
     return(Ok(GetRequestResult(await _issueService.GetIssueDetailsAsync(HttpContext.GetUser(), searchIssueDetailForm))));
 }
コード例 #2
0
        public async Task <SearchIssueDetailsViewModel> GetIssueDetailsAsync(User user, SearchIssueDetailFormModel searchIssueDetailForm)
        {
            try
            {
                var searchIssueDetailsViewModel = new SearchIssueDetailsViewModel();
                var querable = _context.IssueDetails.Include(c => c.User).Include(c => c.IssueDetailComments).Include(c => c.IssueDetailAttachments).Include(c => c.IssueDetailLikes).Include(c => c.EquipmentAttachmentIssueDetailSubscriptions).Where(c => c.IssueId == searchIssueDetailForm.IssueId).AsQueryable();
                if (searchIssueDetailForm.IssueDetailsId.HasValue)
                {
                    querable = querable.Where(c => c.Id == searchIssueDetailForm.IssueDetailsId);
                }
                var resp = await querable.ToListAsync();

                if (resp is null)
                {
                    throw new ExperienceManagementGlobalException(IssueServiceErrors.IssueNotFoundError);
                }
                var result         = _context.Issues.Include(c => c.EquipmentIssueSubscriptions).FirstOrDefault(c => c.Id == searchIssueDetailForm.IssueId);
                var issueviewmodel = new IssueViewModel();
                if (result != null)
                {
                    issueviewmodel.Id           = result.Id;
                    issueviewmodel.AnswerCount  = result.AnswerCounts;
                    issueviewmodel.CreationDate = result.CreationDate;
                    issueviewmodel.Description  = result.Description;
                    issueviewmodel.Equipments   = result.EquipmentIssueSubscriptions.Select(x => new EquipmentViewModel()
                    {
                        Description   = x.Equipment.Description,
                        EquipmentName = x.Equipment.EquipmentName,
                        Id            = x.EquipmentId
                    }).ToList();
                    issueviewmodel.IsActive       = result.IsActive;
                    issueviewmodel.SumLikes       = resp.Sum(c => c.Likes);
                    issueviewmodel.IssueType      = result.IssueType;
                    issueviewmodel.LastUpdateDate = result.LastUpdateDate;
                    issueviewmodel.Title          = result.Title;
                    issueviewmodel.UserId         = result.UserId;
                    issueviewmodel.UserName       = result.User.Username;
                    issueviewmodel.FileId         = result.FileId;
                }



                var issueDetailViewModel = new List <IssueDetailViewModel>();
                resp.ForEach(response =>
                {
                    var issuedetail = new IssueDetailViewModel()
                    {
                        Caption                       = response.Caption,
                        CreationDate                  = response.CreationDate,
                        Text                          = response.Text,
                        IsCorrectAnswer               = response.IsCorrectAnswer,
                        IssueId                       = response.IssueId,
                        Likes                         = response.Likes,
                        IsUserLike                    = response.IssueDetailLikes.Any(d => d.UserId == user.Id),
                        IssueDetailId                 = response.Id,
                        UserId                        = response.UserId,
                        UserName                      = response.User.Username,
                        LastUpdateDate                = response.LastUpdateDate,
                        IssueDetailComments           = new List <IssueDetailCommentViewModel>(),
                        IssueDetailAttachments        = new List <IssueDetailAttachmentViewModel>(),
                        EquipmentAttachmentViewModels = new List <EquipmentAttachmentViewModel>()
                    };
                    response.IssueDetailComments.ToList().ForEach(c =>
                    {
                        var IssueDetailComment = new IssueDetailCommentViewModel()
                        {
                            Comment       = c.Comment,
                            CreationDate  = c.CreationDate,
                            IssueDetailId = c.IssueDetailId,
                            Id            = c.Id,
                            UserId        = c.UserId,
                            UserName      = c.User.Username
                        };
                        issuedetail.IssueDetailComments.Add(IssueDetailComment);
                    });
                    response.IssueDetailAttachments.ToList().ForEach(c =>
                    {
                        var IssueDetailAtt = new IssueDetailAttachmentViewModel()
                        {
                            FileSize      = c.FileSize,
                            FileType      = c.FileType,
                            FileId        = c.FileId,
                            ContentType   = ContentType.GetContentType($".{c.FileType}"),
                            IssueDetailId = c.IssueDetailId,
                            Id            = c.Id,
                        };
                        issuedetail.IssueDetailAttachments.Add(IssueDetailAtt);
                    });
                    response.EquipmentAttachmentIssueDetailSubscriptions?.ToList().ForEach(c =>
                    {
                        var equipmentAttachment = new EquipmentAttachmentViewModel()
                        {
                            EquipmentAttachmentId   = c.Id,
                            CreationDate            = c.EquipmentAttachment.CreationDate,
                            Description             = c.EquipmentAttachment.Description,
                            EquipmentAttachmentName = c.EquipmentAttachment.EquipmentAttachmentName,
                            EquipmentId             = c.EquipmentAttachment.EquipmentId,
                            EquipmentAttachmentType = c.EquipmentAttachment.EquipmentAttachmentType,
                            FileId   = c.EquipmentAttachment.FileId,
                            FileSize = c.EquipmentAttachment.FileSize,
                            FileType = c.EquipmentAttachment.FileType
                        };
                        issuedetail.EquipmentAttachmentViewModels.Add(equipmentAttachment);
                    });

                    issueDetailViewModel.Add(issuedetail);
                });
                searchIssueDetailsViewModel.issueDetailViewModel = issueDetailViewModel;
                searchIssueDetailsViewModel.IssueViewModel       = issueviewmodel;
                return(searchIssueDetailsViewModel);
            }
            catch (Exception ex)
            {
                throw new ExperienceManagementGlobalException(IssueServiceErrors.GetIssueDetailsError, ex);
            }
        }