รวม code แก้ op 4 ข้อ
This commit is contained in:
28
Models/eva_idp_plan_owner/Ieva_idp_plan_ownerService.cs
Normal file
28
Models/eva_idp_plan_owner/Ieva_idp_plan_ownerService.cs
Normal file
@@ -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_idp_plan_ownerService : IBaseService<int, eva_idp_plan_ownerInputModel, eva_idp_plan_ownerViewModel>
|
||||
{
|
||||
new eva_idp_plan_ownerViewModel Insert(eva_idp_plan_ownerInputModel model);
|
||||
new eva_idp_plan_ownerViewModel Update(int id, eva_idp_plan_ownerInputModel model);
|
||||
List<eva_idp_plan_ownerViewModel> GetListBycreate_evaluation_detail_id(int? create_evaluation_detail_id);
|
||||
List<eva_idp_plan_ownerViewModel> GetListBySearch(eva_idp_plan_ownerSearchModel model);
|
||||
|
||||
string UpdateMultiple(List<eva_idp_plan_ownerInputModel> model);
|
||||
eva_idp_plan_ownerWithSelectionViewModel GetWithSelection(int id);
|
||||
eva_idp_plan_ownerWithSelectionViewModel GetBlankItem();
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
32
Models/eva_idp_plan_owner/eva_idp_plan_ownerInputModel.cs
Normal file
32
Models/eva_idp_plan_owner/eva_idp_plan_ownerInputModel.cs
Normal 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_idp_plan_ownerInputModel
|
||||
{
|
||||
|
||||
public int? id { get; set; }
|
||||
|
||||
public int? create_evaluation_detail_id { get; set; }
|
||||
|
||||
public string develop { get; set; }
|
||||
|
||||
public string development_method { get; set; }
|
||||
|
||||
public DateTime? start_date { get; set; }
|
||||
|
||||
public DateTime? end_date { 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_idp_plan_ownerReportRequestModel : eva_idp_plan_ownerSearchModel
|
||||
{
|
||||
public string filetype { get; set; }
|
||||
|
||||
public string contentType { get { return MyHelper.GetContentType(filetype); } }
|
||||
}
|
||||
}
|
||||
|
||||
23
Models/eva_idp_plan_owner/eva_idp_plan_ownerSearchModel.cs
Normal file
23
Models/eva_idp_plan_owner/eva_idp_plan_ownerSearchModel.cs
Normal 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_idp_plan_ownerSearchModel
|
||||
{
|
||||
|
||||
public int id { get; set; }
|
||||
|
||||
public int? create_evaluation_detail_id { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
249
Models/eva_idp_plan_owner/eva_idp_plan_ownerService.cs
Normal file
249
Models/eva_idp_plan_owner/eva_idp_plan_ownerService.cs
Normal file
@@ -0,0 +1,249 @@
|
||||
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_idp_plan_ownerService : Ieva_idp_plan_ownerService
|
||||
{
|
||||
private IBaseRepository2<eva_idp_planEntity, int> _repository;
|
||||
private IMyDatabase db;
|
||||
private Iexternal_linkageService ext;
|
||||
|
||||
public eva_idp_plan_ownerService(IBaseRepository2<eva_idp_planEntity, int> repository, IMyDatabase mydb, Iexternal_linkageService inext)
|
||||
{
|
||||
_repository = repository;
|
||||
db = mydb;
|
||||
ext = inext;
|
||||
}
|
||||
|
||||
#region Private Functions
|
||||
private eva_idp_planEntity GetEntity(eva_idp_plan_ownerInputModel model)
|
||||
{
|
||||
return Mapper.Map<eva_idp_planEntity>(model);
|
||||
}
|
||||
private List<eva_idp_planEntity> GetEntityList(List<eva_idp_plan_ownerInputModel> models)
|
||||
{
|
||||
return Mapper.Map<List<eva_idp_planEntity>>(models);
|
||||
}
|
||||
private eva_idp_plan_ownerViewModel GetDto(eva_idp_planEntity entity)
|
||||
{
|
||||
return Mapper.Map<eva_idp_plan_ownerViewModel>(entity);
|
||||
}
|
||||
private List<eva_idp_plan_ownerViewModel> GetDtoList(List<eva_idp_planEntity> entities)
|
||||
{
|
||||
return Mapper.Map<List<eva_idp_plan_ownerViewModel>>(entities);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Functions
|
||||
#region Query Functions
|
||||
|
||||
public eva_idp_plan_ownerViewModel Get(int id)
|
||||
{
|
||||
var entity = _repository.Get(id);
|
||||
|
||||
return GetDto(entity);
|
||||
}
|
||||
public eva_idp_plan_ownerWithSelectionViewModel GetWithSelection(int id)
|
||||
{
|
||||
var entity = _repository.Get(id);
|
||||
var i = Mapper.Map<eva_idp_plan_ownerWithSelectionViewModel>(entity);
|
||||
|
||||
|
||||
return i;
|
||||
}
|
||||
public eva_idp_plan_ownerWithSelectionViewModel GetBlankItem()
|
||||
{
|
||||
var i = new eva_idp_plan_ownerWithSelectionViewModel();
|
||||
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
public List<eva_idp_plan_ownerViewModel> GetListBycreate_evaluation_detail_id(int? create_evaluation_detail_id)
|
||||
{
|
||||
var model = new eva_idp_plan_ownerSearchModel();
|
||||
model.create_evaluation_detail_id = create_evaluation_detail_id;
|
||||
return GetListBySearch(model);
|
||||
}
|
||||
|
||||
public List<eva_idp_plan_ownerViewModel> GetListBySearch(eva_idp_plan_ownerSearchModel model)
|
||||
{
|
||||
var data = (
|
||||
from m_eva_idp_plan_owner in _repository.Context.eva_idp_plan
|
||||
|
||||
|
||||
where 1==1
|
||||
//&& (m_eva_idp_plan_owner.id == model.id || !model.id.HasValue)
|
||||
&& (m_eva_idp_plan_owner.create_evaluation_detail_id == model.create_evaluation_detail_id || !model.create_evaluation_detail_id.HasValue)
|
||||
|
||||
|
||||
orderby m_eva_idp_plan_owner.created descending
|
||||
select new eva_idp_plan_ownerViewModel()
|
||||
{
|
||||
id = m_eva_idp_plan_owner.id,
|
||||
create_evaluation_detail_id = m_eva_idp_plan_owner.create_evaluation_detail_id,
|
||||
develop = m_eva_idp_plan_owner.develop,
|
||||
development_method = m_eva_idp_plan_owner.development_method,
|
||||
start_date = m_eva_idp_plan_owner.start_date,
|
||||
end_date = m_eva_idp_plan_owner.end_date,
|
||||
|
||||
|
||||
isActive = m_eva_idp_plan_owner.isActive,
|
||||
Created = m_eva_idp_plan_owner.created,
|
||||
Updated = m_eva_idp_plan_owner.updated
|
||||
}
|
||||
).Take(100).ToList();
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation Functions
|
||||
|
||||
public int GetNewPrimaryKey()
|
||||
{
|
||||
int? newkey = 0;
|
||||
|
||||
var x = (from i in _repository.Context.eva_idp_plan
|
||||
orderby i.id descending
|
||||
select i).Take(1).ToList();
|
||||
|
||||
if(x.Count > 0)
|
||||
{
|
||||
newkey = x[0].id + 1;
|
||||
}
|
||||
|
||||
return newkey.Value;
|
||||
}
|
||||
|
||||
public eva_idp_plan_ownerViewModel Insert(eva_idp_plan_ownerInputModel model)
|
||||
{
|
||||
var entity = GetEntity(model);
|
||||
entity.id = GetNewPrimaryKey();
|
||||
|
||||
|
||||
|
||||
var inserted = _repository.Insert(entity);
|
||||
|
||||
return Get(inserted.id);
|
||||
}
|
||||
|
||||
public eva_idp_plan_ownerViewModel Update(int id, eva_idp_plan_ownerInputModel model)
|
||||
{
|
||||
var existingEntity = _repository.Get(id);
|
||||
if (existingEntity != null)
|
||||
{
|
||||
existingEntity.create_evaluation_detail_id = model.create_evaluation_detail_id;
|
||||
existingEntity.develop = model.develop;
|
||||
existingEntity.development_method = model.development_method;
|
||||
existingEntity.start_date = model.start_date;
|
||||
existingEntity.end_date = model.end_date;
|
||||
|
||||
|
||||
var updated = _repository.Update(id, existingEntity);
|
||||
return Get(updated.id);
|
||||
}
|
||||
else
|
||||
throw new NotificationException("No data to update");
|
||||
}
|
||||
|
||||
public string UpdateMultiple(List<eva_idp_plan_ownerInputModel> 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_detail_id = i.create_evaluation_detail_id;
|
||||
existingEntity.develop = i.develop;
|
||||
existingEntity.development_method = i.development_method;
|
||||
existingEntity.start_date = i.start_date;
|
||||
existingEntity.end_date = i.end_date;
|
||||
|
||||
|
||||
_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_idp_plan_ownerViewModel SetAsActive(int id)
|
||||
{
|
||||
var updated = _repository.SetAsActive(id);
|
||||
|
||||
return Get(updated.id);
|
||||
}
|
||||
public eva_idp_plan_ownerViewModel SetAsInactive(int id)
|
||||
{
|
||||
var updated = _repository.SetAsInActive(id);
|
||||
|
||||
return Get(updated.id);
|
||||
}
|
||||
public void Delete(int id)
|
||||
{
|
||||
_repository.Delete(id);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private Dictionary<string,string> GetLookupForLog()
|
||||
{
|
||||
var i = new Dictionary<string, string>();
|
||||
|
||||
|
||||
i.Add("create_evaluation_detail_id", "create_evaluation_detail_id");
|
||||
i.Add("develop", "ความรู้/ทักษะ/สมรรถนะที่ต้องได้รับการพัฒนา");
|
||||
i.Add("development_method", "วิธีการพัฒนา");
|
||||
i.Add("start_date", "ช่วงเวลาเริ่มต้นพัฒนา");
|
||||
i.Add("txt_start_date", "ช่วงเวลาเริ่มต้นพัฒนา");
|
||||
i.Add("end_date", "ช่วงเวลาสิ้นสุดพัฒนา");
|
||||
i.Add("txt_end_date", "ช่วงเวลาสิ้นสุดพัฒนา");
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Match Item
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
33
Models/eva_idp_plan_owner/eva_idp_plan_ownerViewModel.cs
Normal file
33
Models/eva_idp_plan_owner/eva_idp_plan_ownerViewModel.cs
Normal 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;
|
||||
|
||||
namespace TodoAPI2.Models
|
||||
{
|
||||
public class eva_idp_plan_ownerViewModel : BaseViewModel2<int>
|
||||
{
|
||||
|
||||
public int? create_evaluation_detail_id { get; set; }
|
||||
|
||||
public string develop { get; set; }
|
||||
|
||||
public string development_method { get; set; }
|
||||
|
||||
public DateTime? start_date { get; set; }
|
||||
|
||||
public string txt_start_date { get { return MyHelper.GetDateStringForReport(this.start_date); } }
|
||||
|
||||
public DateTime? end_date { get; set; }
|
||||
|
||||
public string txt_end_date { get { return MyHelper.GetDateStringForReport(this.end_date); } }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TodoAPI2.Models
|
||||
{
|
||||
public class eva_idp_plan_ownerWithSelectionViewModel: eva_idp_plan_ownerViewModel
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user