257 lines
8.0 KiB
C#
257 lines
8.0 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_evaluation_groupService : Ieva_evaluation_groupService
|
|
{
|
|
private IBaseRepository<eva_evaluation_groupEntity, Guid> _repository;
|
|
private IMyDatabase db;
|
|
private Iexternal_linkageService ext;
|
|
|
|
public eva_evaluation_groupService(IBaseRepository<eva_evaluation_groupEntity, Guid> repository, IMyDatabase mydb, Iexternal_linkageService inext)
|
|
{
|
|
_repository = repository;
|
|
db = mydb;
|
|
ext = inext;
|
|
}
|
|
|
|
#region Private Functions
|
|
private eva_evaluation_groupEntity GetEntity(eva_evaluation_groupInputModel model)
|
|
{
|
|
return Mapper.Map<eva_evaluation_groupEntity>(model);
|
|
}
|
|
private List<eva_evaluation_groupEntity> GetEntityList(List<eva_evaluation_groupInputModel> models)
|
|
{
|
|
return Mapper.Map<List<eva_evaluation_groupEntity>>(models);
|
|
}
|
|
private eva_evaluation_groupViewModel GetDto(eva_evaluation_groupEntity entity)
|
|
{
|
|
return Mapper.Map<eva_evaluation_groupViewModel>(entity);
|
|
}
|
|
private List<eva_evaluation_groupViewModel> GetDtoList(List<eva_evaluation_groupEntity> entities)
|
|
{
|
|
return Mapper.Map<List<eva_evaluation_groupViewModel>>(entities);
|
|
}
|
|
|
|
private List<eva_evaluation_groupEntity> GetListWithoutBase64Fields(IQueryable<eva_evaluation_groupEntity> listQuery)
|
|
{
|
|
return listQuery.Select(c => new eva_evaluation_groupEntity()
|
|
{
|
|
code = c.code,
|
|
thegroup = c.thegroup,
|
|
|
|
updated = c.updated,
|
|
id = c.id,
|
|
isActive = c.isActive
|
|
}).ToList();
|
|
}
|
|
#endregion
|
|
|
|
#region Public Functions
|
|
#region Query Functions
|
|
|
|
public eva_evaluation_groupViewModel Get(Guid id)
|
|
{
|
|
var entity = _repository.Get(id);
|
|
|
|
return GetDto(entity);
|
|
}
|
|
public eva_evaluation_groupWithSelectionViewModel GetWithSelection(Guid id)
|
|
{
|
|
var entity = _repository.Get(id);
|
|
var i = Mapper.Map<eva_evaluation_groupWithSelectionViewModel>(entity);
|
|
|
|
|
|
return i;
|
|
}
|
|
public eva_evaluation_groupWithSelectionViewModel GetBlankItem()
|
|
{
|
|
var i = new eva_evaluation_groupWithSelectionViewModel();
|
|
|
|
|
|
return i;
|
|
}
|
|
|
|
public List<eva_evaluation_groupViewModel> GetListALLeva_evaluation_group()
|
|
{
|
|
var data = (
|
|
from m_eva_evaluation_group in _repository.Context.eva_evaluation_group
|
|
|
|
orderby m_eva_evaluation_group.created descending
|
|
select new eva_evaluation_groupViewModel()
|
|
{
|
|
id = m_eva_evaluation_group.id,
|
|
code = m_eva_evaluation_group.code,
|
|
thegroup = m_eva_evaluation_group.thegroup,
|
|
|
|
|
|
isActive = m_eva_evaluation_group.isActive,
|
|
Created = m_eva_evaluation_group.created,
|
|
Updated = m_eva_evaluation_group.updated
|
|
}
|
|
).Take(100).ToList();
|
|
|
|
return data;
|
|
}
|
|
|
|
public List<eva_evaluation_groupViewModel> GetListBycode(string code)
|
|
{
|
|
var data = (
|
|
from m_eva_evaluation_group in _repository.Context.eva_evaluation_group
|
|
|
|
|
|
where m_eva_evaluation_group.code == code || string.IsNullOrEmpty(code)
|
|
|
|
orderby m_eva_evaluation_group.created descending
|
|
select new eva_evaluation_groupViewModel()
|
|
{
|
|
id = m_eva_evaluation_group.id,
|
|
code = m_eva_evaluation_group.code,
|
|
thegroup = m_eva_evaluation_group.thegroup,
|
|
|
|
|
|
isActive = m_eva_evaluation_group.isActive,
|
|
Created = m_eva_evaluation_group.created,
|
|
Updated = m_eva_evaluation_group.updated
|
|
}
|
|
).Take(100).ToList();
|
|
|
|
return data;
|
|
}
|
|
|
|
public List<eva_evaluation_groupViewModel> GetListBySearch(eva_evaluation_groupSearchModel model)
|
|
{
|
|
var data = (
|
|
from m_eva_evaluation_group in _repository.Context.eva_evaluation_group
|
|
|
|
|
|
where 1==1
|
|
&& (m_eva_evaluation_group.code == model.code || string.IsNullOrEmpty(model.code))
|
|
|
|
|
|
orderby m_eva_evaluation_group.created descending
|
|
select new eva_evaluation_groupViewModel()
|
|
{
|
|
id = m_eva_evaluation_group.id,
|
|
code = m_eva_evaluation_group.code,
|
|
thegroup = m_eva_evaluation_group.thegroup,
|
|
|
|
|
|
isActive = m_eva_evaluation_group.isActive,
|
|
Created = m_eva_evaluation_group.created,
|
|
Updated = m_eva_evaluation_group.updated
|
|
}
|
|
).Take(100).ToList();
|
|
|
|
return data;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Manipulation Functions
|
|
public eva_evaluation_groupViewModel Insert(eva_evaluation_groupInputModel model)
|
|
{
|
|
var entity = GetEntity(model);
|
|
entity.id = Guid.NewGuid();
|
|
|
|
|
|
|
|
var inserted = _repository.Insert(entity);
|
|
|
|
return Get(inserted.id);
|
|
}
|
|
|
|
public eva_evaluation_groupViewModel Update(Guid id, eva_evaluation_groupInputModel model)
|
|
{
|
|
var existingEntity = _repository.Get(id);
|
|
if (existingEntity != null)
|
|
{
|
|
existingEntity.code = model.code;
|
|
existingEntity.thegroup = model.thegroup;
|
|
|
|
|
|
var updated = _repository.Update(id, existingEntity);
|
|
return Get(updated.id);
|
|
}
|
|
else
|
|
throw new NotificationException("No data to update");
|
|
}
|
|
|
|
public string UpdateMultiple(List<eva_evaluation_groupInputModel> 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.code = i.code;
|
|
existingEntity.thegroup = i.thegroup;
|
|
|
|
|
|
_repository.UpdateWithoutCommit(i.id.Value, existingEntity);
|
|
}
|
|
}
|
|
else if (i.active_mode == "1" && !i.id.HasValue) // add
|
|
{
|
|
var entity = GetEntity(i);
|
|
entity.id = Guid.NewGuid();
|
|
_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_evaluation_groupViewModel SetAsActive(Guid id)
|
|
{
|
|
var updated = _repository.SetAsActive(id);
|
|
|
|
return Get(updated.id);
|
|
}
|
|
public eva_evaluation_groupViewModel SetAsInactive(Guid id)
|
|
{
|
|
var updated = _repository.SetAsInActive(id);
|
|
|
|
return Get(updated.id);
|
|
}
|
|
public void Delete(Guid id)
|
|
{
|
|
_repository.Delete(id);
|
|
|
|
return;
|
|
}
|
|
#endregion
|
|
|
|
#region Match Item
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
}
|
|
} |