First Initial

This commit is contained in:
Nakorn Rientrakrunchai
2020-02-20 15:02:39 +07:00
commit 8b98125e49
3048 changed files with 760804 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
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_create_evaluation_detailService : IBaseService<int, eva_create_evaluation_detailInputModel, eva_create_evaluation_detailViewModel>
{
new eva_create_evaluation_detailViewModel Insert(eva_create_evaluation_detailInputModel model);
new eva_create_evaluation_detailViewModel Update(int id, eva_create_evaluation_detailInputModel model);
List<eva_create_evaluation_detailViewModel> GetListBycreate_evaluation_id(int? create_evaluation_id);
List<eva_create_evaluation_detailViewModel> GetListBySearch(eva_create_evaluation_detailSearchModel model);
string UpdateMultiple(List<eva_create_evaluation_detailInputModel> model);
string AddMultiple(int? create_evaluation_id, List<int> model);
eva_create_evaluation_detailWithSelectionViewModel GetWithSelection(int id);
eva_create_evaluation_detailWithSelectionViewModel GetBlankItem();
}
}

View File

@@ -0,0 +1,90 @@
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_create_evaluation_detailEntity : BaseEntity2<int>
{
public int? create_evaluation_id { get; set; }
public int? employee_id { get; set; }
public int? chief { get; set; }
public decimal? total_summary_chief { get; set; }
public decimal? Final_summary_chief { get; set; }
public decimal? total_summary_supervisor { get; set; }
public decimal? Final_summary_supervisor { get; set; }
public decimal? total_summary_competency_chief { get; set; }
public decimal? Final_summary_competency_chief { get; set; }
public decimal? total_summary_competency_supervisor { get; set; }
public decimal? Final_summary_competency_supervisor { get; set; }
public decimal? achievement_chief { get; set; }
public decimal? competency_chief { get; set; }
public decimal? score_chief { get; set; }
[MaxLength(255)]
public string level_score_chief { get; set; }
public decimal? achievement_supervisor { get; set; }
public decimal? competency_supervisor { get; set; }
public decimal? score_supervisor { get; set; }
[MaxLength(255)]
public string level_score_supervisor { get; set; }
public int? supervisor1 { get; set; }
[MaxLength(1)]
public string supervisor1_result { get; set; }
[MaxLength(1000)]
public string supervisor1_remark { get; set; }
public DateTime? supervisor1_date { get; set; }
public int? supervisor2 { get; set; }
[MaxLength(1)]
public string supervisor2_result { get; set; }
[MaxLength(1000)]
public string supervisor2_remark { get; set; }
public DateTime? supervisor2_date { get; set; }
[MaxLength(1)]
public string status_self { get; set; }
[MaxLength(1)]
public string status_chief { get; set; }
[MaxLength(1)]
public string status_supervisor { get; set; }
}
}

View File

@@ -0,0 +1,28 @@
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_create_evaluation_detailInputModel
{
public int? id { get; set; }
public int? create_evaluation_id { get; set; }
public int? employee_id { get; set; }
public int? chief { get; set; }
public string active_mode { get; set; }
}
}

View File

@@ -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_create_evaluation_detailReportRequestModel : eva_create_evaluation_detailSearchModel
{
public string filetype { get; set; }
public string contentType { get { return MyHelper.GetContentType(filetype); } }
}
}

View File

@@ -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_create_evaluation_detailSearchModel
{
public int? create_evaluation_id { get; set; }
}
}

View File

