แก้ Change Request OP 2599

This commit is contained in:
Nakorn Rientrakrunchai
2020-07-22 11:50:27 +07:00
parent 764cd3c398
commit f9a4d7e0b7
5 changed files with 63 additions and 14 deletions

View File

@@ -27,6 +27,7 @@ namespace TodoAPI2.Controllers
private ILogger<eva_adjust_postponement_normalController> _logger; private ILogger<eva_adjust_postponement_normalController> _logger;
private Ieva_adjust_postponement_normalService _repository; private Ieva_adjust_postponement_normalService _repository;
private IConfiguration Configuration { get; set; } private IConfiguration Configuration { get; set; }
private Iexternal_employeeService emp;
#endregion #endregion
#region Properties #region Properties
@@ -37,13 +38,16 @@ namespace TodoAPI2.Controllers
/// Default constructure for dependency injection /// Default constructure for dependency injection
/// </summary> /// </summary>
/// <param name="repository"></param> /// <param name="repository"></param>
/// <param name="configuration"></param> /// <param name="configuration"></param>
/// <param name="inemp"></param>
/// <param name="logger"></param> /// <param name="logger"></param>
public eva_adjust_postponement_normalController(ILogger<eva_adjust_postponement_normalController> logger, Ieva_adjust_postponement_normalService repository, IConfiguration configuration) public eva_adjust_postponement_normalController(ILogger<eva_adjust_postponement_normalController> logger,
Ieva_adjust_postponement_normalService repository, IConfiguration configuration, Iexternal_employeeService inemp)
{ {
_logger = logger; _logger = logger;
_repository = repository; _repository = repository;
Configuration = configuration; Configuration = configuration;
emp = inemp;
} }
/// <summary> /// <summary>
@@ -64,9 +68,17 @@ namespace TodoAPI2.Controllers
try try
{ {
if (!MyHelper.checkAuth(Configuration, HttpContext)) return Unauthorized(); if (!MyHelper.checkAuth(Configuration, HttpContext)) return Unauthorized();
var result = _repository.GetWithSelection(id);
return Ok(result); if (!string.IsNullOrEmpty(HttpContext.Request.Cookies["user_id"]))
{
var loginid = Convert.ToInt32(HttpContext.Request.Cookies["user_id"]);
var e = emp.GetEmployeeForLogin(Convert.ToInt32(loginid));
return Ok(_repository.GetWithSelection(id, e.id));
}
else
{
return Unauthorized();
}
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -93,9 +105,17 @@ namespace TodoAPI2.Controllers
try try
{ {
if (!MyHelper.checkAuth(Configuration, HttpContext)) return Unauthorized(); if (!MyHelper.checkAuth(Configuration, HttpContext)) return Unauthorized();
var result = _repository.GetBlankItem();
return Ok(result); if (!string.IsNullOrEmpty(HttpContext.Request.Cookies["user_id"]))
{
var loginid = Convert.ToInt32(HttpContext.Request.Cookies["user_id"]);
var e = emp.GetEmployeeForLogin(Convert.ToInt32(loginid));
return Ok(_repository.GetBlankItem(e.id));
}
else
{
return Unauthorized();
}
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -149,7 +169,18 @@ namespace TodoAPI2.Controllers
try try
{ {
if (!MyHelper.checkAuth(Configuration, HttpContext)) return Unauthorized(); if (!MyHelper.checkAuth(Configuration, HttpContext)) return Unauthorized();
return Ok(_repository.GetListBySearch(model));
if (!string.IsNullOrEmpty(HttpContext.Request.Cookies["user_id"]))
{
var loginid = Convert.ToInt32(HttpContext.Request.Cookies["user_id"]);
var e = emp.GetEmployeeForLogin(Convert.ToInt32(loginid));
model.emp_id = e.id;
return Ok(_repository.GetListBySearch(model));
}
else
{
return Unauthorized();
}
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@@ -18,8 +18,8 @@ namespace TodoAPI2.Models
List<eva_adjust_postponement_normalViewModel> GetListBySearch(eva_adjust_postponement_normalSearchModel model); List<eva_adjust_postponement_normalViewModel> GetListBySearch(eva_adjust_postponement_normalSearchModel model);
string UpdateMultiple(List<eva_adjust_postponement_normalInputModel> model); string UpdateMultiple(List<eva_adjust_postponement_normalInputModel> model);
eva_adjust_postponement_normalWithSelectionViewModel GetWithSelection(int id); eva_adjust_postponement_normalWithSelectionViewModel GetWithSelection(int id, int emp_id);
eva_adjust_postponement_normalWithSelectionViewModel GetBlankItem(); eva_adjust_postponement_normalWithSelectionViewModel GetBlankItem(int emp_id);

View File

@@ -22,6 +22,7 @@ namespace TodoAPI2.Models
public int? org_id { get; set; } public int? org_id { get; set; }
public int? emp_id { get; set; }
} }
} }

View File

@@ -72,11 +72,17 @@ namespace TodoAPI2.Models
return GetDto(entity); return GetDto(entity);
} }
public eva_adjust_postponement_normalWithSelectionViewModel GetWithSelection(int id) public eva_adjust_postponement_normalWithSelectionViewModel GetWithSelection(int id, int emp_id)
{ {
var avaliable_eva = (from j in _repository.Context.eva_create_evaluation
where j.employee_id == emp_id
select j.id).ToList();
var entity = _repository.Get(id); var entity = _repository.Get(id);
var i = Mapper.Map<eva_adjust_postponement_normalWithSelectionViewModel>(entity); var i = Mapper.Map<eva_adjust_postponement_normalWithSelectionViewModel>(entity);
i.item_create_evaluation_id = create.GetListBySearch(new eva_create_evaluationSearchModel());
var temp = create.GetListBySearch(new eva_create_evaluationSearchModel());
i.item_create_evaluation_id = (from x in temp where avaliable_eva.Contains(x.id) select x).ToList();
var all_emp = emp.GetListByemployee_type(null, null); var all_emp = emp.GetListByemployee_type(null, null);
i.item_managed_by = all_emp.ToList(); i.item_managed_by = all_emp.ToList();
i.item_org_id = (from x in ext.GetDepartmentData() select x).ToList(); i.item_org_id = (from x in ext.GetDepartmentData() select x).ToList();
@@ -84,10 +90,15 @@ namespace TodoAPI2.Models
return i; return i;
} }
public eva_adjust_postponement_normalWithSelectionViewModel GetBlankItem() public eva_adjust_postponement_normalWithSelectionViewModel GetBlankItem(int emp_id)
{ {
var avaliable_eva = (from j in _repository.Context.eva_create_evaluation
where j.employee_id == emp_id
select j.id).ToList();
var i = new eva_adjust_postponement_normalWithSelectionViewModel(); var i = new eva_adjust_postponement_normalWithSelectionViewModel();
i.item_create_evaluation_id = create.GetListBySearch(new eva_create_evaluationSearchModel()); var temp = create.GetListBySearch(new eva_create_evaluationSearchModel());
i.item_create_evaluation_id = (from x in temp where avaliable_eva.Contains(x.id) select x).ToList();
var all_emp = emp.GetListByemployee_type(null, null); var all_emp = emp.GetListByemployee_type(null, null);
i.item_managed_by = all_emp.ToList(); i.item_managed_by = all_emp.ToList();
i.item_org_id = (from x in ext.GetDepartmentData() select x).ToList(); i.item_org_id = (from x in ext.GetDepartmentData() select x).ToList();
@@ -108,6 +119,10 @@ namespace TodoAPI2.Models
var all_emp = emp.GetListByemployee_type(null, null); var all_emp = emp.GetListByemployee_type(null, null);
var dep = ext.GetDepartmentData(); var dep = ext.GetDepartmentData();
var avaliable_eva = (from j in _repository.Context.eva_create_evaluation
where j.employee_id == model.emp_id
select j.id).ToList();
var data = ( var data = (
from m_eva_adjust_postponement_normal in _repository.Context.eva_adjust_postponement from m_eva_adjust_postponement_normal in _repository.Context.eva_adjust_postponement
@@ -132,6 +147,7 @@ namespace TodoAPI2.Models
from fk_eva_evaluation_groupResult5 in eva_evaluation_groupResult5.DefaultIfEmpty() from fk_eva_evaluation_groupResult5 in eva_evaluation_groupResult5.DefaultIfEmpty()
where 1==1 where 1==1
&& avaliable_eva.Contains(m_eva_adjust_postponement_normal.create_evaluation_id.Value)
//&& (m_eva_adjust_postponement_normal.id == model.id || !model.id.HasValue) //&& (m_eva_adjust_postponement_normal.id == model.id || !model.id.HasValue)
&& (m_eva_adjust_postponement_normal.fiscal_year == model.fiscal_year || !model.fiscal_year.HasValue) && (m_eva_adjust_postponement_normal.fiscal_year == model.fiscal_year || !model.fiscal_year.HasValue)
&& (m_eva_adjust_postponement_normal.theRound == model.theRound || !model.theRound.HasValue) && (m_eva_adjust_postponement_normal.theRound == model.theRound || !model.theRound.HasValue)

View File

@@ -426,12 +426,13 @@
<response code="400">If the model is invalid</response> <response code="400">If the model is invalid</response>
<response code="500">Error Occurred</response> <response code="500">Error Occurred</response>
</member> </member>
<member name="M:TodoAPI2.Controllers.eva_adjust_postponement_normalController.#ctor(Microsoft.Extensions.Logging.ILogger{TodoAPI2.Controllers.eva_adjust_postponement_normalController},TodoAPI2.Models.Ieva_adjust_postponement_normalService,Microsoft.Extensions.Configuration.IConfiguration)"> <member name="M:TodoAPI2.Controllers.eva_adjust_postponement_normalController.#ctor(Microsoft.Extensions.Logging.ILogger{TodoAPI2.Controllers.eva_adjust_postponement_normalController},TodoAPI2.Models.Ieva_adjust_postponement_normalService,Microsoft.Extensions.Configuration.IConfiguration,TodoAPI2.Models.Iexternal_employeeService)">
<summary> <summary>
Default constructure for dependency injection Default constructure for dependency injection
</summary> </summary>
<param name="repository"></param> <param name="repository"></param>
<param name="configuration"></param> <param name="configuration"></param>
<param name="inemp"></param>
<param name="logger"></param> <param name="logger"></param>
</member> </member>
<member name="M:TodoAPI2.Controllers.eva_adjust_postponement_normalController.Get(System.Int32)"> <member name="M:TodoAPI2.Controllers.eva_adjust_postponement_normalController.Get(System.Int32)">