Пример #1
0
        public IActionResult GetInventoryList()
        {
            List <InventoryJson> inventoryJson = new List <InventoryJson>();

            var department = _departmentsService.GetDepartmentById(DepartmentId);
            var items      = _inventoryService.GetAllTransactionsForDepartment(DepartmentId);
            var names      = _departmentsService.GetAllPersonnelNamesForDepartment(DepartmentId);

            //var groups = _departmentGroupsService.GetAllGroupsForDepartment(DepartmentId);

            foreach (var item in items)
            {
                var inventory = new InventoryJson();
                inventory.InventoryId = item.InventoryId;
                inventory.Type        = item.Type.Type;
                inventory.Amount      = item.Amount;
                inventory.Batch       = item.Batch;
                inventory.Timestamp   = item.TimeStamp.FormatForDepartment(department);

                if (item.Unit != null)
                {
                    inventory.Unit = item.Unit.Name;
                }
                else
                {
                    inventory.Unit = "No Unit";
                }

                if (item.Group != null)
                {
                    inventory.Group = item.Group.Name;
                }
                else
                {
                    inventory.Group = "No Group";
                }

                var name = names.FirstOrDefault(x => x.UserId == item.AddedByUserId);

                if (name != null)
                {
                    inventory.UserName = name.Name;
                }
                else
                {
                    inventory.UserName = "******";
                }


                inventoryJson.Add(inventory);
            }

            return(Json(inventoryJson));
        }
Пример #2
0
        public List <UnitDetailResult> GetUnitDetail()
        {
            List <UnitDetailResult> result = new List <UnitDetailResult>();
            var units = _unitsService.GetAllLatestStatusForUnitsByDepartmentId(DepartmentId);
            var names = _departmentsService.GetAllPersonnelNamesForDepartment(DepartmentId);

            foreach (var unit in units)
            {
                var unitResult = new UnitDetailResult();
                unitResult.Roles         = new List <UnitDetailRoleResult>();
                unitResult.Id            = unit.UnitId;
                unitResult.Name          = unit.Unit.Name;
                unitResult.Type          = unit.Unit.Type;
                unitResult.GroupId       = unit.Unit.StationGroupId.GetValueOrDefault();
                unitResult.VIN           = unit.Unit.VIN;
                unitResult.PlateNumber   = unit.Unit.PlateNumber;
                unitResult.Offroad       = unit.Unit.FourWheel.GetValueOrDefault();
                unitResult.SpecialPermit = unit.Unit.SpecialPermit.GetValueOrDefault();
                unitResult.StatusId      = unit.UnitStateId;

                if (unit.Roles != null && unit.Roles.Count() > 0)
                {
                    foreach (var role in unit.Roles)
                    {
                        var roleResult = new UnitDetailRoleResult();
                        roleResult.RoleName = role.Role;
                        roleResult.RoleId   = role.UnitStateRoleId;
                        roleResult.UserId   = role.UserId;

                        var name = names.FirstOrDefault(x => x.UserId == role.UserId);

                        if (name != null)
                        {
                            roleResult.Name = name.Name;
                        }
                        else
                        {
                            roleResult.Name = "Unknown";
                        }

                        unitResult.Roles.Add(roleResult);
                    }
                }

                result.Add(unitResult);
            }

            return(result);
        }
