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,26 @@
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_evaluationService : IBaseService<int, eva_create_evaluationInputModel, eva_create_evaluationViewModel>
{
new eva_create_evaluationViewModel Insert(eva_create_evaluationInputModel model);
new eva_create_evaluationViewModel Update(int id, eva_create_evaluationInputModel model);
List<eva_create_evaluationViewModel> GetListByperformance_plan_id(Guid? performance_plan_id);
List<eva_create_evaluationViewModel> GetListBySearch(eva_create_evaluationSearchModel model);
string UpdateMultiple(List<eva_create_evaluationInputModel> model);
eva_create_evaluationWithSelectionViewModel GetWithSelection(int id);
eva_create_evaluationWithSelectionViewModel GetBlankItem();
}
}

View File

@@ -0,0 +1,33 @@
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_evaluationEntity : BaseEntity2<int>
{
[ForeignKey("performance_plan_id")]
public eva_performance_planEntity eva_performance_plan { get; set; }
public Guid? performance_plan_id { get; set; }
public int? employee_id { get; set; }
public decimal? score1 { get; set; }
public decimal? score2 { get; set; }
[ForeignKey("evaluation_group_id")]
public eva_evaluation_groupEntity eva_evaluation_group { get; set; }
public Guid? evaluation_group_id { get; set; }
}
}

View File

@@ -0,0 +1,32 @@
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_evaluationInputModel
{
public int? id { get; set; }
public Guid? performance_plan_id { get; set; }
public int? employee_id { get; set; }
public decimal? score1 { get; set; }
public decimal? score2 { get; set; }
public Guid? evaluation_group_id { 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_evaluationReportRequestModel : eva_create_evaluationSearchModel
{
public string filetype { get; set; }
public string contentType { get { return MyHelper.GetContentType(filetype); } }
}
}

View File

@@ -0,0 +1,23 @@
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_evaluationSearchModel
{
public Guid? performance_plan_id { get; set; }
public Guid? evaluation_group_id { get; set; }
}
}

View File

@@ -0,0 +1,257 @@
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
}
}

View File

@@ -0,0 +1,43 @@
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_evaluationViewModel : BaseViewModel2<int>
{
public Guid? performance_plan_id { get; set; }
public int? employee_id { get; set; }
public decimal? score1 { get; set; }
public decimal? score2 { get; set; }
public Guid? evaluation_group_id { get; set; }
public int? performance_plan_id_eva_performance_plan_fiscal_year { get; set; }
public string employee_id_external_linkage_external_name { get; set; }
public string evaluation_group_id_eva_evaluation_group_code { get; set; }
public string description
{
get
{
string y = "";
if (performance_plan_id_eva_performance_plan_fiscal_year.HasValue) y = performance_plan_id_eva_performance_plan_fiscal_year.ToString();
return evaluation_group_id_eva_evaluation_group_code + " ปี " +y;
}
}
}
}

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace TodoAPI2.Models
{
public class eva_create_evaluationWithSelectionViewModel: eva_create_evaluationViewModel
{
public List<eva_performance_planEntity> item_performance_plan_id { get; set; }
public List<external_employeeViewModel> item_employee_id { get; set; }
public List<eva_evaluation_groupEntity> item_evaluation_group_id { get; set; }
}
}