111 lines
4.2 KiB
C#
111 lines
4.2 KiB
C#
using AutoMapper;
|
|
using AutoMapper.QueryableExtensions;
|
|
using IRaCIS.Application.Interfaces;
|
|
using IRaCIS.Application.ViewModels;
|
|
using IRaCIS.Core.Application.Contracts.RequestAndResponse;
|
|
using IRaCIS.Core.Domain.Interfaces;
|
|
using IRaCIS.Core.Domain.Models;
|
|
using IRaCIS.Core.Domain.Share;
|
|
using System;
|
|
using System.Linq;
|
|
|
|
namespace IRaCIS.Application.Services
|
|
{
|
|
public class EducationService : IEducationService
|
|
{
|
|
private readonly IPostgraduateRepository _postgraduateRepository;
|
|
private readonly IMapper _mapper;
|
|
private readonly IEducationRepository _educationRepository;
|
|
|
|
public EducationService(IEducationRepository doctorNormalEducationRepository,
|
|
IPostgraduateRepository doctorContinueLearningRepository, IMapper mapper)
|
|
{
|
|
_educationRepository = doctorNormalEducationRepository;
|
|
_postgraduateRepository = doctorContinueLearningRepository;
|
|
_mapper = mapper;
|
|
}
|
|
|
|
public DoctorEducationExperienceDTO GetEducation(Guid doctorId)
|
|
{
|
|
var educationQueryable = _educationRepository.Find(o => o.DoctorId == doctorId).OrderBy(t => t.CreateTime).ProjectTo<EducationInfoViewModel>(_mapper.ConfigurationProvider);
|
|
var educationList = educationQueryable.ToList();
|
|
var postgraduateList = _postgraduateRepository.Find(o => o.DoctorId == doctorId).OrderBy(t => t.CreateTime).ProjectTo<PostgraduateViewModel>(_mapper.ConfigurationProvider).ToList();
|
|
|
|
|
|
var returnResult = new DoctorEducationExperienceDTO()
|
|
{
|
|
EducationList = educationList,
|
|
PostgraduateList = postgraduateList
|
|
};
|
|
|
|
return returnResult;
|
|
}
|
|
|
|
public IResponseOutput AddOrUpdateEducationInfo(EducationCommand educationInfoViewModel)
|
|
{
|
|
if (educationInfoViewModel.Id == Guid.Empty || educationInfoViewModel.Id == null)
|
|
{
|
|
var doctorEducationInfo = _mapper.Map<Education>(educationInfoViewModel);
|
|
switch (educationInfoViewModel.Degree)
|
|
{
|
|
case StaticData.Bachelor:
|
|
doctorEducationInfo.ShowOrder = 1;
|
|
break;
|
|
case StaticData.Master:
|
|
doctorEducationInfo.ShowOrder = 2;
|
|
break;
|
|
case StaticData.Doctorate:
|
|
doctorEducationInfo.ShowOrder = 3;
|
|
break;
|
|
}
|
|
_educationRepository.Add(doctorEducationInfo);
|
|
var success = _educationRepository.SaveChanges();
|
|
|
|
return ResponseOutput.Result(success, doctorEducationInfo.Id.ToString());
|
|
}
|
|
|
|
else
|
|
{
|
|
_educationRepository.Update(_mapper.Map<Education>(educationInfoViewModel));
|
|
var success = _educationRepository.SaveChanges();
|
|
|
|
return ResponseOutput.Result(success);
|
|
|
|
}
|
|
}
|
|
|
|
public IResponseOutput DeleteEducationInfo(Guid id)
|
|
{
|
|
var success = _educationRepository.Delete(o => o.Id == id);
|
|
|
|
return ResponseOutput.Result(success);
|
|
}
|
|
|
|
public IResponseOutput AddOrUpdatePostgraduateInfo(PostgraduateCommand postgraduateViewModel)
|
|
{
|
|
if (postgraduateViewModel.Id == Guid.Empty || postgraduateViewModel.Id == null)
|
|
{
|
|
var doctorContinueLearning = _mapper.Map<Postgraduate>(postgraduateViewModel);
|
|
_postgraduateRepository.Add(doctorContinueLearning);
|
|
var success= _postgraduateRepository.SaveChanges();
|
|
|
|
return ResponseOutput.Result(success,doctorContinueLearning.Id.ToString());
|
|
}
|
|
else
|
|
{
|
|
_postgraduateRepository.Update(_mapper.Map<Postgraduate>(postgraduateViewModel));
|
|
var success = _postgraduateRepository.SaveChanges();
|
|
|
|
return ResponseOutput.Result(success);
|
|
|
|
}
|
|
}
|
|
|
|
public IResponseOutput DeletePostgraduateInfo(Guid doctorId)
|
|
{
|
|
var success = _postgraduateRepository.Delete(o => o.Id == doctorId);
|
|
|
|
return ResponseOutput.Result(success);
|
|
}
|
|
}
|
|
} |