ปรับปรุง คนที่ได้สิทธิพิเศษ ให้ดูรายชื่อได้ทั้งเนติ
This commit is contained in:
32
Models/eva_setup_permission/Ieva_setup_permissionService.cs
Normal file
32
Models/eva_setup_permission/Ieva_setup_permissionService.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
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_setup_permissionService : IBaseService2<Guid, eva_setup_permissionInputModel, eva_setup_permissionViewModel>
|
||||
{
|
||||
new eva_setup_permissionViewModel Insert(eva_setup_permissionInputModel model, bool is_force_save);
|
||||
new eva_setup_permissionViewModel Update(Guid id, eva_setup_permissionInputModel model, bool is_force_save);
|
||||
List<eva_setup_permissionViewModel> GetListByremark(string remark);
|
||||
List<eva_setup_permissionViewModel> GetListBySearch(eva_setup_permissionSearchModel model);
|
||||
|
||||
string UpdateMultiple(List<eva_setup_permissionInputModel> model, bool is_force_save);
|
||||
eva_setup_permissionWithSelectionViewModel GetWithSelection(Guid id);
|
||||
eva_setup_permissionWithSelectionViewModel GetBlankItem();
|
||||
|
||||
void RefreshAutoFieldOfAllData();
|
||||
eva_setup_permissionEntity GetEntity(Guid id);
|
||||
DataContext GetContext();
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
36
Models/eva_setup_permission/eva_setup_permissionEntity.cs
Normal file
36
Models/eva_setup_permission/eva_setup_permissionEntity.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
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_setup_permissionEntity : BaseEntity2<Guid>
|
||||
{
|
||||
|
||||
|
||||
public int? employee_id { get; set; }
|
||||
|
||||
[MaxLength(4000)]
|
||||
public string remark { get; set; }
|
||||
|
||||
|
||||
public void SetAutoField(DataContext context)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void DoAfterInsertUpdate(DataContext context)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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_setup_permissionInputModel
|
||||
{
|
||||
|
||||
public Guid? id { get; set; }
|
||||
|
||||
public int? employee_id { get; set; }
|
||||
|
||||
public string remark { 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_setup_permissionReportRequestModel : eva_setup_permissionSearchModel
|
||||
{
|
||||
public string filetype { get; set; }
|
||||
|
||||
public string contentType { get { return MyHelper.GetContentType(filetype); } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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_setup_permissionSearchModel
|
||||
{
|
||||
|
||||
public Guid id { get; set; }
|
||||
|
||||
public string remark { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
279
Models/eva_setup_permission/eva_setup_permissionService.cs
Normal file
279
Models/eva_setup_permission/eva_setup_permissionService.cs
Normal file
@@ -0,0 +1,279 @@
|
||||
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_setup_permissionService : Ieva_setup_permissionService
|
||||
{
|
||||
private IBaseRepository2<eva_setup_permissionEntity, Guid> _repository;
|
||||
private IMyDatabase db;
|
||||
private Iexternal_linkageService ext;
|
||||
private Iexternal_employeeService emp;
|
||||
|
||||
public eva_setup_permissionService(IBaseRepository2<eva_setup_permissionEntity, Guid> repository, IMyDatabase mydb,
|
||||
Iexternal_linkageService inext, Iexternal_employeeService inemp)
|
||||
{
|
||||
_repository = repository;
|
||||
db = mydb;
|
||||
ext = inext;
|
||||
emp = inemp;
|
||||
}
|
||||
|
||||
#region Private Functions
|
||||
private eva_setup_permissionEntity GetEntity(eva_setup_permissionInputModel model)
|
||||
{
|
||||
return Mapper.Map<eva_setup_permissionEntity>(model);
|
||||
}
|
||||
private List<eva_setup_permissionEntity> GetEntityList(List<eva_setup_permissionInputModel> models)
|
||||
{
|
||||
return Mapper.Map<List<eva_setup_permissionEntity>>(models);
|
||||
}
|
||||
private eva_setup_permissionViewModel GetDto(eva_setup_permissionEntity entity)
|
||||
{
|
||||
return Mapper.Map<eva_setup_permissionViewModel>(entity);
|
||||
}
|
||||
private List<eva_setup_permissionViewModel> GetDtoList(List<eva_setup_permissionEntity> entities)
|
||||
{
|
||||
return Mapper.Map<List<eva_setup_permissionViewModel>>(entities);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Functions
|
||||
#region Query Functions
|
||||
|
||||
public eva_setup_permissionViewModel Get(Guid id)
|
||||
{
|
||||
var entity = _repository.Get(id);
|
||||
|
||||
return GetDto(entity);
|
||||
}
|
||||
|
||||
public eva_setup_permissionEntity GetEntity(Guid id)
|
||||
{
|
||||
var entity = _repository.Get(id);
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
public DataContext GetContext()
|
||||
{
|
||||
return _repository.Context;
|
||||
}
|
||||
|
||||
public eva_setup_permissionWithSelectionViewModel GetWithSelection(Guid id)
|
||||
{
|
||||
var entity = _repository.Get(id);
|
||||
var i = Mapper.Map<eva_setup_permissionWithSelectionViewModel>(entity);
|
||||
i.item_employee_id = (from x in emp.GetAllEmployee() select x).ToList();
|
||||
|
||||
return i;
|
||||
}
|
||||
public eva_setup_permissionWithSelectionViewModel GetBlankItem()
|
||||
{
|
||||
var i = new eva_setup_permissionWithSelectionViewModel();
|
||||
i.item_employee_id = (from x in emp.GetAllEmployee() select x).ToList();
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
public List<eva_setup_permissionViewModel> GetListByremark(string remark)
|
||||
{
|
||||
var model = new eva_setup_permissionSearchModel();
|
||||
model.remark = remark;
|
||||
return GetListBySearch(model);
|
||||
}
|
||||
|
||||
public List<eva_setup_permissionViewModel> GetListBySearch(eva_setup_permissionSearchModel model)
|
||||
{
|
||||
var data = (
|
||||
from m_eva_setup_permission in _repository.Context.eva_setup_permission
|
||||
|
||||
join fk_external_linkage1 in emp.GetAllEmployee() on m_eva_setup_permission.employee_id equals fk_external_linkage1.id
|
||||
into external_linkageResult1
|
||||
from fk_external_linkageResult1 in external_linkageResult1.DefaultIfEmpty()
|
||||
|
||||
|
||||
where
|
||||
1 == 1
|
||||
&& (string.IsNullOrEmpty(model.remark) || m_eva_setup_permission.remark.Contains(model.remark))
|
||||
|
||||
|
||||
orderby m_eva_setup_permission.created descending
|
||||
select new eva_setup_permissionViewModel()
|
||||
{
|
||||
id = m_eva_setup_permission.id,
|
||||
employee_id = m_eva_setup_permission.employee_id,
|
||||
remark = m_eva_setup_permission.remark,
|
||||
|
||||
employee_id_external_linkage_external_name = fk_external_linkageResult1.fullname,
|
||||
|
||||
isActive = m_eva_setup_permission.isActive,
|
||||
Created = m_eva_setup_permission.created,
|
||||
Updated = m_eva_setup_permission.updated
|
||||
}
|
||||
).Take(1000).ToList();
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation Functions
|
||||
|
||||
|
||||
|
||||
public eva_setup_permissionViewModel Insert(eva_setup_permissionInputModel model, bool is_force_save)
|
||||
{
|
||||
var entity = GetEntity(model);
|
||||
entity.id = Guid.NewGuid();
|
||||
|
||||
|
||||
entity.SetAutoField(_repository.Context);
|
||||
|
||||
if (is_force_save)
|
||||
{
|
||||
var inserted = _repository.Insert(entity);
|
||||
entity.DoAfterInsertUpdate(_repository.Context);
|
||||
return Get(inserted.id);
|
||||
}
|
||||
else
|
||||
{
|
||||
_repository.InsertWithoutCommit(entity);
|
||||
entity.DoAfterInsertUpdate(_repository.Context);
|
||||
return Mapper.Map<eva_setup_permissionViewModel>(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public eva_setup_permissionViewModel Update(Guid id, eva_setup_permissionInputModel model, bool is_force_save)
|
||||
{
|
||||
var existingEntity = _repository.Get(id);
|
||||
if (existingEntity != null)
|
||||
{
|
||||
existingEntity.employee_id = model.employee_id;
|
||||
existingEntity.remark = model.remark;
|
||||
|
||||
existingEntity.SetAutoField(_repository.Context);
|
||||
|
||||
if (is_force_save)
|
||||
{
|
||||
var updated = _repository.Update(id, existingEntity);
|
||||
existingEntity.DoAfterInsertUpdate(_repository.Context);
|
||||
return Get(updated.id);
|
||||
}
|
||||
else
|
||||
{
|
||||
_repository.UpdateWithoutCommit(id, existingEntity);
|
||||
existingEntity.DoAfterInsertUpdate(_repository.Context);
|
||||
return Mapper.Map<eva_setup_permissionViewModel>(existingEntity);
|
||||
}
|
||||
}
|
||||
else
|
||||
throw new NotificationException("No data to update");
|
||||
}
|
||||
|
||||
public string UpdateMultiple(List<eva_setup_permissionInputModel> model, bool is_force_save)
|
||||
{
|
||||
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.employee_id = i.employee_id;
|
||||
existingEntity.remark = i.remark;
|
||||
|
||||
existingEntity.SetAutoField(_repository.Context);
|
||||
_repository.UpdateWithoutCommit(i.id.Value, existingEntity);
|
||||
}
|
||||
}
|
||||
else if (i.active_mode == "1" && !i.id.HasValue) // add
|
||||
{
|
||||
var entity = GetEntity(i);
|
||||
entity.id = Guid.NewGuid();
|
||||
entity.SetAutoField(_repository.Context);
|
||||
_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
|
||||
}
|
||||
}
|
||||
if (is_force_save)
|
||||
{
|
||||
_repository.Context.SaveChanges();
|
||||
}
|
||||
|
||||
return model.Count().ToString();
|
||||
}
|
||||
|
||||
public eva_setup_permissionViewModel SetAsActive(Guid id)
|
||||
{
|
||||
var updated = _repository.SetAsActive(id);
|
||||
|
||||
return Get(updated.id);
|
||||
}
|
||||
public eva_setup_permissionViewModel SetAsInactive(Guid id)
|
||||
{
|
||||
var updated = _repository.SetAsInActive(id);
|
||||
|
||||
return Get(updated.id);
|
||||
}
|
||||
public void Delete(Guid id)
|
||||
{
|
||||
_repository.Delete(id);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public void RefreshAutoFieldOfAllData()
|
||||
{
|
||||
var all_items = from i in _repository.Context.eva_setup_permission
|
||||
select i;
|
||||
foreach (var item in all_items)
|
||||
{
|
||||
item.SetAutoField(_repository.Context);
|
||||
}
|
||||
_repository.Context.SaveChanges();
|
||||
}
|
||||
|
||||
private Dictionary<string,string> GetLookupForLog()
|
||||
{
|
||||
var i = new Dictionary<string, string>();
|
||||
|
||||
|
||||
i.Add("employee_id", "ชื่อพนักงาน");
|
||||
i.Add("employee_id_external_linkage_external_name", "ชื่อพนักงาน");
|
||||
i.Add("remark", "หมายเหตุ");
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Match Item
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
24
Models/eva_setup_permission/eva_setup_permissionViewModel.cs
Normal file
24
Models/eva_setup_permission/eva_setup_permissionViewModel.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
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_setup_permissionViewModel : BaseViewModel2<Guid>
|
||||
{
|
||||
|
||||
public int? employee_id { get; set; }
|
||||
|
||||
public string remark { get; set; }
|
||||
|
||||
public string employee_id_external_linkage_external_name { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TodoAPI2.Models
|
||||
{
|
||||
public class eva_setup_permissionWithSelectionViewModel: eva_setup_permissionViewModel
|
||||
{
|
||||
public List<external_employeeViewModel> item_employee_id { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user