First Initial
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
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;
|
||||
|
||||
namespace TodoAPI2.Models
|
||||
{
|
||||
public interface Ieva_evaluation_group_detailService : IBaseService<Guid, eva_evaluation_group_detailInputModel, eva_evaluation_group_detailViewModel>
|
||||
{
|
||||
new eva_evaluation_group_detailViewModel Insert(eva_evaluation_group_detailInputModel model);
|
||||
new eva_evaluation_group_detailViewModel Update(Guid id, eva_evaluation_group_detailInputModel model);
|
||||
List<eva_evaluation_group_detailViewModel> GetListByevaluation_group_id(Guid? evaluation_group_id);
|
||||
List<eva_evaluation_group_detailViewModel> GetListBySearch(eva_evaluation_group_detailSearchModel model);
|
||||
|
||||
string UpdateMultiple(List<eva_evaluation_group_detailInputModel> model);
|
||||
eva_evaluation_group_detailWithSelectionViewModel GetWithSelection(Guid id);
|
||||
eva_evaluation_group_detailWithSelectionViewModel GetBlankItem();
|
||||
|
||||
string AddMultiple(Guid? evaluation_group_id, List<int> model);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using TTSW.EF;
|
||||
using TTSW.Utils;
|
||||
using TTSW.Constant;
|
||||
using TTSW.Common;
|
||||
using System.IO;
|
||||
|
||||
namespace TodoAPI2.Models
|
||||
{
|
||||
public class eva_evaluation_group_detailEntity : BaseEntity<Guid>
|
||||
{
|
||||
|
||||
[ForeignKey("evaluation_group_id")]
|
||||
public eva_evaluation_groupEntity eva_evaluation_group { get; set; }
|
||||
public Guid? evaluation_group_id { get; set; }
|
||||
|
||||
public int? employee_id { get; set; }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using TTSW.EF;
|
||||
using TTSW.Utils;
|
||||
using TTSW.Constant;
|
||||
using TTSW.Common;
|
||||
|
||||
namespace TodoAPI2.Models
|
||||
{
|
||||
public class eva_evaluation_group_detailInputModel
|
||||
{
|
||||
|
||||
public Guid? id { get; set; }
|
||||
|
||||
public Guid? evaluation_group_id { get; set; }
|
||||
|
||||
public int? employee_id { get; set; }
|
||||
|
||||
public string active_mode { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using TTSW.EF;
|
||||
using TTSW.Utils;
|
||||
using TTSW.Constant;
|
||||
using TTSW.Common;
|
||||
|
||||
namespace TodoAPI2.Models
|
||||
{
|
||||
public class eva_evaluation_group_detailReportRequestModel : eva_evaluation_group_detailSearchModel
|
||||
{
|
||||
public string filetype { get; set; }
|
||||
|
||||
public string contentType { get { return MyHelper.GetContentType(filetype); } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using TTSW.EF;
|
||||
using TTSW.Utils;
|
||||
using TTSW.Constant;
|
||||
using TTSW.Common;
|
||||
|
||||
namespace TodoAPI2.Models
|
||||
{
|
||||
public class eva_evaluation_group_detailSearchModel
|
||||
{
|
||||
|
||||
public Guid? evaluation_group_id { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,320 @@
|
||||
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_group_detailService : Ieva_evaluation_group_detailService
|
||||
{
|
||||
private IBaseRepository<eva_evaluation_group_detailEntity, Guid> _repository;
|
||||
private Iexternal_employeeService external_employee;
|
||||
private IMyDatabase db;
|
||||
private Iexternal_linkageService ext;
|
||||
|
||||
public eva_evaluation_group_detailService(IBaseRepository<eva_evaluation_group_detailEntity, Guid> repository,
|
||||
IMyDatabase mydb, Iexternal_linkageService inext, Iexternal_employeeService in_external_employee)
|
||||
{
|
||||
_repository = repository;
|
||||
external_employee = in_external_employee;
|
||||
db = mydb;
|
||||
ext = inext;
|
||||
}
|
||||
|
||||
#region Private Functions
|
||||
private eva_evaluation_group_detailEntity GetEntity(eva_evaluation_group_detailInputModel model)
|
||||
{
|
||||
return Mapper.Map<eva_evaluation_group_detailEntity>(model);
|
||||
}
|
||||
private List<eva_evaluation_group_detailEntity> GetEntityList(List<eva_evaluation_group_detailInputModel> models)
|
||||
{
|
||||
return Mapper.Map<List<eva_evaluation_group_detailEntity>>(models);
|
||||
}
|
||||
private eva_evaluation_group_detailViewModel GetDto(eva_evaluation_group_detailEntity entity)
|
||||
{
|
||||
return Mapper.Map<eva_evaluation_group_detailViewModel>(entity);
|
||||
}
|
||||
private List<eva_evaluation_group_detailViewModel> GetDtoList(List<eva_evaluation_group_detailEntity> entities)
|
||||
{
|
||||
return Mapper.Map<List<eva_evaluation_group_detailViewModel>>(entities);
|
||||
}
|
||||
|
||||
private List<eva_evaluation_group_detailEntity> GetListWithoutBase64Fields(IQueryable<eva_evaluation_group_detailEntity> listQuery)
|
||||
{
|
||||
return listQuery.Select(c => new eva_evaluation_group_detailEntity()
|
||||
{
|
||||
evaluation_group_id = c.evaluation_group_id,
|
||||
employee_id = c.employee_id,
|
||||
|
||||
updated = c.updated,
|
||||
id = c.id,
|
||||
isActive = c.isActive
|
||||
}).ToList();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Public Functions
|
||||
#region Query Functions
|
||||
|
||||
public eva_evaluation_group_detailViewModel Get(Guid id)
|
||||
{
|
||||
var entity = _repository.Get(id);
|
||||
|
||||
return GetDto(entity);
|
||||
}
|
||||
public eva_evaluation_group_detailWithSelectionViewModel GetWithSelection(Guid id)
|
||||
{
|
||||
var entity = _repository.Get(id);
|
||||
var i = Mapper.Map<eva_evaluation_group_detailWithSelectionViewModel>(entity);
|
||||
|
||||
|
||||
return i;
|
||||
}
|
||||
public eva_evaluation_group_detailWithSelectionViewModel GetBlankItem()
|
||||
{
|
||||
var i = new eva_evaluation_group_detailWithSelectionViewModel();
|
||||
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
public List<eva_evaluation_group_detailViewModel> GetListByevaluation_group_id(Guid? evaluation_group_id)
|
||||
{
|
||||
var data = (
|
||||
from m_eva_evaluation_group_detail in _repository.Context.eva_evaluation_group_detail
|
||||
|
||||
join fk_eva_evaluation_group1 in _repository.Context.eva_evaluation_group on m_eva_evaluation_group_detail.evaluation_group_id equals fk_eva_evaluation_group1.id
|
||||
into eva_evaluation_groupResult1
|
||||
from fk_eva_evaluation_groupResult1 in eva_evaluation_groupResult1.DefaultIfEmpty()
|
||||
|
||||
join fk_external_employee in external_employee.GetListByemployee_type(null, null) on m_eva_evaluation_group_detail.employee_id equals fk_external_employee.id
|
||||
into external_employeeResult
|
||||
from fk_external_employeeResult in external_employeeResult.DefaultIfEmpty()
|
||||
|
||||
where m_eva_evaluation_group_detail.evaluation_group_id == evaluation_group_id || !evaluation_group_id.HasValue
|
||||
|
||||
orderby m_eva_evaluation_group_detail.created descending
|
||||
select new eva_evaluation_group_detailViewModel()
|
||||
{
|
||||
id = m_eva_evaluation_group_detail.id,
|
||||
evaluation_group_id = m_eva_evaluation_group_detail.evaluation_group_id,
|
||||
employee_id = m_eva_evaluation_group_detail.employee_id,
|
||||
|
||||
evaluation_group_id_eva_evaluation_group_code = fk_eva_evaluation_groupResult1.code,
|
||||
|
||||
position_number = fk_external_employeeResult.position_number,
|
||||
position_name = fk_external_employeeResult.position_name,
|
||||
fullname = fk_external_employeeResult.fullname,
|
||||
|
||||
isActive = m_eva_evaluation_group_detail.isActive,
|
||||
Created = m_eva_evaluation_group_detail.created,
|
||||
Updated = m_eva_evaluation_group_detail.updated
|
||||
}
|
||||
).Take(100).ToList();
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public List<eva_evaluation_group_detailViewModel> GetListBySearch(eva_evaluation_group_detailSearchModel model)
|
||||
{
|
||||
var data = (
|
||||
from m_eva_evaluation_group_detail in _repository.Context.eva_evaluation_group_detail
|
||||
|
||||
join fk_eva_evaluation_group1 in _repository.Context.eva_evaluation_group on m_eva_evaluation_group_detail.evaluation_group_id equals fk_eva_evaluation_group1.id
|
||||
into eva_evaluation_groupResult1
|
||||
from fk_eva_evaluation_groupResult1 in eva_evaluation_groupResult1.DefaultIfEmpty()
|
||||
|
||||
join fk_external_employee in external_employee.GetListByemployee_type(null, null) on m_eva_evaluation_group_detail.employee_id equals fk_external_employee.id
|
||||
into external_employeeResult
|
||||
from fk_external_employeeResult in external_employeeResult.DefaultIfEmpty()
|
||||
|
||||
where 1==1
|
||||
&& (m_eva_evaluation_group_detail.evaluation_group_id == model.evaluation_group_id || !model.evaluation_group_id.HasValue)
|
||||
|
||||
|
||||
orderby m_eva_evaluation_group_detail.created descending
|
||||
select new eva_evaluation_group_detailViewModel()
|
||||
{
|
||||
id = m_eva_evaluation_group_detail.id,
|
||||
evaluation_group_id = m_eva_evaluation_group_detail.evaluation_group_id,
|
||||
employee_id = m_eva_evaluation_group_detail.employee_id,
|
||||
|
||||
evaluation_group_id_eva_evaluation_group_code = fk_eva_evaluation_groupResult1.code,
|
||||
|
||||
position_number = fk_external_employeeResult.position_number,
|
||||
position_name = fk_external_employeeResult.position_name,
|
||||
fullname = fk_external_employeeResult.fullname,
|
||||
|
||||
isActive = m_eva_evaluation_group_detail.isActive,
|
||||
Created = m_eva_evaluation_group_detail.created,
|
||||
Updated = m_eva_evaluation_group_detail.updated
|
||||
}
|
||||
).Take(100).ToList();
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation Functions
|
||||
public eva_evaluation_group_detailViewModel Insert(eva_evaluation_group_detailInputModel model)
|
||||
{
|
||||
var entity = GetEntity(model);
|
||||
entity.id = Guid.NewGuid();
|
||||
|
||||
|
||||
|
||||
var inserted = _repository.Insert(entity);
|
||||
|
||||
return Get(inserted.id);
|
||||
}
|
||||
|
||||
public eva_evaluation_group_detailViewModel Update(Guid id, eva_evaluation_group_detailInputModel model)
|
||||
{
|
||||
var existingEntity = _repository.Get(id);
|
||||
if (existingEntity != null)
|
||||
{
|
||||
existingEntity.evaluation_group_id = model.evaluation_group_id;
|
||||
existingEntity.employee_id = model.employee_id;
|
||||
|
||||
|
||||
var updated = _repository.Update(id, existingEntity);
|
||||
return Get(updated.id);
|
||||
}
|
||||
else
|
||||
throw new NotificationException("No data to update");
|
||||
}
|
||||
|
||||
public string AddMultiple(Guid? evaluation_group_id, List<int> model)
|
||||
{
|
||||
if (!evaluation_group_id.HasValue)
|
||||
{
|
||||
return "0";
|
||||
}
|
||||
else
|
||||
{
|
||||
int j = 0;
|
||||
var emp = external_employee.GetListByemployee_type(null, null);
|
||||
|
||||
var ex = (from x in _repository.Context.eva_evaluation_group_detail
|
||||
where x.evaluation_group_id == evaluation_group_id
|
||||
select x.employee_id).ToList();
|
||||
|
||||
foreach (var i in model)
|
||||
{
|
||||
if (checkExistEmployeeInExternal(i, emp))
|
||||
{
|
||||
if (!checkExistEmployeeInInternal(i, ex))
|
||||
{
|
||||
var n = new eva_evaluation_group_detailEntity();
|
||||
n.id = Guid.NewGuid();
|
||||
n.employee_id = i;
|
||||
n.evaluation_group_id = evaluation_group_id;
|
||||
n.created = DateTime.Now;
|
||||
n.updated = DateTime.Now;
|
||||
n.isActive = true;
|
||||
_repository.Context.eva_evaluation_group_detail.Add(n);
|
||||
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_repository.Context.SaveChanges();
|
||||
return j.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
private bool checkExistEmployeeInExternal(int emp_id, List<external_employeeViewModel> emp)
|
||||
{
|
||||
foreach (var i in emp)
|
||||
{
|
||||
if (i.id == emp_id) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool checkExistEmployeeInInternal(int emp_id, List<int?> emp)
|
||||
{
|
||||
foreach (var i in emp)
|
||||
{
|
||||
if (i.Value == emp_id) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public string UpdateMultiple(List<eva_evaluation_group_detailInputModel> 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.evaluation_group_id = i.evaluation_group_id;
|
||||
existingEntity.employee_id = i.employee_id;
|
||||
|
||||
|
||||
_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_group_detailViewModel SetAsActive(Guid id)
|
||||
{
|
||||
var updated = _repository.SetAsActive(id);
|
||||
|
||||
return Get(updated.id);
|
||||
}
|
||||
public eva_evaluation_group_detailViewModel 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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using TTSW.EF;
|
||||
using TTSW.Utils;
|
||||
using TTSW.Constant;
|
||||
using TTSW.Common;
|
||||
|
||||
namespace TodoAPI2.Models
|
||||
{
|
||||
public class eva_evaluation_group_detailViewModel : BaseViewModel<Guid>
|
||||
{
|
||||
|
||||
public Guid? evaluation_group_id { get; set; }
|
||||
|
||||
public int? employee_id { get; set; }
|
||||
|
||||
public string evaluation_group_id_eva_evaluation_group_code { get; set; }
|
||||
|
||||
public string position_number { get; set; }
|
||||
|
||||
public string position_name { get; set; }
|
||||
|
||||
public string fullname { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TodoAPI2.Models
|
||||
{
|
||||
public class eva_evaluation_group_detailWithSelectionViewModel: eva_evaluation_group_detailViewModel
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user