Beispiel #1
0
        public async Task <IActionResult> RequireJobCardDetalScheduleOnlyGmCm([FromBody] OptionScheduleViewModel Schedule)
        {
            var Message = "Data not been found.";

            try
            {
                if (Schedule != null)
                {
                    int TotalRow;
                    var predicate = PredicateBuilder.False <JobCardDetail>();
                    // Filter
                    var filters = string.IsNullOrEmpty(Schedule.Filter) ? new string[] { "" }
                                        : Schedule.Filter.ToLower().Split(null);
                    foreach (var keyword in filters)
                    {
                        string temp = keyword;
                        predicate = predicate.Or(x => x.CuttingPlan.CuttingPlanNo.ToLower().Contains(temp) ||
                                                 x.Material.ToLower().Contains(temp) ||
                                                 x.Remark.ToLower().Contains(temp) ||
                                                 x.JobCardMaster.ProjectCodeDetail.ProjectCodeMaster.ProjectCode.ToLower().Contains(temp) ||
                                                 x.JobCardMaster.ProjectCodeDetail.ProjectCodeDetailCode.ToLower().Contains(temp) ||
                                                 x.JobCardMaster.JobCardMasterNo.ToLower().Contains(temp));
                    }

                    predicate = predicate.And(x => x.JobCardDetailStatus != null &&
                                              x.JobCardDetailStatus == JobCardDetailStatus.Wait &&
                                              x.JobCardMaster.JobCardMasterStatus != JobCardMasterStatus.Cancel);

                    // Option ProjectCodeMaster
                    if (Schedule.ProjectMasterId.HasValue)
                    {
                        predicate = predicate.And(x => x.JobCardMaster.ProjectCodeDetail.ProjectCodeMasterId == Schedule.ProjectMasterId);
                    }

                    if (Schedule.ProjectDetailId.HasValue)
                    {
                        predicate = predicate.And(x => x.JobCardMaster.ProjectCodeDetailId == Schedule.ProjectDetailId);
                    }

                    // Option Status
                    if (Schedule.TypeMachineId.HasValue)
                    {
                        predicate = predicate.And(x => x.JobCardMaster.TypeMachineId == Schedule.TypeMachineId);
                    }
                    else
                    {
                        predicate = predicate.And(x => x.JobCardMaster.TypeMachine.TypeMachineCode.Contains("GM") ||
                                                  x.JobCardMaster.TypeMachine.TypeMachineCode.Contains("CM"));
                    }

                    TotalRow = await this.repository.GetLengthWithAsync(predicate);

                    var HasData = await this.repository.GetToListAsync(
                        selector : x => x,
                        predicate : predicate,
                        include : x => x.Include(z => z.CuttingPlan)
                        .Include(z => z.JobCardMaster.TypeMachine)
                        .Include(z => z.JobCardMaster.ProjectCodeDetail.ProjectCodeMaster),
                        skip : Schedule.Skip ?? 0,
                        take : Schedule.Take ?? 10,
                        orderBy : x => x.OrderByDescending(z => z.JobCardMaster.JobCardDate));

                    if (HasData.Any())
                    {
                        List <string> Columns = new List <string>();
                        // PlanDate
                        List <DateTime?> ListDate = new List <DateTime?>()
                        {
                            //START Date
                            HasData.Min(x => x.CreateDate),
                            HasData.Min(x => x?.JobCardMaster?.JobCardDate) ?? null,
                            HasData.Min(x => x?.JobCardMaster?.DueDate) ?? null,
                            //END Date
                            HasData.Max(x => x.CreateDate),
                            HasData.Max(x => x?.JobCardMaster?.JobCardDate) ?? null,
                            HasData.Max(x => x?.JobCardMaster?.DueDate) ?? null,
                        };

                        DateTime?MinDate = ListDate.Min();
                        DateTime?MaxDate = ListDate.Max();

                        if (MinDate == null && MaxDate == null)
                        {
                            return(BadRequest(new { Error = Message }));
                        }
                        // EachDay
                        var EachDate = new Helper.LoopEachDate();

                        foreach (DateTime day in EachDate.EachDate(MinDate.Value, MaxDate.Value.AddDays(1)).OrderByDescending(x => x.Value))
                        {
                            if (HasData.Any(x => x.CreateDate.Value.Date == day.Date))
                            {
                                Columns.Add(day.Date.ToString("dd/MM/yy"));
                            }
                        }

                        var DataTable = new List <IDictionary <String, Object> >();
                        foreach (var GroupMachine in HasData.GroupBy(z => z.JobCardMaster.TypeMachine))
                        {
                            foreach (var Data in GroupMachine.OrderBy(x => x.CreateDate))
                            {
                                var JobNumber = $"{Data?.JobCardMaster?.ProjectCodeDetail?.ProjectCodeMaster?.ProjectCode ?? "No-Data"}" +
                                                $"/{(Data?.JobCardMaster?.ProjectCodeDetail == null ? "No-Data" : Data.JobCardMaster.ProjectCodeDetail.ProjectCodeDetailCode)}";

                                IDictionary <String, Object> rowData;
                                var  WorkGroup = Data?.JobCardMaster?.TypeMachine?.TypeMachineCode ?? "";
                                bool update    = false;
                                if (DataTable.Any(x => (string)x["JobNumber"] == JobNumber && (string)x["GroupMachine"] == WorkGroup))
                                {
                                    var FirstData = DataTable.FirstOrDefault(x => (string)x["JobNumber"] == JobNumber);
                                    if (FirstData != null)
                                    {
                                        rowData = FirstData;
                                        update  = true;
                                    }
                                    else
                                    {
                                        rowData = new ExpandoObject();
                                    }
                                }
                                else
                                {
                                    rowData = new ExpandoObject();
                                }

                                if (Data.CreateDate != null)
                                {
                                    //Get Employee Name
                                    // var Employee = await this.repositoryEmp.GetAsync(Data.RequireEmp);
                                    // var EmployeeReq = Employee != null ? $"คุณ{(Employee?.NameThai ?? "")}" : "No-Data";

                                    var Key = Data.CreateDate.Value.ToString("dd/MM/yy");
                                    // New Data
                                    var Master = new JobCardDetailViewModel()
                                    {
                                        JobCardMasterId = Data.JobCardMasterId,
                                        JobCardDetailId = Data.JobCardDetailId,
                                        Quality         = Data.Quality,
                                        // RequireString = $"{EmployeeReq} | No.{Data.RequireNo}",
                                        CuttingPlanString = $"{(Data.CuttingPlan != null ? Data.CuttingPlan.CuttingPlanNo : "-")}",
                                    };

                                    if (rowData.Any(x => x.Key == Key))
                                    {
                                        // New Value
                                        var ListMaster = (List <JobCardDetailViewModel>)rowData[Key];
                                        ListMaster.Add(Master);
                                        // add to row data
                                        rowData[Key] = ListMaster;
                                    }
                                    else // add new
                                    {
                                        rowData.Add(Key, new List <JobCardDetailViewModel>()
                                        {
                                            Master
                                        });
                                    }
                                }

                                if (!update)
                                {
                                    rowData.Add("JobNumber", JobNumber);
                                    rowData.Add("GroupMachine", Data.JobCardMaster.TypeMachine.TypeMachineCode);
                                    DataTable.Add(rowData);
                                }
                            }
                        }


                        return(new JsonResult(new
                        {
                            TotalRow,
                            Columns,
                            DataTable
                        }, this.DefaultJsonSettings));
                    }
                    else
                    {
                        return(NoContent());
                    }
                }
            }
            catch (Exception ex)
            {
                Message = $"Has error {ex.ToString()}";
            }

            return(BadRequest(new { error = Message }));
        }
        public async Task <IActionResult> CuttingPlanNotFinish([FromBody] ScrollViewModel Scroll)
        {
            var Message = "";

            try
            {
                if (Scroll == null)
                {
                    return(BadRequest());
                }

                int TotalRow;
                var predicate = PredicateBuilder.False <CuttingPlan>();
                // Filter
                var filters = string.IsNullOrEmpty(Scroll.Filter) ? new string[] { "" }
                                    : Scroll.Filter.Split(null);
                foreach (string temp in filters)
                {
                    string keyword = temp;
                    predicate = predicate.Or(x => x.Description.ToLower().Contains(keyword) ||
                                             x.CuttingPlanNo.ToLower().Contains(keyword) ||
                                             x.MaterialSize.ToLower().Contains(keyword) ||
                                             x.ProjectCodeDetail.ProjectCodeDetailCode.ToLower().Contains(keyword) ||
                                             x.ProjectCodeDetail.ProjectCodeMaster.ProjectCode.ToLower().Contains(keyword));
                }

                predicate = predicate.And(x =>
                                          x.JobCardDetails.Any(z => z.JobCardDetailStatus == JobCardDetailStatus.Wait &&
                                                               z.JobCardMaster.JobCardMasterStatus != JobCardMasterStatus.Complete &&
                                                               z.JobCardMaster.JobCardMasterStatus != JobCardMasterStatus.Cancel) &&
                                          x.TypeCuttingPlan == TypeCuttingPlan.CuttingPlan);

                // Option ProjectDetailId
                if (Scroll.WhereId.HasValue)
                {
                    predicate = predicate.And(x => x.ProjectCodeDetail.ProjectCodeDetailId == Scroll.WhereId);
                }

                // Option SDate
                if (Scroll.SDate.HasValue)
                {
                    Scroll.SDate = Scroll.SDate.Value.AddHours(7);
                    predicate    = predicate.And(x =>
                                                 x.CreateDate.Value.Date >= Scroll.SDate.Value.Date);
                }

                // Option EDate
                if (Scroll.EDate.HasValue)
                {
                    Scroll.EDate = Scroll.EDate.Value.AddHours(7);
                    predicate    = predicate.And(x =>
                                                 x.CreateDate.Value.Date <= Scroll.EDate.Value.Date);
                }

                TotalRow = await this.repository.GetLengthWithAsync(predicate);

                var HasData = await this.repository.GetToListAsync(
                    x => x, predicate,
                    x => x.OrderBy(z => z.CreateDate),
                    x => x.Include(z => z.ProjectCodeDetail.ProjectCodeMaster),
                    Scroll.Skip ?? 0, Scroll.Take ?? 10);

                if (HasData.Any())
                {
                    List <string> Columns = new List <string>();
                    // PlanDate
                    List <DateTime?> ListDate = new List <DateTime?>()
                    {
                        //START Date
                        HasData.Min(x => x.CreateDate),
                        //END Date
                        HasData.Max(x => x.CreateDate),
                    };

                    DateTime?MinDate = ListDate.Min();
                    DateTime?MaxDate = ListDate.Max();

                    if (MinDate == null && MaxDate == null)
                    {
                        return(BadRequest(new { Error = Message }));
                    }

                    // EachDay
                    var EachDate = new Helper.LoopEachDate();

                    foreach (DateTime day in EachDate.EachDate(MinDate.Value, MaxDate.Value.AddDays(1)).OrderByDescending(x => x.Value))
                    {
                        if (HasData.Any(x => x.CreateDate.Value.Date == day.Date))
                        {
                            Columns.Add(day.Date.ToString("dd/MM/yy"));
                        }
                    }

                    var DataTable = new List <IDictionary <string, object> >();

                    foreach (var Data in HasData.OrderBy(x => x.CreateDate))
                    {
                        var JobNumber = $"{Data?.ProjectCodeDetail?.ProjectCodeMaster?.ProjectCode ?? "No-Data"}" +
                                        $"/{(Data?.ProjectCodeDetail == null ? "No-Data" : Data.ProjectCodeDetail.ProjectCodeDetailCode)}";

                        IDictionary <string, object> rowData;
                        bool update = false;
                        if (DataTable.Any(x => (string)x["JobNumber"] == JobNumber))
                        {
                            var FirstData = DataTable.FirstOrDefault(x => (string)x["JobNumber"] == JobNumber);
                            if (FirstData != null)
                            {
                                rowData = FirstData;
                                update  = true;
                            }
                            else
                            {
                                rowData = new ExpandoObject();
                            }
                        }
                        else
                        {
                            rowData = new ExpandoObject();
                        }

                        if (Data.CreateDate != null)
                        {
                            //Get Employee Name

                            var Key = Data.CreateDate.Value.ToString("dd/MM/yy");
                            // New Data
                            var Master = new CuttingPlanViewModel()
                            {
                                CuttingPlanId = Data.CuttingPlanId,
                                // RequireString = $"{EmployeeReq} | No.{Data.RequireNo}",
                                CuttingPlanNo = Data.CuttingPlanNo,
                            };

                            if (rowData.Any(x => x.Key == Key))
                            {
                                // New Value
                                var ListMaster = (List <CuttingPlanViewModel>)rowData[Key];
                                ListMaster.Add(Master);
                                // add to row data
                                rowData[Key] = ListMaster;
                            }
                            else // add new
                            {
                                rowData.Add(Key, new List <CuttingPlanViewModel>()
                                {
                                    Master
                                });
                            }
                        }

                        if (!update)
                        {
                            rowData.Add("JobNumber", JobNumber);
                            DataTable.Add(rowData);
                        }
                    }

                    return(new JsonResult(new
                    {
                        TotalRow,
                        Columns,
                        DataTable
                    }, this.DefaultJsonSettings));
                }
                else
                {
                    return(NoContent());
                }
            }
            catch (Exception ex)
            {
                Message = $"Has error {ex.ToString()}";
            }

            return(BadRequest(new { Error = Message }));
        }
        public async Task <IActionResult> ScheduleWithRequire([FromBody] OptionItemMaintananceSchedule Schedule)
        {
            var message = "Data not found.";

            try
            {
                Expression <Func <RequireMaintenance, bool> > expression = x => x.RequireStatus != RequireStatus.Cancel;
                int TotalRow;
                Func <IQueryable <RequireMaintenance>, IOrderedQueryable <RequireMaintenance> > order = o => o.OrderBy(x => x.RequireDate);

                if (Schedule != null)
                {
                    // Option Filter
                    if (!string.IsNullOrEmpty(Schedule.Filter))
                    {
                        var filters = string.IsNullOrEmpty(Schedule.Filter) ? new string[] { "" }
                                   : Schedule.Filter.ToLower().Split(null);
                        foreach (var keyword in filters)
                        {
                            expression = expression.And(x => x.Description.ToLower().Contains(keyword) ||
                                                        x.Remark.ToLower().Contains(keyword) ||
                                                        x.ItemMaintenance.ItemMaintenanceNo.ToLower().Contains(keyword) ||
                                                        x.ItemMaintenance.TypeMaintenance.Name.ToLower().Contains(keyword) ||
                                                        x.Item.ItemType.Name.ToLower().Contains(keyword) ||
                                                        x.Item.ItemCode.ToLower().Contains(keyword) ||
                                                        x.Item.Name.ToLower().Contains(keyword));
                        }
                    }

                    // Option Mode
                    if (Schedule.Mode.HasValue)
                    {
                        if (Schedule.Mode == 1)
                        {
                            order = o => o.OrderByDescending(x => x.RequireDate);
                        }
                        else
                        {
                            expression = expression.And(x => x.RequireStatus == RequireStatus.InProcess ||
                                                        x.RequireStatus == RequireStatus.Waiting ||
                                                        x.RequireStatus == RequireStatus.MaintenanceResponse);

                            order = o => o.OrderBy(x => x.RequireDate);
                        }
                    }
                    // Option ProjectMasterId
                    if (Schedule.ProjectMasterId.HasValue)
                    {
                        expression = expression.And(x => x.ProjectCodeMasterId == Schedule.ProjectMasterId);
                    }
                    // Option Create
                    if (!string.IsNullOrEmpty(Schedule.Creator))
                    {
                        expression = expression.And(x => x.RequireEmp == Schedule.Creator);
                    }
                    // Option RequireMaintenance
                    if (Schedule.RequireMaintenanceId.HasValue)
                    {
                        expression = expression.And(x => x.RequireMaintenanceId == Schedule.RequireMaintenanceId);
                    }
                    // Option WorkGroupMaintenance
                    if (Schedule.GroupMaintenanceId.HasValue)
                    {
                        expression = expression.And(x => x.ItemMaintenance.WorkGroupMaintenanceId == Schedule.GroupMaintenanceId);
                    }

                    TotalRow = await this.repository.GetLengthWithAsync(predicate : expression);

                    // Option Skip and Task
                    // if (Scehdule.Skip.HasValue && Scehdule.Take.HasValue)
                    // ueryData = QueryData.Skip(Schedule.Skip ?? 0).Take(Schedule.Take ?? 20);
                }
                else
                {
                    TotalRow = await this.repository.GetLengthWithAsync();
                }

                var GetData = await this.repository.GetToListAsync(
                    selector : selected => selected, // Selected
                    predicate : expression,          // Where
                    orderBy : order,                 // Order
                    include : x => x.Include(z => z.ItemMaintenance.WorkGroupMaintenance)
                    .Include(z => z.Item),           // Include
                    skip : Schedule.Skip ?? 0,       // Skip
                    take : Schedule.Take ?? 50);     // Take

                if (GetData.Any())
                {
                    IDictionary <string, int>      ColumnGroupTop = new Dictionary <string, int>();
                    IDictionary <DateTime, string> ColumnGroupBtm = new Dictionary <DateTime, string>();
                    List <string> ColumnsAll = new List <string>();
                    // PlanDate
                    List <DateTime?> ListDate = new List <DateTime?>()
                    {
                        //START Date
                        GetData.Min(x => x.RequireDate),
                        GetData.Min(x => x?.ItemMaintenance?.PlanStartDate) ?? null,
                        GetData.Min(x => x?.ItemMaintenance?.ActualStartDate) ?? null,
                        GetData.Min(x => x?.MaintenanceApply) ?? null,
                        //END Date
                        GetData.Max(x => x.RequireDate),
                        GetData.Max(x => x?.ItemMaintenance?.PlanEndDate) ?? null,
                        GetData.Max(x => x?.ItemMaintenance?.ActualEndDate) ?? null,
                        GetData.Max(x => x?.MaintenanceApply) ?? null,
                    };

                    DateTime?MinDate = ListDate.Min();
                    DateTime?MaxDate = ListDate.Max();

                    if (MinDate == null && MaxDate == null)
                    {
                        return(NotFound(new { Error = "Data not found" }));
                    }

                    int countCol = 1;
                    // add Date to max
                    MaxDate = MaxDate.Value.AddDays(2);
                    MinDate = MinDate.Value.AddDays(-2);

                    // If Range of date below then 15 day add more
                    var RangeDay = (MaxDate.Value - MinDate.Value).Days;
                    if (RangeDay < 15)
                    {
                        MaxDate = MaxDate.Value.AddDays((15 - RangeDay) / 2);
                        MinDate = MinDate.Value.AddDays((((15 - RangeDay) / 2) * -1));
                    }

                    // EachDay
                    var EachDate = new Helper.LoopEachDate();
                    // Foreach Date
                    foreach (DateTime day in EachDate.EachDate(MinDate.Value, MaxDate.Value))
                    {
                        // Get Month
                        if (ColumnGroupTop.Any(x => x.Key == day.ToString("MMMM")))
                        {
                            ColumnGroupTop[day.ToString("MMMM")] += 1;
                        }
                        else
                        {
                            ColumnGroupTop.Add(day.ToString("MMMM"), 1);
                        }

                        ColumnGroupBtm.Add(day.Date, $"Col{countCol.ToString("00")}");
                        countCol++;
                    }

                    var DataTable = new List <IDictionary <String, Object> >();
                    // OrderBy(x => x.Machine.TypeMachineId).ThenBy(x => x.Machine.MachineCode)
                    foreach (var Data in GetData.OrderBy(x => x.RequireDate).ThenBy(x => x.CreateDate))
                    {
                        IDictionary <String, Object> rowData = new ExpandoObject();
                        var Progress = Data?.ItemMaintenance?.StatusMaintenance != null?System.Enum.GetName(typeof(StatusMaintenance), Data.ItemMaintenance.StatusMaintenance) : "NoAction";

                        var ProjectMaster = "NoData";
                        if (Data?.ProjectCodeMasterId != null)
                        {
                            var ProjectData = await this.repositoryProject.
                                              GetAsync(Data.ProjectCodeMasterId ?? 0);

                            ProjectMaster = ProjectData != null ? ($"{ProjectData.ProjectCode}/{ProjectData.ProjectName}") : "-";
                            if (ProjectMaster.Length > 25)
                            {
                                ProjectMaster = ProjectMaster.Substring(0, 25) + "...";
                            }
                        }

                        // add column time
                        rowData.Add("ProjectMaster", ProjectMaster);
                        rowData.Add("GroupMaintenance", Data?.ItemMaintenance?.WorkGroupMaintenance?.Description ?? "Not-Assign");
                        rowData.Add("Item", (Data == null ? "Data not been found" : $"{Data.Item.ItemCode}/{Data.Item.Name}"));
                        rowData.Add("Progress", Progress);
                        rowData.Add("ItemMainStatus", Data?.ItemMaintenance != null ? Data.ItemMaintenance.StatusMaintenance : StatusMaintenance.Cancel);
                        rowData.Add("ItemMaintenanceId", Data?.ItemMaintenance != null ? Data.ItemMaintenance.ItemMaintenanceId : 0);
                        // Add new
                        if (Data.MaintenanceApply.HasValue)
                        {
                            if (ColumnGroupBtm.Any(x => x.Key == Data.MaintenanceApply.Value.Date))
                            {
                                rowData.Add("Response", ColumnGroupBtm.FirstOrDefault(x => x.Key == Data.MaintenanceApply.Value.Date).Value);
                            }
                        }
                        // End new

                        // Data is 1:Plan,2:Actual,3:PlanAndActual
                        // For Plan1
                        if (Data.ItemMaintenance != null)
                        {
                            if (Data?.ItemMaintenance?.PlanStartDate != null && Data?.ItemMaintenance?.PlanEndDate != null)
                            {
                                // If Same Date can't loop
                                if (Data?.ItemMaintenance?.PlanStartDate.Date == Data?.ItemMaintenance?.PlanEndDate.Date)
                                {
                                    if (ColumnGroupBtm.Any(x => x.Key == Data?.ItemMaintenance?.PlanStartDate.Date))
                                    {
                                        rowData.Add(ColumnGroupBtm.FirstOrDefault(x => x.Key == Data?.ItemMaintenance?.PlanStartDate.Date).Value, 1);
                                    }
                                }
                                else
                                {
                                    foreach (DateTime day in EachDate.EachDate(Data.ItemMaintenance.PlanStartDate, Data.ItemMaintenance.PlanEndDate))
                                    {
                                        if (ColumnGroupBtm.Any(x => x.Key == day.Date))
                                        {
                                            rowData.Add(ColumnGroupBtm.FirstOrDefault(x => x.Key == day.Date).Value, 1);
                                        }
                                    }
                                }
                            }

                            //For Actual
                            if (Data?.ItemMaintenance?.ActualStartDate != null)
                            {
                                var EndDate = Data?.ItemMaintenance?.ActualEndDate ?? (MaxDate > DateTime.Today ? DateTime.Today : MaxDate);
                                if (Data?.ItemMaintenance?.ActualStartDate.Value.Date > EndDate.Value.Date)
                                {
                                    EndDate = Data?.ItemMaintenance?.ActualStartDate;
                                }
                                // If Same Date can't loop
                                if (Data?.ItemMaintenance?.ActualStartDate.Value.Date == EndDate.Value.Date)
                                {
                                    if (ColumnGroupBtm.Any(x => x.Key == Data?.ItemMaintenance?.ActualStartDate.Value.Date))
                                    {
                                        var Col = ColumnGroupBtm.FirstOrDefault(x => x.Key == Data?.ItemMaintenance?.ActualStartDate.Value.Date);
                                        // if Have Plan change value to 3
                                        if (rowData.Keys.Any(x => x == Col.Value))
                                        {
                                            rowData[Col.Value] = 3;
                                        }
                                        else // else Don't have plan value is 2
                                        {
                                            rowData.Add(Col.Value, 2);
                                        }
                                    }
                                }
                                else
                                {
                                    foreach (DateTime day in EachDate.EachDate(Data.ItemMaintenance.ActualStartDate.Value, EndDate.Value))
                                    {
                                        if (ColumnGroupBtm.Any(x => x.Key == day.Date))
                                        {
                                            var Col = ColumnGroupBtm.FirstOrDefault(x => x.Key == day.Date);

                                            // if Have Plan change value to 3
                                            if (rowData.Keys.Any(x => x == Col.Value))
                                            {
                                                rowData[Col.Value] = 3;
                                            }
                                            else // else Don't have plan value is 2
                                            {
                                                rowData.Add(Col.Value, 2);
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        DataTable.Add(rowData);
                    }

                    if (DataTable.Any())
                    {
                        ColumnGroupBtm.OrderBy(x => x.Key.Date).Select(x => x.Value)
                        .ToList().ForEach(item => ColumnsAll.Add(item));
                    }

                    return(new JsonResult(new
                    {
                        TotalRow,
                        ColumnsTop = ColumnGroupTop.Select(x => new
                        {
                            Name = x.Key,
                            x.Value
                        }),
                        ColumnsLow = ColumnGroupBtm.OrderBy(x => x.Key.Date).Select(x => x.Key.Day),
                        ColumnsAll,
                        DataTable
                    }, this.DefaultJsonSettings));
                }
            }
            catch (Exception ex)
            {
                message = $"Has error with message has {ex.ToString()}.";
            }
            return(BadRequest(new { Error = message }));
        }