コード例 #1
0
        private SummaryTaskDto GetSummaryTask(int condition, string token)
        {
            SummaryTaskDto taskForDay = null;

            using (var client = new HttpClient())
            {
                //client.BaseAddress = new Uri("http://localhost:65076/api");
                //client.DefaultRequestHeaders.Accept.Clear();
                //client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
                //HTTP GET
                string url_api      = "http://localhost:65076/api/Task/" + condition + "/GetSummary";
                var    responseTask = client.GetAsync(url_api);
                responseTask.Wait();

                var result = responseTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    var readTask = result.Content.ReadAsAsync <SummaryTaskDto>();
                    readTask.Wait();

                    taskForDay = readTask.Result;
                }
                else //web api sent error response
                {
                    //log response status here..

                    taskForDay = new SummaryTaskDto
                    {
                        TaskTotal   = 0,
                        TaskDone    = 0,
                        TaskNotDone = 0,
                        TaskRate    = 0
                    };
                }
            }
            return(taskForDay);
        }
コード例 #2
0
        public IHttpActionResult GetSummaryTaskForDay(int condition)
        {
            List <SummaryDto> summarys = new List <SummaryDto>();

            switch (condition)
            {
            case Constants.INT_DAY:
                summarys = (from n in db.t_task
                            where (n.StartDate.Day == DateTime.Now.Day || n.EndDate.Day == DateTime.Now.Day)
                            select new SummaryDto
                {
                    NotDone = (n.Done != 100 ? 1 : 0),
                    Done = (n.Done == 100 ? 1 : 0)
                }).ToList();
                break;

            case Constants.INT_MONTH:
                summarys = (from n in db.t_task
                            where (n.StartDate.Month == DateTime.Now.Month || n.EndDate.Month == DateTime.Now.Month)
                            select new SummaryDto
                {
                    NotDone = (n.Done != 100 ? 1 : 0),
                    Done = (n.Done == 100 ? 1 : 0)
                }).ToList();
                break;

            case Constants.INT_QUARTER:
                int mth        = DateTime.Now.Month;
                int startMonth = 0;
                int endMonth   = 0;
                if (mth <= 3)
                {
                    startMonth = 1;
                    endMonth   = 3;
                }
                else if (mth > 3 && mth <= 6)
                {
                    startMonth = 4;
                    endMonth   = 6;
                }
                else if (mth > 6 && mth <= 9)
                {
                    startMonth = 7;
                    endMonth   = 9;
                }
                else if (mth > 9 && mth <= 12)
                {
                    startMonth = 10;
                    endMonth   = 12;
                }

                summarys = (from n in db.t_task
                            where ((n.StartDate.Month >= startMonth && n.StartDate.Month <= endMonth) || (n.EndDate.Month >= startMonth && n.EndDate.Month <= endMonth))
                            select new SummaryDto
                {
                    NotDone = (n.Done != 100 ? 1 : 0),
                    Done = (n.Done == 100 ? 1 : 0)
                }).ToList();

                break;

            case Constants.INT_YEAR:
                summarys = (from n in db.t_task
                            where (n.StartDate.Year == DateTime.Now.Year || n.EndDate.Year == DateTime.Now.Year)
                            select new SummaryDto
                {
                    NotDone = (n.Done != 100 ? 1 : 0),
                    Done = (n.Done == 100 ? 1 : 0)
                }).ToList();
                break;

            default: break;
            }

            if (summarys.Count() == 0)
            {
                return(NotFound());
            }
            SummaryTaskDto summary;
            int            sumTaskDone    = summarys.Select(n => n.Done).Sum();
            int            sumTaskNotDone = summarys.Select(n => n.NotDone).Sum();

            summary = new SummaryTaskDto
            {
                TaskTotal   = sumTaskDone + sumTaskNotDone,
                TaskDone    = sumTaskDone,
                TaskNotDone = sumTaskNotDone,
                TaskRate    = (sumTaskDone * 100) / (sumTaskDone + sumTaskNotDone)
            };

            return(Ok(summary));
        }