コード例 #1
0
        public HttpResponseMessage GetWorkHours(string strBeginDate, string strEndDate)
        {
            var resp = new HttpResponseMessage();

            if (!string.IsNullOrEmpty(strBeginDate) && !string.IsNullOrEmpty(strEndDate))
            {
                try
                {
                    DateTime beginDate = DateTime.Parse(strBeginDate);
                    DateTime endDate   = DateTime.Parse(strEndDate);

                    //get all the timesheet list between begin date and end date
                    IEnumerable <TimeSheet> allTimesheets = _timesheetService.FindList(beginDate, endDate);

                    if (allTimesheets.Count() > 0)
                    {
                        //get all the staffs job records based on timesheet list
                        var allJobRecords = allTimesheets.ToList().GroupBy(t => t.Task.Staff).Select(g => new JobRecordModel
                        {
                            StaffNo   = g.Key.StaffNo,
                            FirstName = g.Key.FirstName,
                            LastName  = g.Key.LastName,
                            BeginDate = beginDate,
                            EndDate   = endDate,
                            WorkHours = g.Sum(t => t.WorkHours)
                        });



                        resp.Content = new StringContent(JsonConvert.SerializeObject(allJobRecords), System.Text.Encoding.UTF8, "application/json");
                    }
                    else
                    {
                        resp.Content = new StringContent(JsonHelper.NoDataJsonError(), System.Text.Encoding.UTF8, "application/json");
                    }
                }
                catch (Exception e)
                {
                    resp.Content = new StringContent(JsonHelper.APIJsonError(e.Message), System.Text.Encoding.UTF8, "application/json");
                }
            }
            else
            {
                resp.Content = new StringContent(JsonHelper.ParameterJsonError(), System.Text.Encoding.UTF8, "application/json");
            }


            return(resp);
        }