예제 #1
0
 public IHttpActionResult GetClientWiseReport(string empId, DateTime?fromDate, DateTime?toDate, string clientId, int?priority, string status, string taskId, int?catId)
 {
     try
     {
         using (MaxMasterDbEntities db = new MaxMasterDbEntities())
         {
             var allEmpTaskData = db.GetEmployeesActivitiesReport(empId, fromDate, toDate, clientId, status, priority, taskId, catId).ToList();
             var reportData     = allEmpTaskData.Where(x => x.Department == null).GroupBy(x => x.Client).Select(x => x.First()).Select(x => new
             {
                 x.Client,
                 x.Client_Id,
                 Task = allEmpTaskData.Where(y => y.Client_Id == x.Client_Id).GroupBy(y => y.TaskId).Select(y => y.First()).Select(y => new
                 {
                     y.TaskId,
                     y.Client,
                     y.Department,
                     y.Category,
                     y.SubCategory,
                     y.Subject,
                     y.Description,
                     y.Priority,
                     y.CreatedDate,
                     y.EDOC,
                     y.CreatedBy,
                     y.CreatedById,
                     y.TaskOwner,
                     y.TaskOwnerId,
                     y.CompletedDate,
                     y.ParentTask_Id,
                     y.Status,
                     y.TaskType,
                     y.AssignedTo,
                     y.AssignedToId,
                     y.Project,
                     y.Quantity,
                     HoursWorked       = allEmpTaskData.Where(z => z.TaskId == y.TaskId).Sum(z => (decimal?)z.TaskLogHoursWorked) ?? 0,
                     ActualStartDate   = allEmpTaskData.Where(z => z.TaskId == y.TaskId).GroupBy(z => z.TaskLogId).Select(z => z.First()).ToList().Where(tl => tl.TaskLogStartDate != null).FirstOrDefault(),
                     ExpectedStartDate = allEmpTaskData.Where(z => z.TaskId == y.TaskId).GroupBy(z => z.TaskLogId).Select(z => z.First()).ToList().Where(tl => tl.TaskLogStartDate != null).FirstOrDefault(),
                     ExpectedEndDate   = allEmpTaskData.Where(z => z.TaskId == y.TaskId).GroupBy(z => z.TaskLogId).Select(z => z.First()).ToList().Where(tl => tl.TaskLogStartDate != null).FirstOrDefault(),
                     BudgetedHours     = allEmpTaskData.Where(z => z.TaskId == y.TaskId).GroupBy(z => z.TaskLogId).Select(z => z.First()).ToList().Where(tl => tl.TaskLogStartDate != null).FirstOrDefault(),
                     TaskLog           = allEmpTaskData.Where(z => z.TaskId == y.TaskId).GroupBy(z => z.TaskLogId).Select(z => z.First()).Select(z => new
                     {
                         z.TaskLogId,
                         z.TaskLogTaskId,
                         z.TaskLogDate,
                         z.TaskLogAssignedTo,
                         z.TaskLogAssignedToId,
                         z.TaskLogAssignedBy,
                         z.TaskLogAssignedById,
                         z.TaskLogBudgetedHours,
                         z.TaskLogStartDate,
                         z.TaskLogEndDate,
                         z.TaskLogHoursWorked,
                         z.TaskLogStatus,
                         z.TaskLogDescription,
                         z.TaskLogQuantityWorked
                     }).OrderBy(z => z.TaskLogDate).ToList()
                 }).ToList()
             }).ToList();
             return(Content(HttpStatusCode.OK, new { reportData }));
         }
     }
     catch (Exception ex)
     {
         new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace);
         return(Content(HttpStatusCode.InternalServerError, "An error occured, please try again later"));
     }
 }