257 lines
9.4 KiB
C#
257 lines
9.4 KiB
C#
using AutoMapper;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using TTSW.EF;
|
|
using TTSW.Utils;
|
|
using TTSW.Constant;
|
|
using TTSW.Common;
|
|
using TodoAPI2.Models;
|
|
using System.IO;
|
|
using System.Web;
|
|
using System.Net;
|
|
using TTSW.Configure;
|
|
using Microsoft.Extensions.Options;
|
|
using System.Data;
|
|
|
|
namespace TodoAPI2.Models
|
|
{
|
|
public class eva_create_evaluationService : Ieva_create_evaluationService
|
|
{
|
|
private IBaseRepository2<eva_create_evaluationEntity, int> _repository;
|
|
private IMyDatabase db;
|
|
private Iexternal_linkageService ext;
|
|
Iexternal_employeeService emp;
|
|
|
|
public eva_create_evaluationService(IBaseRepository2<eva_create_evaluationEntity, int> repository, IMyDatabase mydb,
|
|
Iexternal_linkageService inext, Iexternal_employeeService inemp)
|
|
{
|
|
_repository = repository;
|
|
db = mydb;
|
|
ext = inext;
|
|
emp = inemp;
|
|
}
|
|
|
|
#region Private Functions
|
|
private eva_create_evaluationEntity GetEntity(eva_create_evaluationInputModel model)
|
|
{
|
|
return Mapper.Map<eva_create_evaluationEntity>(model);
|
|
}
|
|
private List<eva_create_evaluationEntity> GetEntityList(List<eva_create_evaluationInputModel> models)
|
|
{
|
|
return Mapper.Map<List<eva_create_evaluationEntity>>(models);
|
|
}
|
|
private eva_create_evaluationViewModel GetDto(eva_create_evaluationEntity entity)
|
|
{
|
|
return Mapper.Map<eva_create_evaluationViewModel>(entity);
|
|
}
|
|
private List<eva_create_evaluationViewModel> GetDtoList(List<eva_create_evaluationEntity> entities)
|
|
{
|
|
return Mapper.Map<List<eva_create_evaluationViewModel>>(entities);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Public Functions
|
|
#region Query Functions
|
|
|
|
public eva_create_evaluationViewModel Get(int id)
|
|
{
|
|
var entity = _repository.Get(id);
|
|
|
|
return GetDto(entity);
|
|
}
|
|
public eva_create_evaluationWithSelectionViewModel GetWithSelection(int id)
|
|
{
|
|
var entity = _repository.Get(id);
|
|
var i = Mapper.Map<eva_create_evaluationWithSelectionViewModel>(entity);
|
|
i.item_performance_plan_id = (from x in _repository.Context.eva_performance_plan select x).ToList();
|
|
i.item_employee_id = emp.GetListByemployee_type(null, null);
|
|
i.item_evaluation_group_id = (from x in _repository.Context.eva_evaluation_group select x).ToList();
|
|
|
|
|
|
return i;
|
|
}
|
|
public eva_create_evaluationWithSelectionViewModel GetBlankItem()
|
|
{
|
|
var i = new eva_create_evaluationWithSelectionViewModel();
|
|
i.item_performance_plan_id = (from x in _repository.Context.eva_performance_plan select x).ToList();
|
|
i.item_employee_id = emp.GetListByemployee_type(null, null);
|
|
i.item_evaluation_group_id = (from x in _repository.Context.eva_evaluation_group select x).ToList();
|
|
|
|
|
|
return i;
|
|
}
|
|
|
|
public List<eva_create_evaluationViewModel> GetListByperformance_plan_id(Guid? performance_plan_id)
|
|
{
|
|
var model = new eva_create_evaluationSearchModel();
|
|
model.performance_plan_id = performance_plan_id;
|
|
return GetListBySearch(model);
|
|
}
|
|
|
|
public List<eva_create_evaluationViewModel> GetListBySearch(eva_create_evaluationSearchModel model)
|
|
{
|
|
var data = (
|
|
from m_eva_create_evaluation in _repository.Context.eva_create_evaluation
|
|
|
|
join fk_eva_performance_plan1 in _repository.Context.eva_performance_plan on m_eva_create_evaluation.performance_plan_id equals fk_eva_performance_plan1.id
|
|
into eva_performance_planResult1
|
|
from fk_eva_performance_planResult1 in eva_performance_planResult1.DefaultIfEmpty()
|
|
|
|
join fk_external_linkage2 in emp.GetListByemployee_type(null,null) on m_eva_create_evaluation.employee_id equals fk_external_linkage2.id
|
|
into external_linkageResult2
|
|
from fk_external_linkageResult2 in external_linkageResult2.DefaultIfEmpty()
|
|
|
|
join fk_eva_evaluation_group5 in _repository.Context.eva_evaluation_group on m_eva_create_evaluation.evaluation_group_id equals fk_eva_evaluation_group5.id
|
|
into eva_evaluation_groupResult5
|
|
from fk_eva_evaluation_groupResult5 in eva_evaluation_groupResult5.DefaultIfEmpty()
|
|
|
|
|
|
where 1==1
|
|
&& (m_eva_create_evaluation.performance_plan_id == model.performance_plan_id || !model.performance_plan_id.HasValue)
|
|
&& (m_eva_create_evaluation.evaluation_group_id == model.evaluation_group_id || !model.evaluation_group_id.HasValue)
|
|
|
|
|
|
orderby m_eva_create_evaluation.created descending
|
|
select new eva_create_evaluationViewModel()
|
|
{
|
|
id = m_eva_create_evaluation.id,
|
|
performance_plan_id = m_eva_create_evaluation.performance_plan_id,
|
|
employee_id = m_eva_create_evaluation.employee_id,
|
|
score1 = m_eva_create_evaluation.score1,
|
|
score2 = m_eva_create_evaluation.score2,
|
|
evaluation_group_id = m_eva_create_evaluation.evaluation_group_id,
|
|
|
|
performance_plan_id_eva_performance_plan_fiscal_year = fk_eva_performance_planResult1.fiscal_year,
|
|
employee_id_external_linkage_external_name = fk_external_linkageResult2.fullname,
|
|
evaluation_group_id_eva_evaluation_group_code = fk_eva_evaluation_groupResult5.thegroup,
|
|
|
|
isActive = m_eva_create_evaluation.isActive,
|
|
Created = m_eva_create_evaluation.created,
|
|
Updated = m_eva_create_evaluation.updated
|
|
}
|
|
).Take(100).ToList();
|
|
|
|
return data;
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region Manipulation Functions
|
|
|
|
public int GetNewPrimaryKey()
|
|
{
|
|
int? newkey = 0;
|
|
|
|
var x = (from i in _repository.Context.eva_create_evaluation
|
|
orderby i.id descending
|
|
select i).Take(1).ToList();
|
|
|
|
if(x.Count > 0)
|
|
{
|
|
newkey = x[0].id + 1;
|
|
}
|
|
|
|
return newkey.Value;
|
|
}
|
|
|
|
public eva_create_evaluationViewModel Insert(eva_create_evaluationInputModel model)
|
|
{
|
|
var entity = GetEntity(model);
|
|
entity.id = GetNewPrimaryKey();
|
|
|
|
|
|
|
|
var inserted = _repository.Insert(entity);
|
|
|
|
return Get(inserted.id);
|
|
}
|
|
|
|
public eva_create_evaluationViewModel Update(int id, eva_create_evaluationInputModel model)
|
|
{
|
|
var existingEntity = _repository.Get(id);
|
|
if (existingEntity != null)
|
|
{
|
|
existingEntity.performance_plan_id = model.performance_plan_id;
|
|
existingEntity.employee_id = model.employee_id;
|
|
existingEntity.score1 = model.score1;
|
|
existingEntity.score2 = model.score2;
|
|
existingEntity.evaluation_group_id = model.evaluation_group_id;
|
|
|
|
|
|
var updated = _repository.Update(id, existingEntity);
|
|
return Get(updated.id);
|
|
}
|
|
else
|
|
throw new NotificationException("No data to update");
|
|
}
|
|
|
|
public string UpdateMultiple(List<eva_create_evaluationInputModel> model)
|
|
{
|
|
foreach(var i in model)
|
|
{
|
|
if (i.active_mode == "1" && i.id.HasValue) // update
|
|
{
|
|
var existingEntity = _repository.Get(i.id.Value);
|
|
if (existingEntity != null)
|
|
{
|
|
existingEntity.performance_plan_id = i.performance_plan_id;
|
|
existingEntity.employee_id = i.employee_id;
|
|
existingEntity.score1 = i.score1;
|
|
existingEntity.score2 = i.score2;
|
|
existingEntity.evaluation_group_id = i.evaluation_group_id;
|
|
|
|
|
|
_repository.UpdateWithoutCommit(i.id.Value, existingEntity);
|
|
}
|
|
}
|
|
else if (i.active_mode == "1" && !i.id.HasValue) // add
|
|
{
|
|
var entity = GetEntity(i);
|
|
entity.id = GetNewPrimaryKey();
|
|
_repository.InsertWithoutCommit(entity);
|
|
}
|
|
else if (i.active_mode == "0" && i.id.HasValue) // remove
|
|
{
|
|
_repository.DeleteWithoutCommit(i.id.Value);
|
|
}
|
|
else if (i.active_mode == "0" && !i.id.HasValue)
|
|
{
|
|
// nothing to do
|
|
}
|
|
}
|
|
_repository.Context.SaveChanges();
|
|
|
|
return model.Count().ToString();
|
|
}
|
|
|
|
public eva_create_evaluationViewModel SetAsActive(int id)
|
|
{
|
|
var updated = _repository.SetAsActive(id);
|
|
|
|
return Get(updated.id);
|
|
}
|
|
public eva_create_evaluationViewModel SetAsInactive(int id)
|
|
{
|
|
var updated = _repository.SetAsInActive(id);
|
|
|
|
return Get(updated.id);
|
|
}
|
|
public void Delete(int id)
|
|
{
|
|
_repository.Delete(id);
|
|
|
|
return;
|
|
}
|
|
#endregion
|
|
|
|
#region Match Item
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
}
|
|
} |