96 lines
		
	
	
		
			4.4 KiB
		
	
	
	
		
			C#
		
	
	
			
		
		
	
	
			96 lines
		
	
	
		
			4.4 KiB
		
	
	
	
		
			C#
		
	
	
| //--------------------------------------------------------------------
 | |
| //     此代码由T4模板自动生成  byzhouhang 20210918
 | |
| //	   生成时间 2021-12-23 13:20:59 
 | |
| //     对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。
 | |
| //--------------------------------------------------------------------
 | |
| using Microsoft.AspNetCore.Mvc;
 | |
| using IRaCIS.Core.Domain.Share;
 | |
| using IRaCIS.Core.Application.Filter;
 | |
| using IRaCIS.Core.Infra.EFCore;
 | |
| using IRaCIS.Core.Infrastructure;
 | |
| 
 | |
| namespace IRaCIS.Core.Application.Contracts
 | |
| {
 | |
|     /// <summary>
 | |
|     /// TrialSiteUserSurveyService
 | |
|     /// </summary>	
 | |
|     [ApiExplorerSettings(GroupName = "Trial")]
 | |
|     public class TrialSiteUserSurveyService : BaseService, ITrialSiteUserSurveyService
 | |
|     {
 | |
|         private readonly IRepository<TrialSiteUserSurvey> _trialSiteUserSurveyRepository;
 | |
| 
 | |
|         public TrialSiteUserSurveyService(IRepository<TrialSiteUserSurvey> trialSiteUserSurveyRepository)
 | |
|         {
 | |
|             _trialSiteUserSurveyRepository = trialSiteUserSurveyRepository;
 | |
|         }
 | |
| 
 | |
|         [HttpGet("{trialSiteSurveyId:guid}")]
 | |
|         public async Task<List<TrialSiteUserSurveyView>> GetTrialSiteUserSurveyList(Guid trialSiteSurveyId)
 | |
|         {
 | |
| 
 | |
|             var trialSiteUserSurveyQueryable = _trialSiteUserSurveyRepository.Where(t => t.TrialSiteSurveyId == trialSiteSurveyId)
 | |
|              //.WhereIf(_userInfo.UserTypeEnumInt == (int)UserTypeEnum.SPM, t => t.TrialSiteSurvey.State >= TrialSiteSurveyEnum.CRCSubmitted)
 | |
|              //.WhereIf(_userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.APM|| _userInfo.UserTypeEnumInt == (int)UserTypeEnum.CPM, t => t.TrialSiteSurvey.State >= TrialSiteSurveyEnum.SPMApproved)
 | |
|              .ProjectTo<TrialSiteUserSurveyView>(_mapper.ConfigurationProvider);
 | |
| 
 | |
|             return await trialSiteUserSurveyQueryable.ToListAsync();
 | |
|         }
 | |
| 
 | |
|         [TypeFilter(typeof(TrialResourceFilter))]
 | |
|         [HttpPost("{trialId:guid}")]
 | |
|         public async Task<IResponseOutput> AddOrUpdateTrialSiteUserSurvey(TrialSiteUserSurveyAddOrEdit addOrEditTrialSiteUserSurvey)
 | |
|         {
 | |
|            
 | |
| 
 | |
|             if (await _trialSiteUserSurveyRepository.Where(t => t.Id == addOrEditTrialSiteUserSurvey.Id).AnyAsync(t => t.TrialSiteSurvey.State == TrialSiteSurveyEnum.PMCreatedAndLock))
 | |
|             {
 | |
|                 return ResponseOutput.NotOk("已锁定,不允许操作");
 | |
|             }
 | |
| 
 | |
|             if (addOrEditTrialSiteUserSurvey.UserTypeId != null && ( _userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.APM))
 | |
|             {
 | |
|                 var existSysUser = await _repository.FirstOrDefaultAsync<User>(t => t.EMail == addOrEditTrialSiteUserSurvey.Email && t.UserTypeId == addOrEditTrialSiteUserSurvey.UserTypeId);
 | |
| 
 | |
| 
 | |
|                 if (existSysUser != null)
 | |
|                 {
 | |
|                     if (existSysUser.LastName != addOrEditTrialSiteUserSurvey.LastName || existSysUser.FirstName != addOrEditTrialSiteUserSurvey.FirstName)
 | |
|                     {
 | |
|                         return ResponseOutput.NotOk($"该用户在系统中账户名为:{existSysUser.LastName + " / " + existSysUser.FirstName} ,与填写信息存在不一致项, 现将界面信息修改为与系统一致,可进行保存",
 | |
|                             new { existSysUser.LastName, existSysUser.FirstName, existSysUser.Phone }, ApiResponseCodeEnum.NeedTips);
 | |
|                     }
 | |
| 
 | |
|                 }
 | |
| 
 | |
|             }
 | |
| 
 | |
|             var entity = await _trialSiteUserSurveyRepository.InsertOrUpdateAsync(addOrEditTrialSiteUserSurvey, true);
 | |
| 
 | |
|             return ResponseOutput.Ok(entity.Id.ToString());
 | |
| 
 | |
|         }
 | |
| 
 | |
|         [TypeFilter(typeof(TrialResourceFilter))]
 | |
|         [HttpDelete("{trialSiteUserSurveyId:guid}/{trialId:guid}")]
 | |
|         public async Task<IResponseOutput> DeleteTrialSiteUserSurvey(Guid trialSiteUserSurveyId)
 | |
|         {
 | |
|            
 | |
| 
 | |
|             if (await _trialSiteUserSurveyRepository.Where(t => t.Id == trialSiteUserSurveyId).AnyAsync(t => t.TrialSiteSurvey.State == TrialSiteSurveyEnum.PMCreatedAndLock))
 | |
|             {
 | |
|                 return ResponseOutput.NotOk("已锁定,不允许操作");
 | |
|             }
 | |
| 
 | |
|             var success = await _trialSiteUserSurveyRepository.BatchDeleteNoTrackingAsync(t => t.Id == trialSiteUserSurveyId);
 | |
| 
 | |
|             return ResponseOutput.Result(success);
 | |
|         }
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
|     }
 | |
| }
 |