57 lines
1.6 KiB
C#
57 lines
1.6 KiB
C#
namespace YLErp.Web.Controllers
|
|
{
|
|
public class DepartmentsController : BaseController
|
|
{
|
|
public static bool IsListOld = true;
|
|
|
|
private static List<Department> AllDepartmentModel = null;
|
|
|
|
public static List<Department> GetAllDepartmentModel(bool isParentIdOne = true)
|
|
{
|
|
if (IsListOld)
|
|
{
|
|
using (var con = new ErpBaseContext())
|
|
{
|
|
AllDepartmentModel = con.Departments.ToList();
|
|
}
|
|
IsListOld = false;
|
|
}
|
|
if (isParentIdOne)
|
|
{
|
|
return AllDepartmentModel.Where(a => a.PId == 1).ToList();
|
|
}
|
|
else
|
|
{
|
|
return AllDepartmentModel;
|
|
}
|
|
}
|
|
|
|
public static Department GetDepartmentById(int id)
|
|
{
|
|
|
|
Department ret = null;
|
|
if (id != 0)
|
|
{
|
|
var departments = GetAllDepartmentModels();
|
|
ret = departments.FirstOrDefault(c => c.Id == id);
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
public static Department GetDepartmentByName(string name)
|
|
{
|
|
Department ret = null;
|
|
if (!string.IsNullOrWhiteSpace(name))
|
|
{
|
|
var departments = GetAllDepartmentModels();
|
|
ret = departments.FirstOrDefault(c => c.Name == name);
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
public static List<Department> GetAllDepartmentModels()
|
|
{
|
|
return GetAllDepartmentModel(false);
|
|
}
|
|
}
|
|
} |