284 lines
10 KiB
C#
284 lines
10 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_salary_cylinderService : Ieva_salary_cylinderService
|
|
{
|
|
private IBaseRepository2<eva_salary_cylinderEntity, int> _repository;
|
|
private IMyDatabase db;
|
|
private Iexternal_linkageService ext;
|
|
|
|
public eva_salary_cylinderService(IBaseRepository2<eva_salary_cylinderEntity, int> repository, IMyDatabase mydb, Iexternal_linkageService inext)
|
|
{
|
|
_repository = repository;
|
|
db = mydb;
|
|
ext = inext;
|
|
}
|
|
|
|
#region Private Functions
|
|
private eva_salary_cylinderEntity GetEntity(eva_salary_cylinderInputModel model)
|
|
{
|
|
return Mapper.Map<eva_salary_cylinderEntity>(model);
|
|
}
|
|
private List<eva_salary_cylinderEntity> GetEntityList(List<eva_salary_cylinderInputModel> models)
|
|
{
|
|
return Mapper.Map<List<eva_salary_cylinderEntity>>(models);
|
|
}
|
|
private eva_salary_cylinderViewModel GetDto(eva_salary_cylinderEntity entity)
|
|
{
|
|
return Mapper.Map<eva_salary_cylinderViewModel>(entity);
|
|
}
|
|
private List<eva_salary_cylinderViewModel> GetDtoList(List<eva_salary_cylinderEntity> entities)
|
|
{
|
|
return Mapper.Map<List<eva_salary_cylinderViewModel>>(entities);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Public Functions
|
|
#region Query Functions
|
|
|
|
public eva_salary_cylinderViewModel Get(int id)
|
|
{
|
|
var entity = _repository.Get(id);
|
|
|
|
return GetDto(entity);
|
|
}
|
|
public eva_salary_cylinderWithSelectionViewModel GetWithSelection(int id)
|
|
{
|
|
var entity = _repository.Get(id);
|
|
var i = Mapper.Map<eva_salary_cylinderWithSelectionViewModel>(entity);
|
|
i.item_position_type = (from x in ext.Gethrm_position_types() select x).ToList();
|
|
i.item_position_level = (from x in ext.Gethrm_position_levels() select x).ToList();
|
|
|
|
|
|
return i;
|
|
}
|
|
public eva_salary_cylinderWithSelectionViewModel GetBlankItem()
|
|
{
|
|
var i = new eva_salary_cylinderWithSelectionViewModel();
|
|
i.item_position_type = (from x in ext.Gethrm_position_types() select x).ToList();
|
|
i.item_position_level = (from x in ext.Gethrm_position_levels() select x).ToList();
|
|
|
|
|
|
return i;
|
|
}
|
|
|
|
public List<eva_salary_cylinderViewModel> GetListByposition_type(int? position_type)
|
|
{
|
|
var data = (
|
|
from m_eva_salary_cylinder in _repository.Context.eva_salary_cylinder
|
|
|
|
join fk_external_linkage1 in ext.Gethrm_position_types() on m_eva_salary_cylinder.position_type equals fk_external_linkage1.id
|
|
into external_linkageResult1
|
|
from fk_external_linkageResult1 in external_linkageResult1.DefaultIfEmpty()
|
|
|
|
join fk_external_linkage2 in ext.Gethrm_position_levels() on m_eva_salary_cylinder.position_level equals fk_external_linkage2.id
|
|
into external_linkageResult2
|
|
from fk_external_linkageResult2 in external_linkageResult2.DefaultIfEmpty()
|
|
|
|
|
|
where m_eva_salary_cylinder.position_type == position_type || !position_type.HasValue
|
|
|
|
orderby m_eva_salary_cylinder.created descending
|
|
select new eva_salary_cylinderViewModel()
|
|
{
|
|
id = m_eva_salary_cylinder.id,
|
|
position_type = m_eva_salary_cylinder.position_type,
|
|
position_level = m_eva_salary_cylinder.position_level,
|
|
temporary_min = m_eva_salary_cylinder.temporary_min,
|
|
themin = m_eva_salary_cylinder.themin,
|
|
themax = m_eva_salary_cylinder.themax,
|
|
middle = m_eva_salary_cylinder.middle,
|
|
cost_living = m_eva_salary_cylinder.cost_living ,
|
|
|
|
position_type_external_linkage_external_name = fk_external_linkageResult1.external_name,
|
|
position_level_external_linkage_external_name = fk_external_linkageResult2.external_name,
|
|
|
|
isActive = m_eva_salary_cylinder.isActive,
|
|
Created = m_eva_salary_cylinder.created,
|
|
Updated = m_eva_salary_cylinder.updated
|
|
}
|
|
).ToList();
|
|
|
|
return data;
|
|
}
|
|
|
|
public List<eva_salary_cylinderViewModel> GetListBySearch(eva_salary_cylinderSearchModel model)
|
|
{
|
|
var data = (
|
|
from m_eva_salary_cylinder in _repository.Context.eva_salary_cylinder
|
|
|
|
join fk_external_linkage1 in ext.Gethrm_position_types() on m_eva_salary_cylinder.position_type equals fk_external_linkage1.id
|
|
into external_linkageResult1
|
|
from fk_external_linkageResult1 in external_linkageResult1.DefaultIfEmpty()
|
|
|
|
join fk_external_linkage2 in ext.Gethrm_position_levels() on m_eva_salary_cylinder.position_level equals fk_external_linkage2.id
|
|
into external_linkageResult2
|
|
from fk_external_linkageResult2 in external_linkageResult2.DefaultIfEmpty()
|
|
|
|
|
|
where 1==1
|
|
&& (m_eva_salary_cylinder.position_type == model.position_type || !model.position_type.HasValue)
|
|
|
|
|
|
orderby m_eva_salary_cylinder.created descending
|
|
select new eva_salary_cylinderViewModel()
|
|
{
|
|
id = m_eva_salary_cylinder.id,
|
|
position_type = m_eva_salary_cylinder.position_type,
|
|
position_level = m_eva_salary_cylinder.position_level,
|
|
temporary_min = m_eva_salary_cylinder.temporary_min,
|
|
themin = m_eva_salary_cylinder.themin,
|
|
themax = m_eva_salary_cylinder.themax,
|
|
middle = m_eva_salary_cylinder.middle,
|
|
cost_living = m_eva_salary_cylinder.cost_living ,
|
|
|
|
position_type_external_linkage_external_name = fk_external_linkageResult1.external_name,
|
|
position_level_external_linkage_external_name = fk_external_linkageResult2.external_name,
|
|
|
|
isActive = m_eva_salary_cylinder.isActive,
|
|
Created = m_eva_salary_cylinder.created,
|
|
Updated = m_eva_salary_cylinder.updated
|
|
}
|
|
).ToList();
|
|
|
|
return data;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Manipulation Functions
|
|
|
|
public int GetNewPrimaryKey()
|
|
{
|
|
int? newkey = 0;
|
|
|
|
var x = (from i in _repository.Context.eva_salary_cylinder
|
|
orderby i.id descending
|
|
select i).Take(1).ToList();
|
|
|
|
if(x.Count > 0)
|
|
{
|
|
newkey = x[0].id + 1;
|
|
}
|
|
|
|
return newkey.Value;
|
|
}
|
|
|
|
public eva_salary_cylinderViewModel Insert(eva_salary_cylinderInputModel model)
|
|
{
|
|
var entity = GetEntity(model);
|
|
entity.id = GetNewPrimaryKey();
|
|
|
|
|
|
|
|
var inserted = _repository.Insert(entity);
|
|
|
|
return Get(inserted.id);
|
|
}
|
|
|
|
public eva_salary_cylinderViewModel Update(int id, eva_salary_cylinderInputModel model)
|
|
{
|
|
var existingEntity = _repository.Get(id);
|
|
if (existingEntity != null)
|
|
{
|
|
existingEntity.position_type = model.position_type;
|
|
existingEntity.position_level = model.position_level;
|
|
existingEntity.temporary_min = model.temporary_min;
|
|
existingEntity.themin = model.themin;
|
|
existingEntity.themax = model.themax;
|
|
existingEntity.middle = model.middle;
|
|
existingEntity.cost_living = model.cost_living ;
|
|
|
|
|
|
var updated = _repository.Update(id, existingEntity);
|
|
return Get(updated.id);
|
|
}
|
|
else
|
|
throw new NotificationException("No data to update");
|
|
}
|
|
|
|
public string UpdateMultiple(List<eva_salary_cylinderInputModel> 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.position_type = i.position_type;
|
|
existingEntity.position_level = i.position_level;
|
|
existingEntity.temporary_min = i.temporary_min;
|
|
existingEntity.themin = i.themin;
|
|
existingEntity.themax = i.themax;
|
|
existingEntity.middle = i.middle;
|
|
existingEntity.cost_living = i.cost_living ;
|
|
|
|
|
|
_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_salary_cylinderViewModel SetAsActive(int id)
|
|
{
|
|
var updated = _repository.SetAsActive(id);
|
|
|
|
return Get(updated.id);
|
|
}
|
|
public eva_salary_cylinderViewModel 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
|
|
}
|
|
} |