Ejemplo n.º 1
0
        public IActionResult GenerateReport(IFormCollection form)
        {
            var eventIds = new List <int>();

            foreach (var key in form.Keys)
            {
                if (key.ToString().StartsWith("selectEvent_"))
                {
                    var eventId = int.Parse(key.ToString().Replace("selectEvent_", ""));
                    eventIds.Add(eventId);
                }
            }

            var model = new UnitEventsReportView();

            model.Rows       = new List <UnitEventJson>();
            model.Department = _departmentsService.GetDepartmentById(DepartmentId, false);

            foreach (var eventId in eventIds)
            {
                var eventJson   = new UnitEventJson();
                var eventRecord = _unitsService.GetUnitStateById(eventId);

                model.RunOn = DateTime.UtcNow.TimeConverter(model.Department);

                eventJson.UnitName  = eventRecord.Unit.Name;
                eventJson.State     = StringHelpers.GetDescription(((UnitStateTypes)eventRecord.State));
                eventJson.Timestamp = eventRecord.Timestamp.TimeConverterToString(model.Department).ToString();
                eventJson.Note      = eventRecord.Note;

                if (((UnitStateTypes)eventRecord.State) == UnitStateTypes.Enroute)
                {
                    if (eventRecord.DestinationId.HasValue)
                    {
                        var station = _departmentGroupsService.GetGroupById(eventRecord.DestinationId.Value, false);

                        if (station != null)
                        {
                            eventJson.DestinationName = station.Name;
                        }
                        else
                        {
                            eventJson.DestinationName = "Station";
                        }
                    }
                    else
                    {
                        eventJson.DestinationName = "Station";
                    }
                }
                else if (((UnitStateTypes)eventRecord.State) == UnitStateTypes.Responding || ((UnitStateTypes)eventRecord.State) == UnitStateTypes.Committed ||
                         ((UnitStateTypes)eventRecord.State) == UnitStateTypes.OnScene || ((UnitStateTypes)eventRecord.State) == UnitStateTypes.Staging ||
                         ((UnitStateTypes)eventRecord.State) == UnitStateTypes.Released || ((UnitStateTypes)eventRecord.State) == UnitStateTypes.Cancelled)
                {
                    if (eventRecord.DestinationId.HasValue)
                    {
                        var call = _callsService.GetCallById(eventRecord.DestinationId.Value, false);

                        if (call != null)
                        {
                            eventJson.DestinationName = call.Name;
                        }
                        else
                        {
                            eventJson.DestinationName = "Scene";
                        }
                    }
                }

                if (eventRecord.LocalTimestamp.HasValue)
                {
                    eventJson.LocalTimestamp = eventRecord.LocalTimestamp.Value.ToString();
                }

                if (eventRecord.Latitude.HasValue)
                {
                    eventJson.Latitude = eventRecord.Latitude.Value.ToString();
                }

                if (eventRecord.Longitude.HasValue)
                {
                    eventJson.Longitude = eventRecord.Longitude.Value.ToString();
                }

                model.Rows.Add(eventJson);
            }

            return(View("~/Areas/User/Views/Reports/UnitEventsReport.cshtml", model));
        }
Ejemplo n.º 2
0
        public int GetDepartmentIdForType(NotificationItem ni)
        {
            switch ((EventTypes)ni.Type)
            {
            case EventTypes.PersonnelStaffingChanged:
                var state = _userStateService.GetUserStateById(ni.StateId);

                if (state != null)
                {
                    var department = _departmentsService.GetDepartmentByUserId(state.UserId, true);

                    if (department != null)
                    {
                        return(department.DepartmentId);
                    }
                    else
                    {
                        return(0);
                    }
                }
                else
                {
                    return(0);
                }

            case EventTypes.PersonnelStatusChanged:
                var status = _actionLogsService.GetActionlogById(ni.StateId);

                if (status != null)
                {
                    var department = _departmentsService.GetDepartmentByUserId(status.UserId, true);

                    if (department != null)
                    {
                        return(department.DepartmentId);
                    }
                    else
                    {
                        return(0);
                    }
                }
                else
                {
                    return(0);
                }

            case EventTypes.CalendarEventAdded:
                var cal = _calendarService.GetCalendarItemById(ni.ItemId);

                if (cal != null)
                {
                    return(cal.DepartmentId);
                }
                else
                {
                    return(0);
                }

            case EventTypes.CalendarEventUpcoming:
                var calUp = _calendarService.GetCalendarItemById(ni.ItemId);

                if (calUp != null)
                {
                    return(calUp.DepartmentId);
                }
                else
                {
                    return(0);
                }

            case EventTypes.CalendarEventUpdated:
                var calUpdate = _calendarService.GetCalendarItemById(ni.ItemId);

                if (calUpdate != null)
                {
                    return(calUpdate.DepartmentId);
                }
                else
                {
                    return(0);
                }

            case EventTypes.DocumentAdded:
                var docAdded = _documentsService.GetDocumentById(ni.ItemId);

                if (docAdded != null)
                {
                    return(docAdded.DepartmentId);
                }
                else
                {
                    return(0);
                }

            case EventTypes.LogAdded:
                var logAdded = _workLogsService.GetWorkLogById(ni.ItemId);

                if (logAdded != null)
                {
                    return(logAdded.DepartmentId);
                }
                else
                {
                    return(0);
                }

            case EventTypes.NoteAdded:
                var noteAdded = _notesService.GetNoteById(ni.ItemId);

                if (noteAdded != null)
                {
                    return(noteAdded.DepartmentId);
                }
                else
                {
                    return(0);
                }

            case EventTypes.ShiftCreated:
                var shiftCreated = _shiftsService.GetShiftById(ni.ItemId);

                if (shiftCreated != null)
                {
                    return(shiftCreated.DepartmentId);
                }
                else
                {
                    return(0);
                }

            case EventTypes.ShiftDaysAdded:
                var shiftDaysAdded = _shiftsService.GetShiftById(ni.ItemId);

                if (shiftDaysAdded != null)
                {
                    return(shiftDaysAdded.DepartmentId);
                }
                else
                {
                    return(0);
                }

            case EventTypes.ShiftUpdated:
                var shiftUpdated = _shiftsService.GetShiftById(ni.ItemId);

                if (shiftUpdated != null)
                {
                    return(shiftUpdated.DepartmentId);
                }
                else
                {
                    return(0);
                }

            case EventTypes.UnitAdded:
                var unitAdded = _unitsService.GetUnitById(ni.UnitId);

                if (unitAdded != null)
                {
                    return(unitAdded.DepartmentId);
                }
                else
                {
                    return(0);
                }

            case EventTypes.UnitStatusChanged:
                var unitStatusChanged = _unitsService.GetUnitStateById(ni.StateId);

                if (unitStatusChanged != null)
                {
                    var unit = _unitsService.GetUnitById(unitStatusChanged.UnitId);

                    if (unit != null)
                    {
                        return(unit.DepartmentId);
                    }
                    else
                    {
                        return(0);
                    }
                }
                else
                {
                    return(0);
                }
            }

            return(0);
        }