ปรับปรุงให้แนบไฟล์ ผลสัมฤทธิ์ของงาน ได้หลายไฟล์

This commit is contained in:
LAPTOP-KB8JC2K2\acer
2021-04-11 19:40:50 +07:00
parent b96dc008f5
commit 08b0cbf291
22 changed files with 2562 additions and 27 deletions

View 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_evaluation_achievement_attachService : IBaseService2<int, eva_evaluation_achievement_attachInputModel, eva_evaluation_achievement_attachViewModel>
{
new eva_evaluation_achievement_attachViewModel Insert(eva_evaluation_achievement_attachInputModel model, bool is_force_save);
new eva_evaluation_achievement_attachViewModel Update(int id, eva_evaluation_achievement_attachInputModel model, bool is_force_save);
List<eva_evaluation_achievement_attachViewModel> GetListByachievement_id(int? achievement_id);
List<eva_evaluation_achievement_attachViewModel> GetListBySearch(eva_evaluation_achievement_attachSearchModel model);
string UpdateMultiple(List<eva_evaluation_achievement_attachInputModel> model, bool is_force_save);
eva_evaluation_achievement_attachWithSelectionViewModel GetWithSelection(int id);
eva_evaluation_achievement_attachWithSelectionViewModel GetBlankItem();
void RefreshAutoFieldOfAllData();
eva_evaluation_achievement_attachEntity GetEntity(int id);
DataContext GetContext();
}
}

View File

@@ -0,0 +1,48 @@
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_achievement_attachEntity : BaseEntity2<int>
{
[ForeignKey("achievement_id")]
public eva_evaluation_achievementEntity eva_evaluation_achievement_achievement_id { get; set; }
public int? achievement_id { get; set; }
[MaxLength(1000)]
public string the_file { get; set; }
[NotMapped]
public string the_fileDisplay
{
get
{
return (string.IsNullOrEmpty(the_file) ? "" :
FileUtil.GetFileInfo(TTSW.Constant.FilePathConstant.DirType.FilesTestUpload, id, the_file).RelativePath).Replace(@"\", "/");
}
}
public void SetAutoField(DataContext context)
{
}
public void DoAfterInsertUpdate(DataContext context)
{
}
}
}

View File

