Exemple #1
0
        public Entity.BaseResponse <List <Response.DevicePeakHoursResponse> > GetPeakHoursByElevator(Request.ElevatorsPeakRequest request)
        {
            Entity.BaseResponse <List <Response.DevicePeakHoursResponse> > responseResult = new Entity.BaseResponse <List <Response.DevicePeakHoursResponse> >();
            List <Response.DevicePeakHoursResponse> tripList = new List <Response.DevicePeakHoursResponse>();

            try
            {
                string ids = String.Join(",", request.ElevatorList);
                _logger.InfoLog(Constants.ACTION_ENTRY, "Chart_PeakHoursByElevator.Get");
                using (var sqlDataAccess = new SqlDataAccess(ConnectionString))
                {
                    List <Response.OperationHours> result     = new List <Response.OperationHours>();
                    List <DbParameter>             parameters = sqlDataAccess.CreateParams(component.helper.SolutionConfiguration.CurrentUserId, component.helper.SolutionConfiguration.Version);
                    parameters.Add(sqlDataAccess.CreateParameter("companyguid", component.helper.SolutionConfiguration.CompanyId, DbType.Guid, ParameterDirection.Input));
                    parameters.Add(sqlDataAccess.CreateParameter("elevators", ids, DbType.String, ParameterDirection.Input));
                    parameters.Add(sqlDataAccess.CreateParameter("frequency", request.Frequency, DbType.String, ParameterDirection.Input));
                    parameters.Add(sqlDataAccess.CreateParameter("enableDebugInfo", component.helper.SolutionConfiguration.EnableDebugInfo, DbType.String, ParameterDirection.Input));
                    parameters.Add(sqlDataAccess.CreateParameter("syncDate", DateTime.UtcNow, DbType.DateTime, ParameterDirection.Output));
                    DbDataReader dbDataReader = sqlDataAccess.ExecuteReader(sqlDataAccess.CreateCommand("[Chart_PeakHoursByElevator]", CommandType.StoredProcedure, null), parameters.ToArray());
                    result = DataUtils.DataReaderToList <Response.OperationHours>(dbDataReader, null);
                    if (parameters.Where(p => p.ParameterName.Equals("syncDate")).FirstOrDefault() != null)
                    {
                        responseResult.LastSyncDate = Convert.ToString(parameters.Where(p => p.ParameterName.Equals("syncDate")).FirstOrDefault().Value);
                    }

                    var resultGrp = from data in result
                                    group data by data.Name
                                    into egroup
                                    select egroup;

                    foreach (var group in resultGrp)
                    {
                        List <Response.PeakLookup> lookupItems = new List <Response.PeakLookup>();
                        foreach (var items in group)
                        {
                            lookupItems.Add(new Response.PeakLookup {
                                Name = items.ElevatorName, Value = items.Value
                            });
                        }
                        tripList.Add(new Response.DevicePeakHoursResponse {
                            Time = group.Key, Value = lookupItems
                        });
                    }
                    responseResult.Data = tripList;
                }
                _logger.InfoLog(Constants.ACTION_EXIT, null, "", "", this.GetType().Name, MethodBase.GetCurrentMethod().Name);
            }
            catch (Exception ex)
            {
                _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name);
            }
            return(responseResult);
        }
        public Entity.BaseResponse <List <Response.DevicePeakHoursResponse> > GetDevicesPeakHours(Request.ElevatorsPeakRequest elevatorIds)
        {
            if (elevatorIds == null)
            {
                return(new Entity.BaseResponse <List <Response.DevicePeakHoursResponse> >(false, "Invalid Request"));
            }

            Entity.BaseResponse <List <Response.DevicePeakHoursResponse> > response = new Entity.BaseResponse <List <Response.DevicePeakHoursResponse> >(true);
            try
            {
                List <Response.DevicePeakHoursResponse> tripList = new List <Response.DevicePeakHoursResponse> {
                    new Response.DevicePeakHoursResponse {
                        Time = "0:00", Value = new List <Response.PeakLookup>
                        {
                            new Response.PeakLookup {
                                Name = "e1", Value = "10"
                            },
                            new Response.PeakLookup {
                                Name = "e2", Value = "10"
                            },
                        }
                    },
                    new Response.DevicePeakHoursResponse {
                        Time = "1:00", Value = new List <Response.PeakLookup>
                        {
                            new Response.PeakLookup {
                                Name = "e1", Value = "20"
                            },
                            new Response.PeakLookup {
                                Name = "e2", Value = "20"
                            },
                        }
                    },
                    new Response.DevicePeakHoursResponse {
                        Time = "3:00", Value = new List <Response.PeakLookup>
                        {
                            new Response.PeakLookup {
                                Name = "e1", Value = "30"
                            },
                            new Response.PeakLookup {
                                Name = "e2", Value = "30"
                            },
                        }
                    },
                };
                response.Data      = tripList;
                response.IsSuccess = true;
            }
            catch (Exception ex)
            {
                base.LogException(ex);
                return(new Entity.BaseResponse <List <Response.DevicePeakHoursResponse> >(false, ex.Message));
            }
            return(response);
        }
 public Entity.BaseResponse <List <Response.DevicePeakHoursResponse> > PeakHoursByElevator(Request.ElevatorsPeakRequest request)
 {
     Entity.BaseResponse <List <Response.DevicePeakHoursResponse> > response = new Entity.BaseResponse <List <Response.DevicePeakHoursResponse> >();
     try
     {
         response           = _chartService.GetPeakHoursByElevator(request);
         response.IsSuccess = true;
     }
     catch (Exception ex)
     {
         base.LogException(ex);
         return(new Entity.BaseResponse <List <Response.DevicePeakHoursResponse> >(false, ex.Message));
     }
     return(response);
 }