83 lines
3.6 KiB
C#
83 lines
3.6 KiB
C#
//--------------------------------------------------------------------
|
|
// 此代码由T4模板自动生成 byzhouhang 20210918
|
|
// 生成时间 2021-12-23 13:20:59
|
|
// 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。
|
|
//--------------------------------------------------------------------
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using IRaCIS.Core.Application.Filter;
|
|
using IRaCIS.Core.Domain.Share;
|
|
using IRaCIS.Core.Infra.EFCore;
|
|
|
|
namespace IRaCIS.Core.Application.Contracts
|
|
{
|
|
/// <summary>
|
|
/// TrialSiteEquipmentSurveyService
|
|
/// </summary>
|
|
[ApiExplorerSettings(GroupName = "Trial")]
|
|
public class TrialSiteEquipmentSurveyService : BaseService, ITrialSiteEquipmentSurveyService
|
|
{
|
|
private readonly IRepository<TrialSiteEquipmentSurvey> _trialSiteEquipmentSurveyRepository;
|
|
|
|
public TrialSiteEquipmentSurveyService(IRepository<TrialSiteEquipmentSurvey> trialSiteEquipmentSurveyRepository)
|
|
{
|
|
_trialSiteEquipmentSurveyRepository = trialSiteEquipmentSurveyRepository;
|
|
}
|
|
|
|
|
|
[HttpGet("{trialSiteSurveyId:guid}")]
|
|
public async Task<List<TrialSiteEquipmentSurveyView>> GetTrialSiteEquipmentSurveyList(Guid trialSiteSurveyId, string? scannerType)
|
|
{
|
|
var trialSiteEquipmentSurveyQueryable = _trialSiteEquipmentSurveyRepository.Where(t => t.TrialSiteSurveyId == trialSiteSurveyId)
|
|
.WhereIf(!string.IsNullOrEmpty(scannerType), t => t.ScannerType.Contains(scannerType!))
|
|
.ProjectTo<TrialSiteEquipmentSurveyView>(_mapper.ConfigurationProvider);
|
|
|
|
return await trialSiteEquipmentSurveyQueryable.ToListAsync();
|
|
}
|
|
|
|
[TypeFilter(typeof(TrialResourceFilter))]
|
|
[HttpPost("{trialId:guid}")]
|
|
public async Task<IResponseOutput> AddOrUpdateTrialSiteEquipmentSurvey(TrialSiteEquipmentSurveyAddOrEdit addOrEditTrialSiteEquipmentSurvey)
|
|
{
|
|
if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.CPM || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.APM)
|
|
{
|
|
return ResponseOutput.NotOk("CPM/APM 不允许操作");
|
|
}
|
|
|
|
if (addOrEditTrialSiteEquipmentSurvey.Id != null)
|
|
{
|
|
if (await _trialSiteEquipmentSurveyRepository.Where(t => t.Id == addOrEditTrialSiteEquipmentSurvey.Id).AnyAsync(t => t.TrialSiteSurvey.State==TrialSiteSurveyEnum.PMCreatedAndLock))
|
|
{
|
|
return ResponseOutput.NotOk("已锁定,不允许操作");
|
|
}
|
|
}
|
|
|
|
|
|
var entity = await _trialSiteEquipmentSurveyRepository.InsertOrUpdateAsync(addOrEditTrialSiteEquipmentSurvey, true);
|
|
|
|
return ResponseOutput.Ok(entity.Id.ToString());
|
|
|
|
}
|
|
|
|
[TypeFilter(typeof(TrialResourceFilter))]
|
|
[HttpDelete("{trialSiteEquipmentSurveyId:guid}/{trialId:guid}")]
|
|
public async Task<IResponseOutput> DeleteTrialSiteEquipmentSurvey(Guid trialSiteEquipmentSurveyId)
|
|
{
|
|
if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.CPM || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.APM)
|
|
{
|
|
return ResponseOutput.NotOk("CPM/APM 不允许操作");
|
|
}
|
|
|
|
if (await _trialSiteEquipmentSurveyRepository.Where(t => t.Id == trialSiteEquipmentSurveyId).AnyAsync(t => t.TrialSiteSurvey.State==TrialSiteSurveyEnum.PMCreatedAndLock))
|
|
{
|
|
return ResponseOutput.NotOk("已锁定,不允许操作");
|
|
}
|
|
var success = await _trialSiteEquipmentSurveyRepository.BatchDeleteAsync(t => t.Id == trialSiteEquipmentSurveyId);
|
|
|
|
return ResponseOutput.Result(success);
|
|
}
|
|
|
|
|
|
}
|
|
}
|