Add level score detail
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_level_score_detailService : IBaseService2<Guid, eva_level_score_detailInputModel, eva_level_score_detailViewModel>
|
||||
{
|
||||
new eva_level_score_detailViewModel Insert(eva_level_score_detailInputModel model, bool is_force_save);
|
||||
new eva_level_score_detailViewModel Update(Guid id, eva_level_score_detailInputModel model, bool is_force_save);
|
||||
List<eva_level_score_detailViewModel> GetListBylevel_score_id(Guid level_score_id);
|
||||
List<eva_level_score_detailViewModel> GetListBySearch(eva_level_score_detailSearchModel model);
|
||||
|
||||
string UpdateMultiple(List<eva_level_score_detailInputModel> model, bool is_force_save);
|
||||
eva_level_score_detailWithSelectionViewModel GetWithSelection(Guid id);
|
||||
eva_level_score_detailWithSelectionViewModel GetBlankItem();
|
||||
|
||||
void RefreshAutoFieldOfAllData();
|
||||
eva_level_score_detailEntity GetEntity(Guid id);
|
||||
DataContext GetContext();
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
using System.IO;
|
||||
|
||||
namespace TodoAPI2.Models
|
||||
{
|
||||
public class eva_level_score_detailEntity : BaseEntity2<Guid>
|
||||
{
|
||||
|
||||
|
||||
[ForeignKey("level_score_id")]
|
||||
public eva_level_scoreEntity eva_level_score_level_score_id { get; set; }
|
||||
public Guid level_score_id { get; set; }
|
||||
|
||||
public decimal? min_value { get; set; }
|
||||
|
||||
public decimal? max_value { get; set; }
|
||||
|
||||
public decimal? min_percentage { get; set; }
|
||||
|
||||
public decimal? max_percentage { 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_level_score_detailInputModel
|
||||
{
|
||||
|
||||
public Guid? id { get; set; }
|
||||
|
||||
public Guid level_score_id { get; set; }
|
||||
|
||||
public decimal? min_value { get; set; }
|
||||
|
||||
public decimal? max_value { get; set; }
|
||||
|
||||
public decimal? min_percentage { get; set; }
|
||||
|
||||
public decimal? max_percentage { 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_level_score_detailReportRequestModel : eva_level_score_detailSearchModel
|
||||
{
|
||||
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_level_score_detailSearchModel
|
||||
{
|
||||
|
||||
public Guid id { get; set; }
|
||||
|
||||
public Guid level_score_id { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
288
Models/eva_level_score_detail/eva_level_score_detailService.cs
Normal file
288
Models/eva_level_score_detail/eva_level_score_detailService.cs
Normal file
@@ -0,0 +1,288 @@
|
||||
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_level_score_detailService : Ieva_level_score_detailService
|
||||
{
|
||||
private IBaseRepository2<eva_level_score_detailEntity, Guid> _repository;
|
||||
private IMyDatabase db;
|
||||
private Iexternal_linkageService ext;
|
||||
|
||||
public eva_level_score_detailService(IBaseRepository2<eva_level_score_detailEntity, Guid> repository, IMyDatabase mydb, Iexternal_linkageService inext)
|
||||
{
|
||||
_repository = repository;
|
||||
db = mydb;
|
||||
ext = inext;
|
||||
}
|
||||
|
||||
#region Private Functions
|
||||
private eva_level_score_detailEntity GetEntity(eva_level_score_detailInputModel model)
|
||||
{
|
||||
return Mapper.Map<eva_level_score_detailEntity>(model);
|
||||
}
|
||||
private List<eva_level_score_detailEntity> GetEntityList(List<eva_level_score_detailInputModel> models)
|
||||
{
|
||||
return Mapper.Map<List<eva_level_score_detailEntity>>(models);
|
||||
}
|
||||
private eva_level_score_detailViewModel GetDto(eva_level_score_detailEntity entity)
|
||||
{
|
||||
return Mapper.Map<eva_level_score_detailViewModel>(entity);
|
||||
}
|
||||
private List<eva_level_score_detailViewModel> GetDtoList(List<eva_level_score_detailEntity> entities)
|
||||
{
|
||||
return Mapper.Map<List<eva_level_score_detailViewModel>>(entities);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Functions
|
||||
#region Query Functions
|
||||
|
||||
public eva_level_score_detailViewModel Get(Guid id)
|
||||
{
|
||||
var entity = _repository.Get(id);
|
||||
|
||||
return GetDto(entity);
|
||||
}
|
||||
|
||||
public eva_level_score_detailEntity GetEntity(Guid id)
|
||||
{
|
||||
var entity = _repository.Get(id);
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
public DataContext GetContext()
|
||||
{
|
||||
return _repository.Context;
|
||||
}
|
||||
|
||||
public eva_level_score_detailWithSelectionViewModel GetWithSelection(Guid id)
|
||||
{
|
||||
var entity = _repository.Get(id);
|
||||
var i = Mapper.Map<eva_level_score_detailWithSelectionViewModel>(entity);
|
||||
|
||||
|
||||
return i;
|
||||
}
|
||||
public eva_level_score_detailWithSelectionViewModel GetBlankItem()
|
||||
{
|
||||
var i = new eva_level_score_detailWithSelectionViewModel();
|
||||
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
public List<eva_level_score_detailViewModel> GetListBylevel_score_id(Guid level_score_id)
|
||||
{
|
||||
var model = new eva_level_score_detailSearchModel();
|
||||
model.level_score_id = level_score_id;
|
||||
return GetListBySearch(model);
|
||||
}
|
||||
|
||||
public List<eva_level_score_detailViewModel> GetListBySearch(eva_level_score_detailSearchModel model)
|
||||
{
|
||||
var data = (
|
||||
from m_eva_level_score_detail in _repository.Context.eva_level_score_detail
|
||||
|
||||
join fk_eva_level_score1 in _repository.Context.eva_level_score on m_eva_level_score_detail.level_score_id equals fk_eva_level_score1.id
|
||||
into eva_level_scoreResult1
|
||||
from fk_eva_level_scoreResult1 in eva_level_scoreResult1.DefaultIfEmpty()
|
||||
|
||||
|
||||
where
|
||||
1 == 1
|
||||
&& (m_eva_level_score_detail.level_score_id == model.level_score_id)
|
||||
|
||||
|
||||
orderby m_eva_level_score_detail.created descending
|
||||
select new eva_level_score_detailViewModel()
|
||||
{
|
||||
id = m_eva_level_score_detail.id,
|
||||
level_score_id = m_eva_level_score_detail.level_score_id,
|
||||
min_value = m_eva_level_score_detail.min_value,
|
||||
max_value = m_eva_level_score_detail.max_value,
|
||||
min_percentage = m_eva_level_score_detail.min_percentage,
|
||||
max_percentage = m_eva_level_score_detail.max_percentage,
|
||||
|
||||
level_score_id_eva_level_score_code = fk_eva_level_scoreResult1.code,
|
||||
|
||||
isActive = m_eva_level_score_detail.isActive,
|
||||
Created = m_eva_level_score_detail.created,
|
||||
Updated = m_eva_level_score_detail.updated
|
||||
}
|
||||
).Take(1000).ToList();
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation Functions
|
||||
|
||||
|
||||
|
||||
public eva_level_score_detailViewModel Insert(eva_level_score_detailInputModel 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_level_score_detailViewModel>(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public eva_level_score_detailViewModel Update(Guid id, eva_level_score_detailInputModel model, bool is_force_save)
|
||||
{
|
||||
var existingEntity = _repository.Get(id);
|
||||
if (existingEntity != null)
|
||||
{
|
||||
existingEntity.level_score_id = model.level_score_id;
|
||||
existingEntity.min_value = model.min_value;
|
||||
existingEntity.max_value = model.max_value;
|
||||
existingEntity.min_percentage = model.min_percentage;
|
||||
existingEntity.max_percentage = model.max_percentage;
|
||||
|
||||
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_level_score_detailViewModel>(existingEntity);
|
||||
}
|
||||
}
|
||||
else
|
||||
throw new NotificationException("No data to update");
|
||||
}
|
||||
|
||||
public string UpdateMultiple(List<eva_level_score_detailInputModel> 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.level_score_id = i.level_score_id;
|
||||
existingEntity.min_value = i.min_value;
|
||||
existingEntity.max_value = i.max_value;
|
||||
existingEntity.min_percentage = i.min_percentage;
|
||||
existingEntity.max_percentage = i.max_percentage;
|
||||
|
||||
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_level_score_detailViewModel SetAsActive(Guid id)
|
||||
{
|
||||
var updated = _repository.SetAsActive(id);
|
||||
|
||||
return Get(updated.id);
|
||||
}
|
||||
public eva_level_score_detailViewModel 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_level_score_detail
|
||||
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("level_score_id", "level_score_id");
|
||||
i.Add("level_score_id_eva_level_score_code", "level_score_id");
|
||||
i.Add("min_value", "ช่วงคะแนนต่ำสุด");
|
||||
i.Add("max_value", "ช่วงคะแนนสูงสุด");
|
||||
i.Add("min_percentage", "ร้อยละที่ได้เลื่อนต่ำสุด");
|
||||
i.Add("max_percentage", "ร้อยละที่ได้เลื่อนสูงสุด");
|
||||
|
||||
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_level_score_detailViewModel : BaseViewModel2<Guid>
|
||||
{
|
||||
|
||||
public Guid level_score_id { get; set; }
|
||||
|
||||
public decimal? min_value { get; set; }
|
||||
|
||||
public decimal? max_value { get; set; }
|
||||
|
||||
public decimal? min_percentage { get; set; }
|
||||
|
||||
public decimal? max_percentage { get; set; }
|
||||
|
||||
public string level_score_id_eva_level_score_code { 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_level_score_detailWithSelectionViewModel: eva_level_score_detailViewModel
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user