Пример #3
0
        public IActionResult GetMapData(MapSettingsInput input)
        {
            MapDataJson dataJson = new MapDataJson();

            var calls              = _callsService.GetActiveCallsByDepartment(DepartmentId);
            var department         = _departmentsService.GetDepartmentById(DepartmentId, false);
            var stations           = _departmentGroupsService.GetAllStationGroupsForDepartment(DepartmentId);
            var lastUserActionlogs = _actionLogsService.GetActionLogsForDepartment(DepartmentId);
            var personnelNames     = _departmentsService.GetAllPersonnelNamesForDepartment(DepartmentId);
            var unitStates         = _unitsService.GetAllLatestStatusForUnitsByDepartmentId(DepartmentId);

            var userLocationPermission = _permissionsService.GetPermisionByDepartmentType(DepartmentId, PermissionTypes.CanSeePersonnelLocations);

            if (userLocationPermission != null)
            {
                var userGroup = _departmentGroupsService.GetGroupForUser(UserId, DepartmentId);
                int?groupId   = null;

                if (userGroup != null)
                {
                    groupId = userGroup.DepartmentGroupId;
                }

                var roles        = _personnelRolesService.GetRolesForUser(UserId, DepartmentId);
                var allowedUsers = _permissionsService.GetAllowedUsers(userLocationPermission, DepartmentId, groupId, ClaimsAuthorizationHelper.IsUserDepartmentAdmin(), ClaimsAuthorizationHelper.IsUserDepartmentAdmin(), roles);

                lastUserActionlogs.RemoveAll(x => !allowedUsers.Contains(x.UserId));
            }

            if (input.ShowDistricts)
            {
                foreach (var station in stations)
                {
                    if (!String.IsNullOrWhiteSpace(station.Geofence))
                    {
                        GeofenceJson geofence = new GeofenceJson();
                        geofence.Name  = station.Name;
                        geofence.Color = station.GeofenceColor;
                        geofence.Fence = station.Geofence;

                        dataJson.Geofences.Add(geofence);
                    }
                }
            }

            if (input.ShowStations)
            {
                foreach (var station in stations)
                {
                    MapMakerInfo info = new MapMakerInfo();
                    info.ImagePath         = "Station";
                    info.Title             = station.Name;
                    info.InfoWindowContent = station.Name;

                    if (station.Address != null)
                    {
                        string coordinates =
                            _geoLocationProvider.GetLatLonFromAddress(string.Format("{0} {1} {2} {3}", station.Address.Address1,
                                                                                    station.Address.City,
                                                                                    station.Address.State,
                                                                                    station.Address.PostalCode));

                        if (!String.IsNullOrEmpty(coordinates))
                        {
                            info.Latitude  = double.Parse(coordinates.Split(char.Parse(","))[0]);
                            info.Longitude = double.Parse(coordinates.Split(char.Parse(","))[1]);

                            dataJson.Markers.Add(info);
                        }
                    }
                    else if (!String.IsNullOrWhiteSpace(station.Latitude) && !String.IsNullOrWhiteSpace(station.Longitude))
                    {
                        info.Latitude  = double.Parse(station.Latitude);
                        info.Longitude = double.Parse(station.Longitude);

                        dataJson.Markers.Add(info);
                    }
                }
            }

            if (input.ShowCalls)
            {
                foreach (var call in calls)
                {
                    MapMakerInfo info = new MapMakerInfo();
                    info.ImagePath         = "Call";
                    info.Title             = call.Name;
                    info.InfoWindowContent = call.NatureOfCall;

                    if (!String.IsNullOrEmpty(call.GeoLocationData))
                    {
                        try
                        {
                            info.Latitude  = double.Parse(call.GeoLocationData.Split(char.Parse(","))[0]);
                            info.Longitude = double.Parse(call.GeoLocationData.Split(char.Parse(","))[1]);

                            dataJson.Markers.Add(info);
                        }
                        catch
                        {
                        }
                    }
                    else if (!String.IsNullOrEmpty(call.Address))
                    {
                        string coordinates = _geoLocationProvider.GetLatLonFromAddress(call.Address);
                        if (!String.IsNullOrEmpty(coordinates))
                        {
                            info.Latitude  = double.Parse(coordinates.Split(char.Parse(","))[0]);
                            info.Longitude = double.Parse(coordinates.Split(char.Parse(","))[1]);
                        }

                        dataJson.Markers.Add(info);
                    }
                }
            }

            if (input.ShowUnits)
            {
                foreach (var unit in unitStates)
                {
                    if (unit.Latitude.HasValue && unit.Latitude.Value != 0 && unit.Longitude.HasValue &&
                        unit.Longitude.Value != 0)
                    {
                        MapMakerInfo info = new MapMakerInfo();
                        info.ImagePath         = "Engine_Responding";
                        info.Title             = unit.Unit.Name;
                        info.InfoWindowContent = "";
                        info.Latitude          = double.Parse(unit.Latitude.Value.ToString());
                        info.Longitude         = double.Parse(unit.Longitude.Value.ToString());

                        dataJson.Markers.Add(info);
                    }
                }
            }

            if (input.ShowPersonnel)
            {
                foreach (var person in lastUserActionlogs)
                {
                    if (!String.IsNullOrWhiteSpace(person.GeoLocationData))
                    {
                        MapMakerInfo info = new MapMakerInfo();
                        info.ImagePath = "Person";

                        var name = personnelNames.FirstOrDefault(x => x.UserId == person.UserId);
                        if (name != null)
                        {
                            info.Title             = name.Name;
                            info.InfoWindowContent = "";
                        }
                        else
                        {
                            info.Title             = "";
                            info.InfoWindowContent = "";
                        }

                        var infos = person.GeoLocationData.Split(char.Parse(","));
                        if (infos != null && infos.Length == 2)
                        {
                            info.Latitude  = double.Parse(infos[0]);
                            info.Longitude = double.Parse(infos[1]);

                            dataJson.Markers.Add(info);
                        }
                    }
                }
            }

            if (input.ShowPOIs)
            {
                var poiTypes = _mappingService.GetPOITypesForDepartment(DepartmentId);

                foreach (var poiType in poiTypes)
                {
                    foreach (var poi in poiType.Pois)
                    {
                        MapMakerInfo info = new MapMakerInfo();
                        info.ImagePath         = poiType.Image;
                        info.Marker            = poiType.Marker;
                        info.Title             = poiType.Name;
                        info.InfoWindowContent = "";
                        info.Latitude          = poi.Latitude;
                        info.Longitude         = poi.Longitude;
                        info.Color             = poiType.Color;

                        dataJson.Pois.Add(info);
                    }
                }
            }

            return(Json(dataJson));
        }
