นำเข้าหน้าจอ เพิ่ม แก้ไข ลบ แบบข้อตกลง
This commit is contained in:
@@ -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_evaluation_operating_agreementService : IBaseService<int, eva_evaluation_operating_agreementInputModel, eva_evaluation_operating_agreementViewModel>
|
||||
{
|
||||
new eva_evaluation_operating_agreementViewModel Insert(eva_evaluation_operating_agreementInputModel model);
|
||||
new eva_evaluation_operating_agreementViewModel Update(int id, eva_evaluation_operating_agreementInputModel model);
|
||||
List<eva_evaluation_operating_agreementViewModel> GetListBycreate_evaluation_detail_id(int? create_evaluation_detail_id);
|
||||
List<eva_evaluation_operating_agreementViewModel> GetListBySearch(eva_evaluation_operating_agreementSearchModel model);
|
||||
|
||||
string UpdateMultiple(List<eva_evaluation_operating_agreementInputModel> model, bool is_force_save);
|
||||
eva_evaluation_operating_agreementWithSelectionViewModel GetWithSelection(int id);
|
||||
eva_evaluation_operating_agreementWithSelectionViewModel GetBlankItem();
|
||||
|
||||
void RefreshAutoFieldOfAllData();
|
||||
eva_evaluation_operating_agreementEntity GetEntity(int id);
|
||||
DataContext GetContext();
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
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_operating_agreementEntity : BaseEntity2<int>
|
||||
{
|
||||
|
||||
|
||||
[ForeignKey("create_evaluation_detail_id")]
|
||||
public eva_create_evaluation_detailEntity eva_create_evaluation_detail_create_evaluation_detail_id { get; set; }
|
||||
public int? create_evaluation_detail_id { get; set; }
|
||||
|
||||
public int? mission_no { get; set; }
|
||||
|
||||
[MaxLength(4000)]
|
||||
public string mission_detail { get; set; }
|
||||
|
||||
[MaxLength(4000)]
|
||||
public string target { get; set; }
|
||||
|
||||
[MaxLength(4000)]
|
||||
public string indicators { get; set; }
|
||||
|
||||
|
||||
public void SetAutoField(DataContext context)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void DoAfterInsertUpdate(DataContext context)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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_evaluation_operating_agreementInputModel
|
||||
{
|
||||
|
||||
public int? id { get; set; }
|
||||
|
||||
public int? create_evaluation_detail_id { get; set; }
|
||||
|
||||
public int? mission_no { get; set; }
|
||||
|
||||
public string mission_detail { get; set; }
|
||||
|
||||
public string target { get; set; }
|
||||
|
||||
public string indicators { 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_operating_agreementReportRequestModel : eva_evaluation_operating_agreementSearchModel
|
||||
{
|
||||
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_evaluation_operating_agreementSearchModel
|
||||
{
|
||||
|
||||
public int id { get; set; }
|
||||
|
||||
public int? create_evaluation_detail_id { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,287 @@
|
||||
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_operating_agreementService : Ieva_evaluation_operating_agreementService
|
||||
{
|
||||
private IBaseRepository2<eva_evaluation_operating_agreementEntity, int> _repository;
|
||||
private IMyDatabase db;
|
||||
private Iexternal_linkageService ext;
|
||||
|
||||
public eva_evaluation_operating_agreementService(IBaseRepository2<eva_evaluation_operating_agreementEntity, int> repository, IMyDatabase mydb, Iexternal_linkageService inext)
|
||||
{
|
||||
_repository = repository;
|
||||
db = mydb;
|
||||
ext = inext;
|
||||
}
|
||||
|
||||
#region Private Functions
|
||||
private eva_evaluation_operating_agreementEntity GetEntity(eva_evaluation_operating_agreementInputModel model)
|
||||
{
|
||||
return Mapper.Map<eva_evaluation_operating_agreementEntity>(model);
|
||||
}
|
||||
private List<eva_evaluation_operating_agreementEntity> GetEntityList(List<eva_evaluation_operating_agreementInputModel> models)
|
||||
{
|
||||
return Mapper.Map<List<eva_evaluation_operating_agreementEntity>>(models);
|
||||
}
|
||||
private eva_evaluation_operating_agreementViewModel GetDto(eva_evaluation_operating_agreementEntity entity)
|
||||
{
|
||||
return Mapper.Map<eva_evaluation_operating_agreementViewModel>(entity);
|
||||
}
|
||||
private List<eva_evaluation_operating_agreementViewModel> GetDtoList(List<eva_evaluation_operating_agreementEntity> entities)
|
||||
{
|
||||
return Mapper.Map<List<eva_evaluation_operating_agreementViewModel>>(entities);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Functions
|
||||
#region Query Functions
|
||||
|
||||
public eva_evaluation_operating_agreementViewModel Get(int id)
|
||||
{
|
||||
var entity = _repository.Get(id);
|
||||
|
||||
return GetDto(entity);
|
||||
}
|
||||
|
||||
public eva_evaluation_operating_agreementEntity GetEntity(int id)
|
||||
{
|
||||
var entity = _repository.Get(id);
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
public DataContext GetContext()
|
||||
{
|
||||
return _repository.Context;
|
||||
}
|
||||
|
||||
public eva_evaluation_operating_agreementWithSelectionViewModel GetWithSelection(int id)
|
||||
{
|
||||
var entity = _repository.Get(id);
|
||||
var i = Mapper.Map<eva_evaluation_operating_agreementWithSelectionViewModel>(entity);
|
||||
|
||||
|
||||
return i;
|
||||
}
|
||||
public eva_evaluation_operating_agreementWithSelectionViewModel GetBlankItem()
|
||||
{
|
||||
var i = new eva_evaluation_operating_agreementWithSelectionViewModel();
|
||||
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
public List<eva_evaluation_operating_agreementViewModel> GetListBycreate_evaluation_detail_id(int? create_evaluation_detail_id)
|
||||
{
|
||||
var model = new eva_evaluation_operating_agreementSearchModel();
|
||||
model.create_evaluation_detail_id = create_evaluation_detail_id;
|
||||
return GetListBySearch(model);
|
||||
}
|
||||
|
||||
public List<eva_evaluation_operating_agreementViewModel> GetListBySearch(eva_evaluation_operating_agreementSearchModel model)
|
||||
{
|
||||
var data = (
|
||||
from m_eva_evaluation_operating_agreement in _repository.Context.eva_evaluation_operating_agreement
|
||||
|
||||
join fk_eva_create_evaluation_detail1 in _repository.Context.eva_create_evaluation_detail on m_eva_evaluation_operating_agreement.create_evaluation_detail_id equals fk_eva_create_evaluation_detail1.id
|
||||
into eva_create_evaluation_detailResult1
|
||||
from fk_eva_create_evaluation_detailResult1 in eva_create_evaluation_detailResult1.DefaultIfEmpty()
|
||||
|
||||
|
||||
where
|
||||
(model.create_evaluation_detail_id.HasValue && m_eva_evaluation_operating_agreement.create_evaluation_detail_id == model.create_evaluation_detail_id)
|
||||
|
||||
|
||||
orderby m_eva_evaluation_operating_agreement.created descending
|
||||
select new eva_evaluation_operating_agreementViewModel()
|
||||
{
|
||||
id = m_eva_evaluation_operating_agreement.id,
|
||||
create_evaluation_detail_id = m_eva_evaluation_operating_agreement.create_evaluation_detail_id,
|
||||
mission_no = m_eva_evaluation_operating_agreement.mission_no,
|
||||
mission_detail = m_eva_evaluation_operating_agreement.mission_detail,
|
||||
target = m_eva_evaluation_operating_agreement.target,
|
||||
indicators = m_eva_evaluation_operating_agreement.indicators,
|
||||
|
||||
create_evaluation_detail_id_eva_create_evaluation_detail_create_evaluation_id = fk_eva_create_evaluation_detailResult1.create_evaluation_id,
|
||||
|
||||
isActive = m_eva_evaluation_operating_agreement.isActive,
|
||||
Created = m_eva_evaluation_operating_agreement.created,
|
||||
Updated = m_eva_evaluation_operating_agreement.updated
|
||||
}
|
||||
).Take(1000).ToList();
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation Functions
|
||||
|
||||
|
||||
public int GetNewPrimaryKey()
|
||||
{
|
||||
int? newkey = 0;
|
||||
|
||||
var x = (from i in _repository.Context.eva_evaluation_operating_agreement
|
||||
orderby i.id descending
|
||||
select i).Take(1).ToList();
|
||||
|
||||
if(x.Count > 0)
|
||||
{
|
||||
newkey = x[0].id + 1;
|
||||
}
|
||||
|
||||
return newkey.Value;
|
||||
}
|
||||
|
||||
|
||||
public eva_evaluation_operating_agreementViewModel Insert(eva_evaluation_operating_agreementInputModel model)
|
||||
{
|
||||
var entity = GetEntity(model);
|
||||
entity.id = GetNewPrimaryKey();
|
||||
|
||||
|
||||
entity.SetAutoField(_repository.Context);
|
||||
|
||||
var inserted = _repository.Insert(entity);
|
||||
entity.DoAfterInsertUpdate(_repository.Context);
|
||||
return Get(inserted.id);
|
||||
}
|
||||
|
||||
public eva_evaluation_operating_agreementViewModel Update(int id, eva_evaluation_operating_agreementInputModel model)
|
||||
{
|
||||
var existingEntity = _repository.Get(id);
|
||||
if (existingEntity != null)
|
||||
{
|
||||
existingEntity.create_evaluation_detail_id = model.create_evaluation_detail_id;
|
||||
existingEntity.mission_no = model.mission_no;
|
||||
existingEntity.mission_detail = model.mission_detail;
|
||||
existingEntity.target = model.target;
|
||||
existingEntity.indicators = model.indicators;
|
||||
|
||||
existingEntity.SetAutoField(_repository.Context);
|
||||
|
||||
var updated = _repository.Update(id, existingEntity);
|
||||
existingEntity.DoAfterInsertUpdate(_repository.Context);
|
||||
return Get(updated.id);
|
||||
}
|
||||
else
|
||||
throw new NotificationException("No data to update");
|
||||
}
|
||||
|
||||
public string UpdateMultiple(List<eva_evaluation_operating_agreementInputModel> 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.create_evaluation_detail_id = i.create_evaluation_detail_id;
|
||||
existingEntity.mission_no = i.mission_no;
|
||||
existingEntity.mission_detail = i.mission_detail;
|
||||
existingEntity.target = i.target;
|
||||
existingEntity.indicators = i.indicators;
|
||||
|
||||
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 = GetNewPrimaryKey();
|
||||
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_evaluation_operating_agreementViewModel SetAsActive(int id)
|
||||
{
|
||||
var updated = _repository.SetAsActive(id);
|
||||
|
||||
return Get(updated.id);
|
||||
}
|
||||
public eva_evaluation_operating_agreementViewModel SetAsInactive(int id)
|
||||
{
|
||||
var updated = _repository.SetAsInActive(id);
|
||||
|
||||
return Get(updated.id);
|
||||
}
|
||||
public void Delete(int id)
|
||||
{
|
||||
_repository.Delete(id);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public void RefreshAutoFieldOfAllData()
|
||||
{
|
||||
var all_items = from i in _repository.Context.eva_evaluation_operating_agreement
|
||||
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("create_evaluation_detail_id", "อ้างอิงตาราง eva_create_evaluation_detail");
|
||||
i.Add("create_evaluation_detail_id_eva_create_evaluation_detail_create_evaluation_id", "อ้างอิงตาราง eva_create_evaluation_detail");
|
||||
i.Add("mission_no", "ภารกิจที่");
|
||||
i.Add("mission_detail", "รายละเอียดภารกิจ");
|
||||
i.Add("target", "เป้าหมาย");
|
||||
i.Add("indicators", "ตัวชี้วัด");
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#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_operating_agreementViewModel : BaseViewModel2<int>
|
||||
{
|
||||
|
||||
public int? create_evaluation_detail_id { get; set; }
|
||||
|
||||
public int? mission_no { get; set; }
|
||||
|
||||
public string mission_detail { get; set; }
|
||||
|
||||
public string target { get; set; }
|
||||
|
||||
public string indicators { get; set; }
|
||||
|
||||
public int? create_evaluation_detail_id_eva_create_evaluation_detail_create_evaluation_id { 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_operating_agreementWithSelectionViewModel: eva_evaluation_operating_agreementViewModel
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user