/// <summary> /// Retrive project information by user /// </summary> /// <param name="userId">Pk User Id</param> /// <returns></returns> public List <ProjectByUserEntity> RetriveData(int userId) { try { using (var ctx = new ModelTestContext()) { var resp = (from up in ctx.UserProjects join pj in ctx.Projects on up.ProjectId equals pj.Id where up.UserId == userId select new ProjectByUserEntity { ProjectId = up.ProjectId, StartDate = pj.StartDate, TimeToStart = (SqlFunctions.DateDiff("day", pj.StartDate, up.AssignedDate) < 0 ?"Started": SqlFunctions.DateDiff("day", pj.StartDate, up.AssignedDate).ToString()), EndDate = pj.EndDate, Credits = pj.Credits, Status = ((up.IsActive.Equals(true)) ? "Active": "Inactive") }).ToList(); return(resp); } } catch (Exception ex) { throw new Exception("Some thing goind bad: " + ex.Message); //log in some DLL log library. } }
/// <summary> /// Retrive all users /// </summary> /// <returns>User list</returns> public List <UserEntity> AllUsers() { using (var ctx = new ModelTestContext()) { var resp = (from up in ctx.Users select new UserEntity { Id = up.Id, Name = (up.FirstName + " " + up.LastName) }).ToList(); return(resp); } }