public ActionResult GetAll() { var dbfactory = new DatabaseFactory(); var dataContext = dbfactory.Get(); var rawlist = _regionService.GetAll(); var empSrv = new ERPOptima.Service.Hrm.HrmEmployeeService(new ERPOptima.Data.Hrm.Repository.HrmEmployeeRepository(dbfactory), new UnitOfWork(dbfactory)); var list = rawlist.Select(m => new { Id=m.Id, Code=m.Code, Name=m.Name, Head=m.Head, Remarks=m.Remarks, HeadName = empSrv.GetById(m.Head) == null ? "" : empSrv.GetById(m.Head).Name }); JsonResult jresult = new JsonResult(); jresult = Json(list, JsonRequestBehavior.AllowGet); return jresult; }
public ActionResult CompaniesForUser() { ISecUserService _su; _su = new SecUserService(new SecUserRepository(_databaseFactory), new UnitOfWork(_databaseFactory)); if (Session["userId"] != null) { int userId = Convert.ToInt32(Session["userId"]); SecUser user = _su.GetById(userId); ISecCompanyUserService _compUserService = new SecCompanyUserService(new SecCompanyUserRepository(_databaseFactory), new UnitOfWork(_databaseFactory)); var compUserList = _compUserService.GetAll(); if (compUserList != null && compUserList.Count() > 0) { compUserList = compUserList.Where(i => i.SecUserId == userId).ToList(); if (compUserList != null && compUserList.Count() > 0) { var companyIds = compUserList.Select(i => i.SecCompanyId).ToList(); var permittedCompanyList = _company.GetAll(); IList<SecCompany> result = permittedCompanyList.Where(b => companyIds.Contains(b.Id)).ToList(); List<CompanyIdAndName> list = GetCompanyList(result); //Default compnay if (user.HrmEmployeeId != null) { ERPOptima.Model.HRM.HrmEmployee emp = new ERPOptima.Model.HRM.HrmEmployee(); ERPOptima.Service.Hrm.HrmEmployeeService es = new ERPOptima.Service.Hrm.HrmEmployeeService(new ERPOptima.Data.Hrm.Repository.HrmEmployeeRepository(_databaseFactory), new UnitOfWork(_databaseFactory)); emp = es.GetById(user.HrmEmployeeId.Value); if (emp != null) { _company = new SecCompanyService(new SecCompanyRepository(_databaseFactory), new UnitOfWork(_databaseFactory)); var defaultCompany = _company.GetById(emp.SecCompanyId.Value); if (defaultCompany != null) { CompanyIdAndName obj = new CompanyIdAndName(); obj.Id = defaultCompany.Id; obj.Name = defaultCompany.Name; if (!list.Contains(obj)) { list.Insert(0, obj); } } } } return Json(list, JsonRequestBehavior.AllowGet); } else { List<CompanyIdAndName> list = new List<CompanyIdAndName>(); //default company if (user.HrmEmployeeId != null) { ERPOptima.Model.HRM.HrmEmployee emp = new ERPOptima.Model.HRM.HrmEmployee(); ERPOptima.Service.Hrm.HrmEmployeeService es = new ERPOptima.Service.Hrm.HrmEmployeeService(new ERPOptima.Data.Hrm.Repository.HrmEmployeeRepository(_databaseFactory), new UnitOfWork(_databaseFactory)); emp = es.GetById(user.HrmEmployeeId.Value); if (emp != null) { _company = new SecCompanyService(new SecCompanyRepository(_databaseFactory), new UnitOfWork(_databaseFactory)); var defaultCompany = _company.GetById(emp.SecCompanyId.Value); if (defaultCompany != null) { CompanyIdAndName obj = new CompanyIdAndName(); obj.Id = defaultCompany.Id; obj.Name = defaultCompany.Name; if (!list.Contains(obj)) { list.Insert(0, obj); } } } } return Json(list, JsonRequestBehavior.AllowGet); } } //var a = _company.GetModuleIdAndName(); //List<CompanyIdAndName> list = new List<CompanyIdAndName>(); //foreach (var item in a) //{ // CompanyIdAndName company = new CompanyIdAndName { Id = item.Key, Name = item.Value }; // list.Add(company); //} //return Json(list, JsonRequestBehavior.AllowGet); else { //default company //IList<SecCompany> defaultCompanyList = new List<SecCompany>(); //var defaultCompany = _company.GetById(1); //defaultCompanyList.Add(defaultCompany); //List<CompanyIdAndName> list = GetCompanyList(defaultCompanyList); List<CompanyIdAndName> list = new List<CompanyIdAndName>(); //default company if (user.HrmEmployeeId != null) { ERPOptima.Model.HRM.HrmEmployee emp = new ERPOptima.Model.HRM.HrmEmployee(); ERPOptima.Service.Hrm.HrmEmployeeService es = new ERPOptima.Service.Hrm.HrmEmployeeService(new ERPOptima.Data.Hrm.Repository.HrmEmployeeRepository(_databaseFactory), new UnitOfWork(_databaseFactory)); emp = es.GetById(user.HrmEmployeeId.Value); if (emp != null) { _company = new SecCompanyService(new SecCompanyRepository(_databaseFactory), new UnitOfWork(_databaseFactory)); var defaultCompany = _company.GetById(emp.SecCompanyId.Value); if (defaultCompany != null) { CompanyIdAndName obj = new CompanyIdAndName(); obj.Id = defaultCompany.Id; obj.Name = defaultCompany.Name; if (!list.Contains(obj)) { list.Insert(0, obj); } } } } return Json(list, JsonRequestBehavior.AllowGet); } } else { Operation ret = new Operation(); ret.Success = false; ret.Message = "Unauthenticated user "; ret.OperationId = -1; return Json(ret, JsonRequestBehavior.AllowGet); } }
public ActionResult GetCompaniesByUserId(int userId) { //ISecUserService _su; ISecCompanyUserService _cu; var dbfactory = new DatabaseFactory(); SecUser user = _su.GetById(userId); _su = new SecUserService(new SecUserRepository(dbfactory), new UnitOfWork(dbfactory)); _cu = new SecCompanyUserService(new SecCompanyUserRepository(dbfactory), new UnitOfWork(dbfactory)); DataTable dt = _cu.GetCompanyUsers(userId); var list = dt.DataTableToList<CompanyUserViewModel>().Where(t => t.Status == true).Select(t => new { Id = t.Id, Name = t.Name }).ToList(); if(user.HrmEmployeeId!=null) { ERPOptima.Model.HRM.HrmEmployee emp = new ERPOptima.Model.HRM.HrmEmployee(); ERPOptima.Service.Hrm.HrmEmployeeService es = new ERPOptima.Service.Hrm.HrmEmployeeService(new ERPOptima.Data.Hrm.Repository.HrmEmployeeRepository(dbfactory), new UnitOfWork(dbfactory)); emp = es.GetById(user.HrmEmployeeId.Value); if(emp!=null) { ISecCompanyService _company; _company = new SecCompanyService(new SecCompanyRepository(dbfactory), new UnitOfWork(dbfactory)); var defaultCompany = _company.GetById(emp.SecCompanyId.Value); if (defaultCompany != null) { var obj = new { Id = defaultCompany.Id, Name = defaultCompany.Name }; if (!list.Contains(obj)) { list.Insert(0, obj); } } } } return Json(list, JsonRequestBehavior.AllowGet); }