コード例 #1
0
        public IActionResult GetMonitoring(long prId)
        {
            try
            {
                identityService.Username       = User.Claims.Single(p => p.Type.Equals("username")).Value;
                identityService.TimezoneOffset = int.Parse(Request.Headers["x-timezone-offset"].First());
                identityService.Token          = Request.Headers["Authorization"].First().Replace("Bearer ", "");

                if (Request.Headers["accept"] == "application/xls")
                {
                    Tuple <MemoryStream, string> xls = facade.GetExcel(prId);
                    byte[] xlsInBytes = xls.Item1.ToArray();
                    var    file       = File(xlsInBytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", $"{xls.Item2}.xlsx");
                    return(file);
                }

                var result = facade.GetMonitoring(prId);

                Dictionary <string, object> Result =
                    new ResultFormatter(ApiVersion, General.OK_STATUS_CODE, General.OK_MESSAGE)
                    .Ok(result);
                return(Ok(Result));
            }
            catch (Exception e)
            {
                Dictionary <string, object> Result =
                    new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message)
                    .Fail();
                return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, Result));
            }
        }
        public IActionResult GetReport(long prId, string Order = "{}")
        {
            int    offset = Convert.ToInt32(Request.Headers["x-timezone-offset"]);
            string accept = Request.Headers["Accept"];

            try
            {
                var data = facade.GetMonitoring(prId, Order);

                return(Ok(new
                {
                    apiVersion = ApiVersion,
                    data = data.Item1,
                    info = new { total = data.Item2 },
                    message = General.OK_MESSAGE,
                    statusCode = General.OK_STATUS_CODE
                }));
            }
            catch (Exception e)
            {
                Dictionary <string, object> Result =
                    new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message)
                    .Fail();
                return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, Result));
            }
        }