Пример #4
0
        public List <PersonnelViewModel> GetPersonnelStatuses()
        {
            var department         = _departmentsService.GetDepartmentById(DepartmentId, false);
            var stations           = _departmentGroupsService.GetAllStationGroupsForDepartment(DepartmentId);
            var calls              = _callsService.GetActiveCallsByDepartment(DepartmentId);
            var allUsers           = _departmentsService.GetAllUsersForDepartment(DepartmentId);
            var hideUnavailable    = _departmentSettingsService.GetBigBoardHideUnavailableDepartment(DepartmentId);
            var lastUserActionlogs = _actionLogsService.GetActionLogsForDepartment(DepartmentId);
            //var departmentGroups = _departmentGroupsService.GetAllGroupsForDepartment(DepartmentId);

            var lastUserStates = _userStateService.GetLatestStatesForDepartment(DepartmentId);
            var personnelNames = _departmentsService.GetAllPersonnelNamesForDepartment(DepartmentId);

            var names = new Dictionary <string, string>();

            var userStates = new List <UserState>();

            foreach (var u in allUsers)
            {
                var state = lastUserStates.FirstOrDefault(x => x.UserId == u.UserId);

                if (state != null)
                {
                    userStates.Add(state);
                }
                else
                {
                    userStates.Add(_userStateService.GetLastUserStateByUserId(u.UserId));
                }

                var name = personnelNames.FirstOrDefault(x => x.UserId == u.UserId);
                if (name != null)
                {
                    names.Add(u.UserId, name.Name);
                }
            }

            var personnelViewModels = new List <PersonnelViewModel>();

            var sortedUngroupedUsers = from u in allUsers
                                       // let mu = Membership.GetUser(u.UserId)
                                       let userGroup = _departmentGroupsService.GetGroupForUser(u.UserId, DepartmentId)
                                                       let groupName                         = userGroup == null ? "" : userGroup.Name
                                                                                   let roles = _personnelRolesService.GetRolesForUser(u.UserId, DepartmentId)
                                                                                               //let name = (ProfileBase.Create(mu.UserName, true)).GetPropertyValue("Name").ToString()
                                                                                               let name = names[u.UserId]
                                                                                                          let weight = lastUserActionlogs.Where(x => x.UserId == u.UserId).FirstOrDefault().GetWeightForAction()
                                                                                                                       orderby groupName, weight, name ascending
                select new
            {
                Name  = name,
                User  = u,
                Group = userGroup,
                Roles = roles
            };

            foreach (var u in sortedUngroupedUsers)
            {
                //var mu = Membership.GetUser(u.User.UserId);
                var al = lastUserActionlogs.Where(x => x.UserId == u.User.UserId).FirstOrDefault();
                var us = userStates.Where(x => x.UserId == u.User.UserId).FirstOrDefault();

                // if setting is such, ignore unavailable users.
                if (hideUnavailable.HasValue && hideUnavailable.Value && us.State != (int)UserStateTypes.Unavailable)
                {
                    continue;
                }

                string callNumber = "";
                if (al != null && al.ActionTypeId == (int)ActionTypes.RespondingToScene ||
                    (al != null && al.DestinationType.HasValue && al.DestinationType.Value == 2))
                {
                    if (al.DestinationId.HasValue)
                    {
                        var call = calls.FirstOrDefault(x => x.CallId == al.DestinationId.Value);

                        if (call != null)
                        {
                            callNumber = call.Number;
                        }
                    }
                }
                var respondingToDepartment =
                    stations.Where(s => al != null && s.DepartmentGroupId == al.DestinationId).FirstOrDefault();
                var personnelViewModel = PersonnelViewModel.Create(u.Name, al, us, department, respondingToDepartment, u.Group,
                                                                   u.Roles, callNumber);

                personnelViewModels.Add(personnelViewModel);
            }

            return(personnelViewModels);
        }
