Json return code to simplify if possible.
- by pirzada
Can you simplify this code?. Is there anything we can do to make it more simple. I am not sure but it looks ugly to me.
[HttpPost]
public JsonResult UserDetailById(int userId, string username)
{
IQueryable<Company> repository = companyRepository.GetGridCompanies();
Employee emp = companyRepository.GetEmployee(userId);
//Drop down fill
var a = (from c in repository
.OrderBy(c => c.companyName)
select new
{
Id = c.companyID,
Name = c.companyName
}).ToArray();
var data = new
{
Id = emp.companyID.ToString(),
Name = emp.employeeFirstname + " " + emp.employeeLastname,
Fn = emp.employeeFirstname,
Ln = emp.employeeLastname,
Dept = emp.employeeDepartment,
Sup = emp.employeeSup.ToString(),
HireDate = String.Format("{0:MM/dd/yyyy}", emp.employeeHiredate),
CompVm = a
};
return Json(data);
}