Ejemplo n.º 1
0
        public async Task <IActionResult> GetUnitsList()
        {
            List <UnitForListJson> unitsJson = new List <UnitForListJson>();

            var units = await _unitsService.GetUnitsForDepartmentAsync(DepartmentId);

            var states = await _unitsService.GetAllLatestStatusForUnitsByDepartmentIdAsync(DepartmentId);

            var department = await _departmentsService.GetDepartmentByIdAsync(DepartmentId, false);

            var groups = await _departmentGroupsService.GetAllGroupsForDepartmentAsync(DepartmentId);

            foreach (var unit in units)
            {
                var unitJson = new UnitForListJson();
                unitJson.Name   = unit.Name;
                unitJson.Type   = unit.Type;
                unitJson.UnitId = unit.UnitId;

                if (unit.StationGroupId.HasValue)
                {
                    var group = groups.FirstOrDefault(x => x.DepartmentGroupId == unit.StationGroupId.Value);

                    if (group != null)
                    {
                        unitJson.Station = group.Name;
                    }
                }

                var state = states.FirstOrDefault(x => x.UnitId == unit.UnitId);

                if (state != null)
                {
                    var customState = await CustomStatesHelper.GetCustomUnitState(state);

                    unitJson.StateId    = state.State;
                    unitJson.State      = customState.ButtonText;
                    unitJson.StateColor = customState.ButtonColor;
                    unitJson.TextColor  = customState.TextColor;
                    unitJson.Timestamp  = state.Timestamp.TimeConverterToString(department);
                }

                unitsJson.Add(unitJson);
            }

            return(Json(unitsJson));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> GetUnitsList(int linkId)
        {
            var link = await _departmentLinksService.GetLinkByIdAsync(linkId);

            if (link.DepartmentId != DepartmentId && link.LinkedDepartmentId != DepartmentId)
            {
                Unauthorized();
            }

            List <UnitForListJson> unitsJson = new List <UnitForListJson>();

            var units = await _unitsService.GetUnitsForDepartmentAsync(link.DepartmentId);

            var states = await _unitsService.GetAllLatestStatusForUnitsByDepartmentIdAsync(link.DepartmentId);

            var department = await _departmentsService.GetDepartmentByIdAsync(link.DepartmentId, false);

            foreach (var unit in units)
            {
                var unitJson = new UnitForListJson();
                unitJson.Name   = unit.Name;
                unitJson.Type   = unit.Type;
                unitJson.UnitId = unit.UnitId;

                if (unit.StationGroup != null)
                {
                    unitJson.Station = unit.StationGroup.Name;
                }

                var state = states.FirstOrDefault(x => x.UnitId == unit.UnitId);

                if (state != null)
                {
                    var customState = await CustomStatesHelper.GetCustomUnitState(state);

                    unitJson.StateId    = state.State;
                    unitJson.State      = customState.ButtonText;
                    unitJson.StateColor = customState.ButtonColor;
                    unitJson.TextColor  = customState.TextColor;
                    unitJson.Timestamp  = state.Timestamp.TimeConverterToString(department);
                }

                unitsJson.Add(unitJson);
            }

            return(Json(unitsJson));
        }
Ejemplo n.º 3
0
        public IActionResult GetUnitsForCallGrid(string callLat, string callLong)
        {
            List <UnitForListJson> unitsJson = new List <UnitForListJson>();

            var units      = _unitsService.GetUnitsForDepartment(DepartmentId);
            var states     = _unitsService.GetAllLatestStatusForUnitsByDepartmentId(DepartmentId);
            var department = _departmentsService.GetDepartmentById(DepartmentId, false);

            foreach (var unit in units)
            {
                var unitJson = new UnitForListJson();
                unitJson.Name   = unit.Name;
                unitJson.Type   = unit.Type;
                unitJson.UnitId = unit.UnitId;

                if (unit.StationGroup != null)
                {
                    unitJson.Station = unit.StationGroup.Name;
                }

                var state = states.FirstOrDefault(x => x.UnitId == unit.UnitId);

                if (state != null)
                {
                    var customState = CustomStatesHelper.GetCustomUnitState(state);

                    unitJson.StateId    = state.State;
                    unitJson.State      = customState.ButtonText;
                    unitJson.StateColor = customState.ButtonColor;
                    unitJson.TextColor  = customState.TextColor;
                    unitJson.Timestamp  = state.Timestamp.TimeConverterToString(department);


                    if (String.IsNullOrWhiteSpace(callLat) || String.IsNullOrWhiteSpace(callLong))
                    {
                        unitJson.Eta = "N/A";
                    }
                    else
                    {
                        var location = _unitsService.GetLatestUnitLocation(state.UnitId, state.Timestamp);

                        if (location != null)
                        {
                            var eta = _geoService.GetEtaInSeconds($"{location.Latitude},{location.Longitude}", String.Format("{0},{1}", callLat, callLong));

                            if (eta > 0)
                            {
                                unitJson.Eta = $"{Math.Round(eta / 60, MidpointRounding.AwayFromZero)}m";
                            }
                            else
                            {
                                unitJson.Eta = "N/A";
                            }
                        }
                        else if (!String.IsNullOrWhiteSpace(state.GeoLocationData))
                        {
                            var eta = _geoService.GetEtaInSeconds(state.GeoLocationData, String.Format("{0},{1}", callLat, callLong));

                            if (eta > 0)
                            {
                                unitJson.Eta = $"{Math.Round(eta / 60, MidpointRounding.AwayFromZero)}m";
                            }
                            else
                            {
                                unitJson.Eta = "N/A";
                            }
                        }
                        else
                        {
                            unitJson.Eta = "N/A";
                        }
                    }
                }

                unitsJson.Add(unitJson);
            }

            return(Json(unitsJson));
        }