Пример #5
0
        public async Task <IActionResult> Settings()
        {
            var model = new OrderSetttingsView();

            var department = _departmentsService.GetDepartmentById(DepartmentId);
            var settings   = await _resourceOrdersService.GetSettingsByDepartmentId(DepartmentId);

            if (settings != null)
            {
                model.Settings = settings;
            }
            else
            {
                model.Settings = new ResourceOrderSetting();
                model.Settings.DefaultResourceOrderManagerUserId = department.ManagingUserId;
                model.Settings.Range = 500;
            }

            model.OrderVisibilities = model.Visibility.ToSelectListInt();

            var staffingLevels = _customStateService.GetActiveStaffingLevelsForDepartment(DepartmentId);

            if (staffingLevels == null)
            {
                model.StaffingLevels = model.UserStateTypes.ToSelectListInt();
            }
            else
            {
                model.StaffingLevels = new SelectList(staffingLevels.GetActiveDetails(), "CustomStateDetailId", "ButtonText");
            }

            model.SetUsers(_departmentsService.GetAllUsersForDepartment(DepartmentId, false, true), _departmentsService.GetAllPersonnelNamesForDepartment(DepartmentId));
            ViewBag.Users = new SelectList(model.Users, "Key", "Value");

            return(View(model));
        }
Пример #6
0
        public IActionResult GetPersonnelList(int linkId)
        {
            var link = _departmentLinksService.GetLinkById(linkId);

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

            var department         = _departmentsService.GetDepartmentById(link.DepartmentId);
            var allUsers           = _departmentsService.GetAllUsersForDepartment(link.DepartmentId);
            var lastUserActionlogs = _actionLogsService.GetActionLogsForDepartment(link.DepartmentId);
            var departmentGroups   = _departmentGroupsService.GetAllGroupsForDepartment(link.DepartmentId);

            var lastUserStates = _userStateService.GetLatestStatesForDepartment(link.DepartmentId);
            var personnelNames = _departmentsService.GetAllPersonnelNamesForDepartment(link.DepartmentId);

            var calls    = _callsService.GetActiveCallsByDepartment(link.DepartmentId);
            var stations = _departmentGroupsService.GetAllStationGroupsForDepartment(link.DepartmentId);

            var names = new Dictionary <string, string>();

            var userStates = new List <UserState>();

            foreach (var u in allUsers)
            {
                var state = lastUserStates.FirstOrDefault(x => x.UserId == u.UserId);

                if (state != null)
                {
                    userStates.Add(state);
                }
                else
                {
                    userStates.Add(_userStateService.GetLastUserStateByUserId(u.UserId));
                }

                var name = personnelNames.FirstOrDefault(x => x.UserId == u.UserId);
                if (name != null)
                {
                    names.Add(u.UserId, name.Name);
                }
                else
                {
                    names.Add(u.UserId, UserHelper.GetFullNameForUser(u.UserId));
                }
            }

            var personnelViewModels = new List <Models.BigBoardX.PersonnelViewModel>();

            var sortedUngroupedUsers = from u in allUsers
                                       // let mu = Membership.GetUser(u.UserId)
                                       let userGroup = _departmentGroupsService.GetGroupForUser(u.UserId, DepartmentId)
                                                       let groupName                         = userGroup == null ? "" : userGroup.Name
                                                                                   let roles = _personnelRolesService.GetRolesForUser(u.UserId, DepartmentId)
                                                                                               //let name = (ProfileBase.Create(mu.UserName, true)).GetPropertyValue("Name").ToString()
                                                                                               let name = names[u.UserId]
                                                                                                          let weight = lastUserActionlogs.Where(x => x.UserId == u.UserId).FirstOrDefault().GetWeightForAction()
                                                                                                                       orderby groupName, weight, name ascending
                select new
            {
                Name  = name,
                User  = u,
                Group = userGroup,
                Roles = roles
            };

            foreach (var u in sortedUngroupedUsers)
            {
                //var mu = Membership.GetUser(u.User.UserId);
                var al = lastUserActionlogs.Where(x => x.UserId == u.User.UserId).FirstOrDefault();
                var us = userStates.Where(x => x.UserId == u.User.UserId).FirstOrDefault();

                string callNumber = "";
                if (al != null && al.ActionTypeId == (int)ActionTypes.RespondingToScene || (al != null && al.DestinationType.HasValue && al.DestinationType.Value == 2))
                {
                    if (al.DestinationId.HasValue)
                    {
                        var call = calls.FirstOrDefault(x => x.CallId == al.DestinationId.Value);

                        if (call != null)
                        {
                            callNumber = call.Number;
                        }
                    }
                }
                var respondingToDepartment = stations.Where(s => al != null && s.DepartmentGroupId == al.DestinationId).FirstOrDefault();
                var personnelViewModel     = Models.BigBoardX.PersonnelViewModel.Create(u.Name, al, us, department, respondingToDepartment, u.Group, u.Roles, callNumber);

                personnelViewModels.Add(personnelViewModel);
            }

            return(Json(personnelViewModels));
        }