@@ -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_evaluation_achievement_attachInputModel
{
public int? id { get; set; }
public int? achievement_id { get; set; }
public string the_file { 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_evaluation_achievement_attachReportRequestModel : eva_evaluation_achievement_attachSearchModel
{
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_evaluation_achievement_attachSearchModel
{
public int id { get; set; }
public int? achievement_id { get; set; }
}
}

View File

@@ -0,0 +1,332 @@
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_achievement_attachService : Ieva_evaluation_achievement_attachService
{
private IBaseRepository2<eva_evaluation_achievement_attachEntity, int> _repository;
private IMyDatabase db;
private Iexternal_linkageService ext;
public eva_evaluation_achievement_attachService(IBaseRepository2<eva_evaluation_achievement_attachEntity, int> repository, IMyDatabase mydb, Iexternal_linkageService inext)
{
_repository = repository;
db = mydb;
ext = inext;
}
#region Private Functions
private eva_evaluation_achievement_attachEntity GetEntity(eva_evaluation_achievement_attachInputModel model)
{
return Mapper.Map<eva_evaluation_achievement_attachEntity>(model);
}
private List<eva_evaluation_achievement_attachEntity> GetEntityList(List<eva_evaluation_achievement_attachInputModel> models)
{
return Mapper.Map<List<eva_evaluation_achievement_attachEntity>>(models);
}
private eva_evaluation_achievement_attachViewModel GetDto(eva_evaluation_achievement_attachEntity entity)
{
return Mapper.Map<eva_evaluation_achievement_attachViewModel>(entity);
}
private List<eva_evaluation_achievement_attachViewModel> GetDtoList(List<eva_evaluation_achievement_attachEntity> entities)
{
return Mapper.Map<List<eva_evaluation_achievement_attachViewModel>>(entities);
}
#endregion
#region Public Functions
#region Query Functions
public eva_evaluation_achievement_attachViewModel Get(int id)
{
var entity = _repository.Get(id);
return GetDto(entity);
}
public eva_evaluation_achievement_attachEntity GetEntity(int id)
{
var entity = _repository.Get(id);
return entity;
}
public DataContext GetContext()
{
return _repository.Context;
}
public eva_evaluation_achievement_attachWithSelectionViewModel GetWithSelection(int id)
{
var entity = _repository.Get(id);
var i = Mapper.Map<eva_evaluation_achievement_attachWithSelectionViewModel>(entity);
return i;
}
public eva_evaluation_achievement_attachWithSelectionViewModel GetBlankItem()
{
var i = new eva_evaluation_achievement_attachWithSelectionViewModel();
return i;
}
public List<eva_evaluation_achievement_attachViewModel> GetListByachievement_id(int? achievement_id)
{
var model = new eva_evaluation_achievement_attachSearchModel();
model.achievement_id = achievement_id;
return GetListBySearch(model);
}
public List<eva_evaluation_achievement_attachViewModel> GetListBySearch(eva_evaluation_achievement_attachSearchModel model)
{
var data = (
from m_eva_evaluation_achievement_attach in _repository.Context.eva_evaluation_achievement_attach
join fk_eva_evaluation_achievement1 in _repository.Context.eva_evaluation_achievement on m_eva_evaluation_achievement_attach.achievement_id equals fk_eva_evaluation_achievement1.id
into eva_evaluation_achievementResult1
from fk_eva_evaluation_achievementResult1 in eva_evaluation_achievementResult1.DefaultIfEmpty()
where
1 == 1
&& (!model.achievement_id.HasValue || m_eva_evaluation_achievement_attach.achievement_id == model.achievement_id)
orderby m_eva_evaluation_achievement_attach.created descending
select new eva_evaluation_achievement_attachViewModel()
{
id = m_eva_evaluation_achievement_attach.id,
achievement_id = m_eva_evaluation_achievement_attach.achievement_id,
the_file = m_eva_evaluation_achievement_attach.the_file,
the_fileDisplay = m_eva_evaluation_achievement_attach.the_fileDisplay,
achievement_id_eva_evaluation_achievement_create_evaluation_detail_id = fk_eva_evaluation_achievementResult1.create_evaluation_detail_id,
isActive = m_eva_evaluation_achievement_attach.isActive,
Created = m_eva_evaluation_achievement_attach.created,
Updated = m_eva_evaluation_achievement_attach.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_achievement_attach
orderby i.id descending
select i).Take(1).ToList();
if(x.Count > 0)
{
newkey = x[0].id + 1;
}
return newkey.Value;
}
public eva_evaluation_achievement_attachViewModel Insert(eva_evaluation_achievement_attachInputModel model, bool is_force_save)
{
var entity = GetEntity(model);
entity.id = GetNewPrimaryKey();
if (!string.IsNullOrEmpty(model.the_file))
{
//Move file from temp to physical
string the_fileFileName = FileUtil.MoveTempUploadFileToActualPath(
model.the_file, FilePathConstant.DirType.FilesTestUpload, entity.id);
entity.the_file = the_fileFileName;
}
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_evaluation_achievement_attachViewModel>(entity);
}
}
public eva_evaluation_achievement_attachViewModel Update(int id, eva_evaluation_achievement_attachInputModel model, bool is_force_save)
{
var existingEntity = _repository.Get(id);
if (existingEntity != null)
{
existingEntity.achievement_id = model.achievement_id;
if (!string.IsNullOrEmpty(model.the_file))
{
if (model.the_file.StartsWith("Uploads"))
{
var the_fileFileName = FileUtil.MoveTempUploadFileToActualPath(
model.the_file, FilePathConstant.DirType.FilesTestUpload, existingEntity.id, existingEntity.the_file);
existingEntity.the_file = the_fileFileName;
}
else
{
existingEntity.the_file = model.the_file;
}
}
else
{
existingEntity.the_file = null;
}
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_evaluation_achievement_attachViewModel>(existingEntity);
}
}
else
throw new NotificationException("No data to update");
}
public string UpdateMultiple(List<eva_evaluation_achievement_attachInputModel> 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.achievement_id = i.achievement_id;
if (!string.IsNullOrEmpty(i.the_file))
{
if (i.the_file.StartsWith("Uploads"))
{
var the_fileFileName = FileUtil.MoveTempUploadFileToActualPath(
i.the_file, FilePathConstant.DirType.FilesTestUpload, existingEntity.id, existingEntity.the_file);
existingEntity.the_file = the_fileFileName;
}
else
{
existingEntity.the_file = i.the_file;
}
}
else
{
existingEntity.the_file = null;
}
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_achievement_attachViewModel SetAsActive(int id)
{
var updated = _repository.SetAsActive(id);
return Get(updated.id);
}
public eva_evaluation_achievement_attachViewModel 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_achievement_attach
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("achievement_id", "อ้างอิงตาราง eva_create_evaluation_detail");
i.Add("achievement_id_eva_evaluation_achievement_create_evaluation_detail_id", "อ้างอิงตาราง eva_create_evaluation_detail");
return i;
}
#endregion
#region Match Item
#endregion
#endregion
}
}

View File

@@ -0,0 +1,34 @@
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_achievement_attachViewModel : BaseViewModel2<int>
{
public int? achievement_id { get; set; }
public string the_file { get; set; }
public string the_fileDisplay { get; set; }
public string txt_the_file
{
get
{
return (string.IsNullOrEmpty(the_file) ? "" :
$"<a href='../{the_fileDisplay}' target='_blank'>{the_file}</a>");
}
}
public int? achievement_id_eva_evaluation_achievement_create_evaluation_detail_id { get; set; }
}
}

View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace TodoAPI2.Models
{
public class eva_evaluation_achievement_attachWithSelectionViewModel: eva_evaluation_achievement_attachViewModel
{
}
}