forked from ddrilling/AsbCloudServer
#7065595 fix
This commit is contained in:
parent
703112d894
commit
236c32b16c
@ -38,14 +38,14 @@ namespace AsbCloudApp.Repositories
|
||||
Task<IEnumerable<UserDto>> GetAvailableUsersAsync(int idWell, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Сохранение категории файла
|
||||
/// Возвращаент категорию файла
|
||||
/// </summary>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="idCategory"></param>
|
||||
/// <param name="idUser"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<WellFinalDocumentDBDto> SaveCategoryAsync(int idWell, int idCategory, int idUser, CancellationToken token);
|
||||
Task<WellFinalDocumentDBDto> GetCategoryAsync(int idWell, int idCategory, int idUser, CancellationToken token);
|
||||
}
|
||||
#nullable disable
|
||||
}
|
||||
|
@ -33,27 +33,27 @@ namespace AsbCloudInfrastructure.Repository
|
||||
///<inheritdoc/>
|
||||
public async Task<IEnumerable<WellFinalDocumentDBDto>> UpdateRangeAsync(int idWell, IEnumerable<WellFinalDocumentInputDto>? dtos, CancellationToken token)
|
||||
{
|
||||
if (dtos is not null)
|
||||
{
|
||||
var entities = dtos
|
||||
.Where(dto => dto.IdsPublishers?.Any() == true)
|
||||
.SelectMany(dto => dto.IdsPublishers
|
||||
.Select(idUser => new WellFinalDocument
|
||||
{
|
||||
IdCategory = dto.IdCategory,
|
||||
IdWell = idWell,
|
||||
IdUser = idUser
|
||||
}));
|
||||
if (dtos is null)
|
||||
throw new ArgumentInvalidException("Данные по категориям отсутствуют.");
|
||||
|
||||
var itemsToDelete = context.WellFinalDocuments.Where(d => d.IdWell == idWell);
|
||||
context.WellFinalDocuments.RemoveRange(itemsToDelete);
|
||||
var entities = dtos
|
||||
.Where(dto => dto.IdsPublishers?.Any() == true)
|
||||
.SelectMany(dto => dto.IdsPublishers
|
||||
.Select(idUser => new WellFinalDocument
|
||||
{
|
||||
IdCategory = dto.IdCategory,
|
||||
IdWell = idWell,
|
||||
IdUser = idUser
|
||||
}));
|
||||
|
||||
await context.WellFinalDocuments.AddRangeAsync(entities).ConfigureAwait(false);
|
||||
await context.SaveChangesAsync(token).ConfigureAwait(false);
|
||||
var itemsToDelete = context.WellFinalDocuments.Where(d => d.IdWell == idWell);
|
||||
context.WellFinalDocuments.RemoveRange(itemsToDelete);
|
||||
|
||||
context.WellFinalDocuments.AddRange(entities);
|
||||
await context.SaveChangesAsync(token).ConfigureAwait(false);
|
||||
|
||||
return entities.Adapt<IEnumerable<WellFinalDocumentDBDto>>();
|
||||
|
||||
return entities.Adapt<IEnumerable<WellFinalDocumentDBDto>>();
|
||||
}
|
||||
throw new ArgumentInvalidException("Данные по категориям отсутствуют.");
|
||||
}
|
||||
|
||||
///<inheritdoc/>
|
||||
@ -108,6 +108,7 @@ namespace AsbCloudInfrastructure.Repository
|
||||
public async Task<IEnumerable<UserDto>> GetAvailableUsersAsync(int idWell, CancellationToken token)
|
||||
{
|
||||
var companyIds = await context.RelationCompaniesWells
|
||||
.AsNoTracking()
|
||||
.Where(x => x.IdWell == idWell).Select(x => x.IdCompany)
|
||||
.ToListAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
@ -123,7 +124,7 @@ namespace AsbCloudInfrastructure.Repository
|
||||
}
|
||||
|
||||
///<inheritdoc/>
|
||||
public async Task<WellFinalDocumentDBDto> SaveCategoryAsync(int idWell, int idCategory, int idUser, CancellationToken token)
|
||||
public async Task<WellFinalDocumentDBDto> GetCategoryAsync(int idWell, int idCategory, int idUser, CancellationToken token)
|
||||
{
|
||||
var entity = await context.WellFinalDocuments
|
||||
.AsNoTracking()
|
||||
|
@ -4,7 +4,6 @@ using AsbCloudApp.Repositories;
|
||||
using AsbCloudApp.Requests;
|
||||
using AsbCloudApp.Services;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@ -51,11 +50,8 @@ namespace AsbCloudInfrastructure.Services
|
||||
{
|
||||
var data = await wellFinalDocumentsRepository.UpdateRangeAsync(idWell, dtos, token);
|
||||
|
||||
if (data.Any())
|
||||
{
|
||||
var message = "от Вас ожидается загрузка на портал документа «{0}»";
|
||||
await GenerateMessageAsync(data, message, token);
|
||||
}
|
||||
var message = "от Вас ожидается загрузка на портал документа «{0}»";
|
||||
await GenerateMessageAsync(data, message, token);
|
||||
|
||||
return data.Count();
|
||||
}
|
||||
@ -63,13 +59,16 @@ namespace AsbCloudInfrastructure.Services
|
||||
///<inheritdoc/>
|
||||
public async Task<int> SaveCategoryFileAsync(int idWell, int idCategory, int idUser, Stream fileStream, string fileName, CancellationToken token)
|
||||
{
|
||||
var dto = await wellFinalDocumentsRepository.SaveCategoryAsync(idWell, idCategory, idUser, token)
|
||||
var dto = await wellFinalDocumentsRepository.GetCategoryAsync(idWell, idCategory, idUser, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
var file = await fileService.SaveAsync(dto.IdWell, dto.IdUser, dto.IdCategory, fileName,
|
||||
fileStream, token).ConfigureAwait(false);
|
||||
|
||||
return file?.Id ?? FileServiceThrewException; //TODO: изменить когда файловый сервис будет переведен на nullable
|
||||
if (file is not null)
|
||||
return file.Id;
|
||||
|
||||
return FileServiceThrewException;
|
||||
}
|
||||
|
||||
///<inheritdoc/>
|
||||
@ -130,12 +129,12 @@ namespace AsbCloudInfrastructure.Services
|
||||
var category = await fileCategoryService.GetOrDefaultAsync(item.IdCategory, token);
|
||||
var well = await wellService.GetOrDefaultAsync(item.IdWell, token);
|
||||
|
||||
SendMessage(well, user, category.Name, message, token);
|
||||
SendMessage(well, user, category.Name, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SendMessage(WellDto? well, UserDto user, string documentCategory, string message, CancellationToken token)
|
||||
private void SendMessage(WellDto? well, UserDto user, string documentCategory, string message)
|
||||
{
|
||||
var factory = new WellFinalDocumentMailBodyFactory(configuration);
|
||||
var subject = factory.MakeSubject(well, documentCategory);
|
||||
|
@ -76,7 +76,7 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
||||
wellFinalDocumentsRepository.Setup(r => r.GetByWellIdAsync(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(wellCaseDto);
|
||||
|
||||
wellFinalDocumentsRepository.Setup(r => r.SaveCategoryAsync(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<CancellationToken>()))
|
||||
wellFinalDocumentsRepository.Setup(r => r.GetCategoryAsync(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(wellFinalDocumentDBDto);
|
||||
|
||||
fileRepositoryMock = new Mock<IFileRepository>();
|
||||
|
@ -52,7 +52,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
return Forbid();
|
||||
|
||||
var idUser = User?.GetUserId();
|
||||
var data = await wellFinalDocumentsRepository.GetByWellIdAsync(idWell, idUser ?? default, token);
|
||||
var data = await wellFinalDocumentsRepository.GetByWellIdAsync(idWell, (int)idUser!, token);
|
||||
return Ok(data);
|
||||
}
|
||||
|
||||
@ -89,8 +89,8 @@ namespace AsbCloudWebApi.Controllers
|
||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||
return Forbid();
|
||||
|
||||
var idUser = User.GetUserId() ?? -1;
|
||||
var data = await wellFinalDocumentsService.UpdateRangeAsync(idWell, idUser, dtos, token);
|
||||
var idUser = User.GetUserId();
|
||||
var data = await wellFinalDocumentsService.UpdateRangeAsync(idWell, (int)idUser!, dtos, token);
|
||||
return Ok(data);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user