@@ -0,0 +1,390 @@
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_evaluation_detailService : Ieva_create_evaluation_detailService
{
private IBaseRepository2<eva_create_evaluation_detailEntity, int> _repository;
private IMyDatabase db;
private Iexternal_linkageService ext;
private Iexternal_employeeService emp;
private Iexternal_competencyService com;
public eva_create_evaluation_detailService(IBaseRepository2<eva_create_evaluation_detailEntity, int> repository,
IMyDatabase mydb, Iexternal_linkageService inext, Iexternal_employeeService inemp,
Iexternal_competencyService incom)
{
_repository = repository;
db = mydb;
ext = inext;
emp = inemp;
com = incom;
}
#region Private Functions
private eva_create_evaluation_detailEntity GetEntity(eva_create_evaluation_detailInputModel model)
{
return Mapper.Map<eva_create_evaluation_detailEntity>(model);
}
private List<eva_create_evaluation_detailEntity> GetEntityList(List<eva_create_evaluation_detailInputModel> models)
{
return Mapper.Map<List<eva_create_evaluation_detailEntity>>(models);
}
private eva_create_evaluation_detailViewModel GetDto(eva_create_evaluation_detailEntity entity)
{
return Mapper.Map<eva_create_evaluation_detailViewModel>(entity);
}
private List<eva_create_evaluation_detailViewModel> GetDtoList(List<eva_create_evaluation_detailEntity> entities)
{
return Mapper.Map<List<eva_create_evaluation_detailViewModel>>(entities);
}
#endregion
#region Public Functions
#region Query Functions
public eva_create_evaluation_detailViewModel Get(int id)
{
var entity = _repository.Get(id);
return GetDto(entity);
}
public eva_create_evaluation_detailWithSelectionViewModel GetWithSelection(int id)
{
var entity = _repository.Get(id);
var i = Mapper.Map<eva_create_evaluation_detailWithSelectionViewModel>(entity);
i.item_employee_id = emp.GetListByemployee_type(null, null);
i.item_chief = i.item_employee_id;
return i;
}
public eva_create_evaluation_detailWithSelectionViewModel GetBlankItem()
{
var i = new eva_create_evaluation_detailWithSelectionViewModel();
i.item_employee_id = emp.GetListByemployee_type(null, null);
i.item_chief = i.item_employee_id;
return i;
}
public List<eva_create_evaluation_detailViewModel> GetListBycreate_evaluation_id(int? create_evaluation_id)
{
var model = new eva_create_evaluation_detailSearchModel();
model.create_evaluation_id = create_evaluation_id;
return GetListBySearch(model);
}
public List<eva_create_evaluation_detailViewModel> GetListBySearch(eva_create_evaluation_detailSearchModel model)
{
var allemp = emp.GetListByemployee_type(null, null);
var data = (
from m_eva_create_evaluation_detail in _repository.Context.eva_create_evaluation_detail
join fk_external_linkage2 in allemp on m_eva_create_evaluation_detail.employee_id equals fk_external_linkage2.id
into external_linkageResult2
from fk_external_linkageResult2 in external_linkageResult2.DefaultIfEmpty()
join fk_external_linkage3 in allemp on m_eva_create_evaluation_detail.chief equals fk_external_linkage3.id
into external_linkageResult3
from fk_external_linkageResult3 in external_linkageResult3.DefaultIfEmpty()
join fk_external_linkage21 in ext.GetAgreeDisagree() on m_eva_create_evaluation_detail.supervisor1_result equals fk_external_linkage21.external_code
into external_linkageResult21
from fk_external_linkageResult21 in external_linkageResult21.DefaultIfEmpty()
join fk_external_linkage25 in ext.GetAgreeDisagree() on m_eva_create_evaluation_detail.supervisor2_result equals fk_external_linkage25.external_code
into external_linkageResult25
from fk_external_linkageResult25 in external_linkageResult25.DefaultIfEmpty()
where 1 ==1
&& (m_eva_create_evaluation_detail.create_evaluation_id == model.create_evaluation_id || !model.create_evaluation_id.HasValue)
orderby m_eva_create_evaluation_detail.created descending
select new eva_create_evaluation_detailViewModel()
{
id = m_eva_create_evaluation_detail.id,
create_evaluation_id = m_eva_create_evaluation_detail.create_evaluation_id,
employee_id = m_eva_create_evaluation_detail.employee_id,
chief = m_eva_create_evaluation_detail.chief,
total_summary_chief = m_eva_create_evaluation_detail.total_summary_chief,
Final_summary_chief = m_eva_create_evaluation_detail.Final_summary_chief,
total_summary_supervisor = m_eva_create_evaluation_detail.total_summary_supervisor,
Final_summary_supervisor = m_eva_create_evaluation_detail.Final_summary_supervisor,
total_summary_competency_chief = m_eva_create_evaluation_detail.total_summary_competency_chief,
Final_summary_competency_chief = m_eva_create_evaluation_detail.Final_summary_competency_chief,
total_summary_competency_supervisor = m_eva_create_evaluation_detail.total_summary_competency_supervisor,
Final_summary_competency_supervisor = m_eva_create_evaluation_detail.Final_summary_competency_supervisor,
achievement_chief = m_eva_create_evaluation_detail.achievement_chief,
competency_chief = m_eva_create_evaluation_detail.competency_chief,
score_chief = m_eva_create_evaluation_detail.score_chief,
level_score_chief = m_eva_create_evaluation_detail.level_score_chief,
achievement_supervisor = m_eva_create_evaluation_detail.achievement_supervisor,
competency_supervisor = m_eva_create_evaluation_detail.competency_supervisor,
score_supervisor = m_eva_create_evaluation_detail.score_supervisor,
level_score_supervisor = m_eva_create_evaluation_detail.level_score_supervisor,
supervisor1 = m_eva_create_evaluation_detail.supervisor1,
supervisor1_result = m_eva_create_evaluation_detail.supervisor1_result,
supervisor1_remark = m_eva_create_evaluation_detail.supervisor1_remark,
supervisor1_date = m_eva_create_evaluation_detail.supervisor1_date,
supervisor2 = m_eva_create_evaluation_detail.supervisor2,
supervisor2_result = m_eva_create_evaluation_detail.supervisor2_result,
supervisor2_remark = m_eva_create_evaluation_detail.supervisor2_remark,
supervisor2_date = m_eva_create_evaluation_detail.supervisor2_date,
status_self = m_eva_create_evaluation_detail.status_self,
status_chief = m_eva_create_evaluation_detail.status_chief,
status_supervisor = m_eva_create_evaluation_detail.status_supervisor,
employee_id_external_linkage_external_name = fk_external_linkageResult2.fullname,
chief_external_linkage_external_name = fk_external_linkageResult3.fullname,
supervisor1_result_external_linkage_external_name = fk_external_linkageResult21.external_name,
supervisor2_result_external_linkage_external_name = fk_external_linkageResult25.external_name,
isActive = m_eva_create_evaluation_detail.isActive,
Created = m_eva_create_evaluation_detail.created,
Updated = m_eva_create_evaluation_detail.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_detail
orderby i.id descending
select i).Take(1).ToList();
if(x.Count > 0)
{
newkey = x[0].id + 1;
}
return newkey.Value;
}
public eva_create_evaluation_detailViewModel Insert(eva_create_evaluation_detailInputModel model)
{
var entity = GetEntity(model);
entity.id = GetNewPrimaryKey();
var inserted = _repository.Insert(entity);
return Get(inserted.id);
}
public eva_create_evaluation_detailViewModel Update(int id, eva_create_evaluation_detailInputModel model)
{
var existingEntity = _repository.Get(id);
if (existingEntity != null)
{
existingEntity.create_evaluation_id = model.create_evaluation_id;
existingEntity.employee_id = model.employee_id;
existingEntity.chief = model.chief;
var updated = _repository.Update(id, existingEntity);
return Get(updated.id);
}
else
throw new NotificationException("No data to update");
}
public string UpdateMultiple(List<eva_create_evaluation_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.create_evaluation_id = i.create_evaluation_id;
existingEntity.employee_id = i.employee_id;
existingEntity.chief = i.chief;
_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 int GetNewPrimaryKeyBehavior()
{
int? newkey = 0;
var x = (from i in _repository.Context.eva_evaluation_behavior
orderby i.id descending
select i).Take(1).ToList();
if (x.Count > 0)
{
newkey = x[0].id + 1;
}
return newkey.Value;
}
public string AddMultiple(int? create_evaluation_id, List<int> model)
{
if (!create_evaluation_id.HasValue)
{
return "0";
}
else
{
int j = 0;
int current_new_id = GetNewPrimaryKey();
var allemp = emp.GetListByemployee_type(null, null);
var comx = com.Getcom_competencys();
var k1 = GetNewPrimaryKeyBehavior();
var ex = (from x in _repository.Context.eva_create_evaluation_detail
where x.create_evaluation_id == create_evaluation_id
select x.employee_id).ToList();
foreach (var i in model)
{
if (checkExistEmployeeInExternal(i, allemp))
{
if (!checkExistEmployeeInInternal(i, ex))
{
var n = new eva_create_evaluation_detailEntity();
n.id = current_new_id;
n.employee_id = i;
n.create_evaluation_id = create_evaluation_id;
n.chief = emp.GetLeader(i);
n.created = DateTime.Now;
n.updated = DateTime.Now;
n.isActive = true;
_repository.Context.eva_create_evaluation_detail.Add(n);
// ต้องเพิ่มการ add eva_evaluation_behavior โดยดึงจาก สมรรนะหลัก 5 ตัว
foreach (var k in comx)
{
var p = new eva_evaluation_behaviorEntity();
p.id = k1;
p.create_evaluation_detail_id = n.id;
p.behavior = k.competency_code + " " + k.competency_topic;
p.weight = 0;
p.created = DateTime.Now;
p.updated = DateTime.Now;
p.isActive = true;
_repository.Context.eva_evaluation_behavior.Add(p);
k1++;
}
j++;
current_new_id++;
}
}
}
_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 eva_create_evaluation_detailViewModel SetAsActive(int id)
{
var updated = _repository.SetAsActive(id);
return Get(updated.id);
}
public eva_create_evaluation_detailViewModel SetAsInactive(int id)
{
var updated = _repository.SetAsInActive(id);
return Get(updated.id);
}
public void Delete(int id)
{
var a1 = from i in _repository.Context.eva_evaluation_achievement
where i.create_evaluation_detail_id == id
select i;
_repository.Context.eva_evaluation_achievement.RemoveRange(a1);
var a2 = from i in _repository.Context.eva_evaluation_behavior
where i.create_evaluation_detail_id == id
select i;
_repository.Context.eva_evaluation_behavior.RemoveRange(a2);
_repository.Delete(id);
return;
}
#endregion
#region Match Item
#endregion
#endregion
}
}

View File

@@ -0,0 +1,87 @@
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_create_evaluation_detailViewModel : BaseViewModel2<int>
{
public int? create_evaluation_id { get; set; }
public int? employee_id { get; set; }
public int? chief { get; set; }
public decimal? total_summary_chief { get; set; }
public decimal? Final_summary_chief { get; set; }
public decimal? total_summary_supervisor { get; set; }
public decimal? Final_summary_supervisor { get; set; }
public decimal? total_summary_competency_chief { get; set; }
public decimal? Final_summary_competency_chief { get; set; }
public decimal? total_summary_competency_supervisor { get; set; }
public decimal? Final_summary_competency_supervisor { get; set; }
public decimal? achievement_chief { get; set; }
public decimal? competency_chief { get; set; }
public decimal? score_chief { get; set; }
public string level_score_chief { get; set; }
public decimal? achievement_supervisor { get; set; }
public decimal? competency_supervisor { get; set; }
public decimal? score_supervisor { get; set; }
public string level_score_supervisor { get; set; }
public int? supervisor1 { get; set; }
public string supervisor1_result { get; set; }
public string supervisor1_remark { get; set; }
public DateTime? supervisor1_date { get; set; }
public string txt_supervisor1_date { get { return MyHelper.GetDateStringForReport(this.supervisor1_date); } }
public int? supervisor2 { get; set; }
public string supervisor2_result { get; set; }
public string supervisor2_remark { get; set; }
public DateTime? supervisor2_date { get; set; }
public string txt_supervisor2_date { get { return MyHelper.GetDateStringForReport(this.supervisor2_date); } }
public string status_self { get; set; }
public string status_chief { get; set; }
public string status_supervisor { get; set; }
public string employee_id_external_linkage_external_name { get; set; }
public string chief_external_linkage_external_name { get; set; }
public string supervisor1_result_external_linkage_external_name { get; set; }
public string supervisor2_result_external_linkage_external_name { get; set; }
}
}

View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace TodoAPI2.Models
{
public class eva_create_evaluation_detailWithSelectionViewModel: eva_create_evaluation_detailViewModel
{
public List<external_employeeViewModel> item_employee_id { get; set; }
public List<external_employeeViewModel> item_chief { get; set; }
}
}