Пример #1
0
        public async Task <IActionResult> Index()
        {
            var model = new UnitsIndexView();

            model.Department = await _departmentsService.GetDepartmentByIdAsync(DepartmentId);

            model.CanUserAddUnit = await _limitsService.CanDepartmentAddNewUnit(DepartmentId);

            model.Groups = await _departmentGroupsService.GetAllGroupsForDepartmentAsync(DepartmentId);

            model.Units = await _unitsService.GetUnitsForDepartmentAsync(DepartmentId);

            model.States = await _unitsService.GetAllLatestStatusForUnitsByDepartmentIdAsync(DepartmentId);

            model.UnitStatuses = await _customStateService.GetAllActiveUnitStatesForDepartmentAsync(DepartmentId);

            model.UnitCustomStates = new Dictionary <int, CustomState>();

            foreach (var unit in model.Units)
            {
                var type = await _unitsService.GetUnitTypeByNameAsync(DepartmentId, unit.Type);

                if (type != null && type.CustomStatesId.HasValue)
                {
                    var customStates = await _customStateService.GetCustomSateByIdAsync(type.CustomStatesId.Value);

                    if (customStates != null)
                    {
                        model.UnitCustomStates.Add(unit.UnitId, customStates);
                    }
                }
            }

            return(View(model));
        }
Пример #2
0
        public async Task <IActionResult> GetDepartmentEnitites()
        {
            List <DepartmentEntitiesJson> items = new List <DepartmentEntitiesJson>();

            var department = await _departmentsService.GetDepartmentByIdAsync(DepartmentId);

            var groups = await _departmentGroupsService.GetAllGroupsForDepartmentAsync(DepartmentId);

            items.Add(new DepartmentEntitiesJson()
            {
                Id   = $"D:{DepartmentId}",
                Type = -1,
                Name = department.Name
            });

            foreach (var group in groups)
            {
                items.Add(new DepartmentEntitiesJson()
                {
                    Id   = $"G:{group.DepartmentGroupId}",
                    Type = group.Type.GetValueOrDefault(),
                    Name = group.Name
                });
            }

            return(Json(items));
        }
Пример #3
0
        private async Task <List <FilterResult> > GetFilterOptions()
        {
            var result = new List <FilterResult>();

            var stations = await _departmentGroupsService.GetAllGroupsForDepartmentAsync(DepartmentId);

            Parallel.ForEach(stations, s =>
            {
                var respondingTo  = new FilterResult();
                respondingTo.Id   = string.Format("G:{0}", s.DepartmentGroupId);
                respondingTo.Type = "Group";
                respondingTo.Name = s.Name;

                result.Add(respondingTo);
            });

            return(result);
        }
Пример #4
0
        /// <summary>
        /// Adds a new call into Resgrid and Dispatches the call
        /// </summary>
        /// <param name="callInput">Call data to add into the system</param>
        /// <returns></returns>
        public async Task <AddCallInput> AddCall([FromBody] AddCallInput callInput)
        {
            try
            {
                var call = new Call
                {
                    DepartmentId     = DepartmentId,
                    ReportingUserId  = UserId,
                    Priority         = callInput.Priority,
                    Name             = callInput.Name,
                    NatureOfCall     = callInput.NatureOfCall,
                    Number           = callInput.Number,
                    IsCritical       = callInput.IsCritical,
                    IncidentNumber   = callInput.IncidentNumber,
                    MapPage          = callInput.MapPage,
                    Notes            = callInput.Notes,
                    CompletedNotes   = callInput.CompletedNotes,
                    Address          = callInput.Address,
                    GeoLocationData  = callInput.GeoLocationData,
                    LoggedOn         = callInput.LoggedOn,
                    ClosedByUserId   = callInput.ClosedByUserId,
                    ClosedOn         = callInput.ClosedOn,
                    State            = callInput.State,
                    IsDeleted        = callInput.IsDeleted,
                    CallSource       = callInput.CallSource,
                    DispatchCount    = callInput.DispatchCount,
                    LastDispatchedOn = callInput.LastDispatchedOn,
                    SourceIdentifier = callInput.SourceIdentifier,
                    W3W                = callInput.W3W,
                    ContactName        = callInput.ContactName,
                    ContactNumber      = callInput.ContactNumber,
                    Public             = callInput.Public,
                    ExternalIdentifier = callInput.ExternalIdentifier,
                    ReferenceNumber    = callInput.ReferenceNumber
                };

                if (string.IsNullOrWhiteSpace(call.GeoLocationData) && !string.IsNullOrWhiteSpace(call.Address))
                {
                    call.GeoLocationData = _geoLocationProvider.GetLatLonFromAddress(call.Address);
                }

                if (string.IsNullOrWhiteSpace(call.GeoLocationData) && !string.IsNullOrWhiteSpace(call.W3W))
                {
                    var coords = await _geoLocationProvider.GetCoordinatesFromW3WAsync(call.W3W);

                    if (coords != null)
                    {
                        call.GeoLocationData = $"{coords.Latitude},{coords.Longitude}";
                    }
                }

                call.LoggedOn = DateTime.UtcNow;

                if (!String.IsNullOrWhiteSpace(callInput.Type) && callInput.Type != "No Type")
                {
                    var callTypes = await _callsService.GetCallTypesForDepartmentAsync(DepartmentId);

                    var type = callTypes.FirstOrDefault(x => x.Type == callInput.Type);

                    if (type != null)
                    {
                        call.Type = type.Type;
                    }
                }

                call.Dispatches      = new List <CallDispatch>();
                call.GroupDispatches = new List <CallDispatchGroup>();
                call.RoleDispatches  = new List <CallDispatchRole>();

                List <string> groupUserIds = new List <string>();

                var users = await _departmentsService.GetAllUsersForDepartmentAsync(DepartmentId);

                if (callInput.AllCall)
                {
                    foreach (var u in users)
                    {
                        var cd = new CallDispatch {
                            UserId = u.UserId
                        };

                        call.Dispatches.Add(cd);
                    }
                }
                else
                {
                    if (callInput.GroupCodesToDispatch != null && callInput.GroupCodesToDispatch.Count > 0)
                    {
                        var allGroups = await _departmentGroupsService.GetAllGroupsForDepartmentAsync(DepartmentId);

                        foreach (var groupCode in callInput.GroupCodesToDispatch)
                        {
                            var groupsToDispatch = allGroups.FirstOrDefault(x => x.DispatchEmail == groupCode);

                            if (groupsToDispatch != null)
                            {
                                var cd = new CallDispatchGroup {
                                    DepartmentGroupId = groupsToDispatch.DepartmentGroupId
                                };
                                call.GroupDispatches.Add(cd);

                                if (groupsToDispatch.Members != null && groupsToDispatch.Members.Any())
                                {
                                    foreach (var departmentGroupMember in groupsToDispatch.Members)
                                    {
                                        if (!groupUserIds.Contains(departmentGroupMember.UserId))
                                        {
                                            groupUserIds.Add(departmentGroupMember.UserId);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                if (callInput.Attachments != null && callInput.Attachments.Any())
                {
                    call.Attachments = new List <CallAttachment>();

                    foreach (var attachment in callInput.Attachments)
                    {
                        var newAttachment = new CallAttachment();
                        newAttachment.Data               = attachment.Data;
                        newAttachment.Timestamp          = DateTime.UtcNow;
                        newAttachment.FileName           = attachment.FileName;
                        newAttachment.Size               = attachment.Size;
                        newAttachment.CallAttachmentType = attachment.CallAttachmentType;

                        call.Attachments.Add(newAttachment);
                    }
                }

                var savedCall = _callsService.SaveCall(call);


                OutboundEventProvider.CallAddedTopicHandler handler = new OutboundEventProvider.CallAddedTopicHandler();
                handler.Handle(new CallAddedEvent()
                {
                    DepartmentId = DepartmentId, Call = savedCall
                });

                var cqi = new CallQueueItem();
                cqi.Call = savedCall;

                if (cqi.Call.Dispatches != null && cqi.Call.Dispatches.Any())
                {
                    cqi.Profiles =
                        await _userProfileService.GetSelectedUserProfilesAsync(cqi.Call.Dispatches.Select(x => x.UserId).ToList());
                }
                else
                {
                    if (groupUserIds.Any())
                    {
                        cqi.Profiles = await _userProfileService.GetSelectedUserProfilesAsync(groupUserIds);
                    }
                }

                _queueService.EnqueueCallBroadcast(cqi);

                callInput.CallId = savedCall.CallId;
                callInput.Number = savedCall.Number;
            }
            catch (Exception ex)
            {
                Logging.LogException(ex);

                throw ex;
            }

            return(callInput);
        }
Пример #5
0
        public async Task <ActionResult <List <PersonnelViewModel> > > GetPersonnelStatuses()
        {
            var department = await _departmentsService.GetDepartmentByIdAsync(DepartmentId, false);

            var stations = await _departmentGroupsService.GetAllStationGroupsForDepartmentAsync(DepartmentId);

            var calls = await _callsService.GetActiveCallsByDepartmentAsync(DepartmentId);

            var allUsers = await _departmentsService.GetAllUsersForDepartmentAsync(DepartmentId);

            var hideUnavailable = await _departmentSettingsService.GetBigBoardHideUnavailableDepartmentAsync(DepartmentId);

            //var lastUserActionlogs = await _actionLogsService.GetAllActionLogsForDepartmentAsync(DepartmentId);
            var lastUserActionlogs = await _actionLogsService.GetLastActionLogsForDepartmentAsync(DepartmentId);

            var departmentGroups = await _departmentGroupsService.GetAllGroupsForDepartmentAsync(DepartmentId);

            var lastUserStates = await _userStateService.GetLatestStatesForDepartmentAsync(DepartmentId);

            var personnelNames = await _departmentsService.GetAllPersonnelNamesForDepartmentAsync(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(await _userStateService.GetLastUserStateByUserIdAsync(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 = departmentGroups.FirstOrDefault(x => x.Members.Any(y => y.UserId == u.UserId))
                                                       let groupName = userGroup == null ? "" : userGroup.Name
                                                                       //let roles = _personnelRolesService.GetRolesForUserAsync(u.UserId, DepartmentId).Result
                                                                       //let name = (ProfileBase.Create(mu.UserName, true)).GetPropertyValue("Name").ToString()
                                                                       let name = names.ContainsKey(u.UserId) ? names[u.UserId] : "Unknown User"
                                                                                  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 = new List <PersonnelRole>()
            };

            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;
                }

                u.Roles.AddRange(await _personnelRolesService.GetRolesForUserAsync(u.User.UserId, DepartmentId));

                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 = await PersonnelViewModel.Create(u.Name, al, us, department, respondingToDepartment, u.Group,
                                                                         u.Roles, callNumber);

                personnelViewModels.Add(personnelViewModel);
            }

            return(personnelViewModels);
        }
Пример #6
0
        public async Task <ActionResult <UnitAppPayloadResult> > GetCommandAppCoreData()
        {
            var results = new UnitAppPayloadResult();

            results.Personnel    = new List <PersonnelInfoResult>();
            results.Groups       = new List <GroupInfoResult>();
            results.Units        = new List <UnitInfoResult>();
            results.Roles        = new List <RoleInfoResult>();
            results.Statuses     = new List <CustomStatusesResult>();
            results.Calls        = new List <CallResultEx>();
            results.UnitStatuses = new List <UnitStatusCoreResult>();
            results.UnitRoles    = new List <UnitRoleResult>();

            var users = await _departmentsService.GetAllUsersForDepartmentAsync(DepartmentId);

            var groups = await _departmentGroupsService.GetAllDepartmentGroupsForDepartmentAsync(DepartmentId);

            var rolesForUsersInDepartment = await _personnelRolesService.GetAllRolesForUsersInDepartmentAsync(DepartmentId);

            var allRoles = await _personnelRolesService.GetRolesForDepartmentAsync(DepartmentId);

            var allProfiles = await _userProfileService.GetAllProfilesForDepartmentAsync(DepartmentId);

            var allGroups = await _departmentGroupsService.GetAllGroupsForDepartmentAsync(DepartmentId);

            var units = await _unitsService.GetUnitsForDepartmentAsync(DepartmentId);

            var unitTypes = await _unitsService.GetUnitTypesForDepartmentAsync(DepartmentId);


            foreach (var user in users)
            {
                //var profile = _userProfileService.GetProfileByUserId(user.UserId);
                //var group = _departmentGroupsService.GetGroupForUser(user.UserId);

                UserProfile profile = null;
                if (allProfiles.ContainsKey(user.UserId))
                {
                    profile = allProfiles[user.UserId];
                }

                DepartmentGroup group = null;
                if (groups.ContainsKey(user.UserId))
                {
                    group = groups[user.UserId];
                }

                //var roles = _personnelRolesService.GetRolesForUser(user.UserId);

                List <PersonnelRole> roles = null;
                if (rolesForUsersInDepartment.ContainsKey(user.UserId))
                {
                    roles = rolesForUsersInDepartment[user.UserId];
                }

                var result = new PersonnelInfoResult();

                if (profile != null)
                {
                    result.Fnm = profile.FirstName;
                    result.Lnm = profile.LastName;
                    result.Id  = profile.IdentificationNumber;
                    result.Mnu = profile.MobileNumber;
                }
                else
                {
                    result.Fnm = "Unknown";
                    result.Lnm = "Check Profile";
                    result.Id  = "";
                    result.Mnu = "";
                }

                result.Eml = user.Email;
                result.Did = DepartmentId;
                result.Uid = user.UserId.ToString();

                if (group != null)
                {
                    result.Gid = group.DepartmentGroupId;
                    result.Gnm = group.Name;
                }

                result.Roles = new List <string>();
                if (roles != null && roles.Count > 0)
                {
                    foreach (var role in roles)
                    {
                        if (role != null)
                        {
                            result.Roles.Add(role.Name);
                        }
                    }
                }

                results.Personnel.Add(result);
            }


            results.Rights = new DepartmentRightsResult();
            var currentUser = await _usersService.GetUserByNameAsync(UserName);

            if (currentUser == null)
            {
                return(Unauthorized());
            }

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

            results.Rights.Adm  = department.IsUserAnAdmin(currentUser.UserId);
            results.Rights.Grps = new List <GroupRight>();

            var currentGroup = await _departmentGroupsService.GetGroupForUserAsync(currentUser.UserId, DepartmentId);

            if (currentGroup != null)
            {
                var groupRight = new GroupRight();
                groupRight.Gid = currentGroup.DepartmentGroupId;
                groupRight.Adm = currentGroup.IsUserGroupAdmin(currentUser.UserId);

                results.Rights.Grps.Add(groupRight);
            }

            foreach (var group in allGroups)
            {
                var groupInfo = new GroupInfoResult();
                groupInfo.Gid = group.DepartmentGroupId;
                groupInfo.Nme = group.Name;

                if (group.Type.HasValue)
                {
                    groupInfo.Typ = group.Type.Value;
                }

                if (group.Address != null)
                {
                    groupInfo.Add = group.Address.FormatAddress();
                }

                results.Groups.Add(groupInfo);
            }

            foreach (var unit in units)
            {
                var unitResult = new UnitInfoResult();
                unitResult.Uid = unit.UnitId;
                unitResult.Did = DepartmentId;
                unitResult.Nme = unit.Name;
                unitResult.Typ = unit.Type;

                if (!string.IsNullOrWhiteSpace(unit.Type))
                {
                    var unitType = unitTypes.FirstOrDefault(x => x.Type == unit.Type);

                    if (unitType != null)
                    {
                        unitResult.Cid = unitType.CustomStatesId.GetValueOrDefault();
                    }
                }
                else
                {
                    unitResult.Cid = 0;
                }

                if (unit.StationGroup != null)
                {
                    unitResult.Sid = unit.StationGroup.DepartmentGroupId;
                    unitResult.Snm = unit.StationGroup.Name;
                }

                results.Units.Add(unitResult);

                // Add unit roles for this unit
                var roles = await _unitsService.GetRolesForUnitAsync(unit.UnitId);

                foreach (var role in roles)
                {
                    var roleResult = new UnitRoleResult();
                    roleResult.Name       = role.Name;
                    roleResult.UnitId     = role.UnitId;
                    roleResult.UnitRoleId = role.UnitRoleId;

                    results.UnitRoles.Add(roleResult);
                }
            }

            var unitStatuses = await _unitsService.GetAllLatestStatusForUnitsByDepartmentIdAsync(DepartmentId);

            foreach (var us in unitStatuses)
            {
                var unitStatus = new UnitStatusCoreResult();
                unitStatus.UnitId      = us.UnitId;
                unitStatus.StateType   = (UnitStateTypes)us.State;
                unitStatus.StateTypeId = us.State;
                unitStatus.Type        = us.Unit.Type;
                unitStatus.Timestamp   = us.Timestamp.TimeConverter(department);
                unitStatus.Name        = us.Unit.Name;

                if (us.DestinationId.HasValue)
                {
                    unitStatus.DestinationId = us.DestinationId.Value;
                }

                results.UnitStatuses.Add(unitStatus);
            }

            foreach (var role in allRoles)
            {
                var roleResult = new RoleInfoResult();
                roleResult.Rid = role.PersonnelRoleId;
                roleResult.Nme = role.Name;

                results.Roles.Add(roleResult);
            }

            var customStates = await _customStateService.GetAllActiveCustomStatesForDepartmentAsync(DepartmentId);

            foreach (var customState in customStates)
            {
                if (customState.IsDeleted)
                {
                    continue;
                }

                foreach (var stateDetail in customState.GetActiveDetails())
                {
                    if (stateDetail.IsDeleted)
                    {
                        continue;
                    }

                    var customStateResult = new CustomStatusesResult();
                    customStateResult.Id      = stateDetail.CustomStateDetailId;
                    customStateResult.Type    = customState.Type;
                    customStateResult.StateId = stateDetail.CustomStateId;
                    customStateResult.Text    = stateDetail.ButtonText;
                    customStateResult.BColor  = stateDetail.ButtonColor;
                    customStateResult.Color   = stateDetail.TextColor;
                    customStateResult.Gps     = stateDetail.GpsRequired;
                    customStateResult.Note    = stateDetail.NoteType;
                    customStateResult.Detail  = stateDetail.DetailType;

                    results.Statuses.Add(customStateResult);
                }
            }

            var calls = (await _callsService.GetActiveCallsByDepartmentAsync(DepartmentId)).OrderByDescending(x => x.LoggedOn);

            if (calls != null && calls.Any())
            {
                foreach (var c in calls)
                {
                    var call = new CallResultEx();

                    call.Cid = c.CallId;
                    call.Pri = c.Priority;
                    call.Ctl = c.IsCritical;
                    call.Nme = c.Name;
                    call.Noc = c.NatureOfCall;
                    call.Map = c.MapPage;
                    call.Not = c.Notes;

                    if (String.IsNullOrWhiteSpace(c.Address) && !String.IsNullOrWhiteSpace(c.GeoLocationData))
                    {
                        var geo = c.GeoLocationData.Split(char.Parse(","));

                        if (geo.Length == 2)
                        {
                            call.Add = await _geoLocationProvider.GetAddressFromLatLong(double.Parse(geo[0]), double.Parse(geo[1]));
                        }
                    }
                    else
                    {
                        call.Add = c.Address;
                    }

                    call.Add = c.Address;
                    call.Geo = c.GeoLocationData;
                    call.Lon = c.LoggedOn.TimeConverter(department);
                    call.Ste = c.State;
                    call.Num = c.Number;

                    results.Calls.Add(call);
                }
            }
            else
            {
                // This is a hack due to a bug in the current units app! -SJ 1-31-2016
                var call = new CallResultEx();
                call.Cid = 0;
                call.Pri = 0;
                call.Ctl = false;
                call.Nme = "No Call";
                call.Noc = "";
                call.Map = "";
                call.Not = "";
                call.Add = "";
                call.Geo = "";
                call.Lon = DateTime.UtcNow;
                call.Ste = 0;
                call.Num = "";

                results.Calls.Add(call);
            }


            return(Ok(results));
        }
Пример #7
0
        public async Task <IActionResult> NewGroup(NewGroupView model, IFormCollection collection, CancellationToken cancellationToken)
        {
            model.Users = await _departmentsService.GetAllUsersForDepartmentAsync(DepartmentId);

            model.Groups = await _departmentGroupsService.GetAllGroupsForDepartmentAsync(DepartmentId);

            var groups = new List <DepartmentGroup>();

            groups.Add(new DepartmentGroup {
                DepartmentGroupId = -1, Name = "None"
            });
            groups.AddRange(model.Groups.Where(x => x.Type.HasValue && x.Type.Value == (int)DepartmentGroupTypes.Station));

            model.StationGroups = new SelectList(groups, "DepartmentGroupId", "Name");

            var groupAdmins = new List <string>();
            var groupUsers  = new List <string>();
            var allUsers    = new List <string>();

            if (collection.ContainsKey("groupAdmins"))
            {
                groupAdmins.AddRange(collection["groupAdmins"].ToString().Split(char.Parse(",")));
            }

            if (collection.ContainsKey("groupUsers"))
            {
                groupUsers.AddRange(collection["groupUsers"].ToString().Split(char.Parse(",")));
            }

            allUsers.AddRange(groupAdmins);
            allUsers.AddRange(groupUsers);

            foreach (var groupUser in allUsers)
            {
                if (await _departmentGroupsService.IsUserInAGroupAsync(groupUser, DepartmentId))
                {
                    var profile = await _userProfileService.GetProfileByUserIdAsync(groupUser);

                    ModelState.AddModelError("", string.Format("{0} Is already in a group. Cannot add to another.", profile.FullName.AsFirstNameLastName));
                }
            }

            if (model.NewGroup.Type.HasValue && model.NewGroup.Type.Value == (int)DepartmentGroupTypes.Station)
            {
                if (String.IsNullOrWhiteSpace(model.What3Word))
                {
                    if (String.IsNullOrEmpty(model.Latitude) && String.IsNullOrEmpty(model.Longitude))
                    {
                        if (String.IsNullOrEmpty(model.Address1))
                        {
                            ModelState.AddModelError("Address1", string.Format("The Address field is required for station groups"));
                        }

                        if (String.IsNullOrEmpty(model.City))
                        {
                            ModelState.AddModelError("City", string.Format("The City field is required for station groups"));
                        }

                        if (String.IsNullOrEmpty(model.Country))
                        {
                            ModelState.AddModelError("Country", string.Format("The Country field is required for station groups"));
                        }

                        if (String.IsNullOrEmpty(model.PostalCode))
                        {
                            ModelState.AddModelError("PostalCode", string.Format("The Postal Code field is required for station groups"));
                        }

                        if (String.IsNullOrEmpty(model.State))
                        {
                            ModelState.AddModelError("State", string.Format("The State field is required for station groups"));
                        }
                    }
                }
                else
                {
                    var result = _geoLocationProvider.GetCoordinatesFromW3W(model.What3Word);

                    if (result == null)
                    {
                        ModelState.AddModelError("What3Word", string.Format("The What3Words address entered was incorrect."));
                    }
                    else
                    {
                        model.Latitude  = result.Latitude.ToString();
                        model.Longitude = result.Longitude.ToString();
                    }
                }
            }

            if (ModelState.IsValid)
            {
                model.NewGroup.DepartmentId = DepartmentId;
                var users = new List <DepartmentGroupMember>();

                foreach (var user in allUsers)
                {
                    if (users.All(x => x.UserId != user))
                    {
                        var dgm = new DepartmentGroupMember();
                        dgm.DepartmentId = DepartmentId;
                        dgm.UserId       = user;

                        if (groupAdmins.Contains(user))
                        {
                            dgm.IsAdmin = true;
                        }

                        users.Add(dgm);
                    }
                }

                if (model.NewGroup.Type.HasValue && model.NewGroup.Type.Value == (int)DepartmentGroupTypes.Station)
                {
                    if (String.IsNullOrEmpty(model.Latitude) && String.IsNullOrEmpty(model.Longitude))
                    {
                        model.NewGroup.Address.Address1   = model.Address1;
                        model.NewGroup.Address.City       = model.City;
                        model.NewGroup.Address.Country    = model.Country;
                        model.NewGroup.Address.PostalCode = model.PostalCode;
                        model.NewGroup.Address.State      = model.State;
                    }
                    else
                    {
                        model.NewGroup.Address   = null;
                        model.NewGroup.Latitude  = model.Latitude;
                        model.NewGroup.Longitude = model.Longitude;
                    }

                    if (!String.IsNullOrWhiteSpace(model.What3Word))
                    {
                        model.NewGroup.What3Words = model.What3Word;
                    }
                }
                else
                {
                    model.NewGroup.Address = null;
                }

                if (model.NewGroup.ParentDepartmentGroupId <= 0)
                {
                    model.NewGroup.ParentDepartmentGroupId = null;
                }

                if (!String.IsNullOrWhiteSpace(model.PrinterApiKey) && !String.IsNullOrWhiteSpace(model.PrinterId))
                {
                    var printer = new DepartmentGroupPrinter();
                    printer.PrinterId   = int.Parse(model.PrinterId);
                    printer.PrinterName = model.PrinterName;
                    printer.ApiKey      = SymmetricEncryption.Encrypt(model.PrinterApiKey, Config.SystemBehaviorConfig.ExternalLinkUrlParamPassphrase);

                    model.NewGroup.DispatchToPrinter = true;
                    model.NewGroup.PrinterData       = JsonConvert.SerializeObject(printer);
                }

                model.NewGroup.Members       = users;
                model.NewGroup.DispatchEmail = RandomGenerator.GenerateRandomString(6, 6, false, true, false, true, true, false, null);
                model.NewGroup.MessageEmail  = RandomGenerator.GenerateRandomString(6, 6, false, true, false, true, true, false, null);

                if (!String.IsNullOrWhiteSpace(model.NewGroup.Latitude))
                {
                    model.NewGroup.Latitude = model.NewGroup.Latitude.Replace(" ", "");
                }

                if (!String.IsNullOrWhiteSpace(model.NewGroup.Longitude))
                {
                    model.NewGroup.Longitude = model.NewGroup.Longitude.Replace(" ", "");
                }

                await _departmentGroupsService.SaveAsync(model.NewGroup, cancellationToken);

                var auditEvent = new AuditEvent();
                auditEvent.DepartmentId = DepartmentId;
                auditEvent.UserId       = UserId;
                auditEvent.Type         = AuditLogTypes.GroupAdded;
                auditEvent.After        = model.NewGroup.CloneJson();
                _eventAggregator.SendMessage <AuditEvent>(auditEvent);

                return(RedirectToAction("Index", "Groups", new { Area = "User" }));
            }

            return(View("NewGroup", model));
        }
Пример #8
0
        public async Task <ActionResult <ResponderChatResult> > GetResponderChatInfo()
        {
            var result = new ResponderChatResult();

            result.UserId = UserId;

            var department = await _departmentsService.GetDepartmentByIdAsync(DepartmentId);

            var groups = await _departmentGroupsService.GetAllGroupsForDepartmentAsync(DepartmentId);

            var departmentGroup = new ResponderChatGroupInfo();

            departmentGroup.Id   = $"{Config.ChatConfig.DepartmentChatPrefix}{department.Code}";
            departmentGroup.Name = department.Name;
            departmentGroup.Type = 1;
            result.Groups.Add(departmentGroup);

            if (department.IsUserAnAdmin(UserId))
            {
                foreach (var group in groups)
                {
                    var newGroup = new ResponderChatGroupInfo()
                    {
                        Id = $"{Config.ChatConfig.DepartmentGroupChatPrefix}{department.Code}_{group.DepartmentGroupId}", Name = group.Name, Count = group.Members.Count
                    };

                    if (group.Type.HasValue)
                    {
                        newGroup.Type = 3;
                    }
                    else if (group.Type.GetValueOrDefault() == (int)DepartmentGroupTypes.Station)
                    {
                        newGroup.Type = 2;
                    }
                    else if (group.Type.GetValueOrDefault() == (int)DepartmentGroupTypes.Orginizational)
                    {
                        newGroup.Type = 3;
                    }

                    result.Groups.Add(newGroup);
                }
            }
            else
            {
                var group = await _departmentGroupsService.GetGroupForUserAsync(UserId, DepartmentId);

                if (group != null)
                {
                    var newGroup = new ResponderChatGroupInfo()
                    {
                        Id = $"{Config.ChatConfig.DepartmentGroupChatPrefix}{department.Code}_{group.DepartmentGroupId}", Name = group.Name, Count = group.Members.Count
                    };

                    if (group.Type.HasValue)
                    {
                        newGroup.Type = 3;
                    }
                    else if (group.Type.GetValueOrDefault() == (int)DepartmentGroupTypes.Station)
                    {
                        newGroup.Type = 2;
                    }
                    else if (group.Type.GetValueOrDefault() == (int)DepartmentGroupTypes.Orginizational)
                    {
                        newGroup.Type = 3;
                    }

                    result.Groups.Add(newGroup);
                }
            }

            return(Ok(result));
        }
Пример #9
0
        public async Task <ActionResult <List <StationResult> > > GetStationResources()
        {
            var result = new List <StationResult>();

            var unitStatuses = await _unitsService.GetAllLatestStatusForUnitsByDepartmentIdAsync(DepartmentId);

            var actionLogs = await _actionLogsService.GetAllActionLogsForDepartmentAsync(DepartmentId);

            var userStates = await _userStateService.GetLatestStatesForDepartmentAsync(DepartmentId);

            var stations = await _departmentGroupsService.GetAllGroupsForDepartmentAsync(DepartmentId);

            var userGroups = await _departmentGroupsService.GetAllDepartmentGroupsForDepartmentAsync(DepartmentId);

            var users = await _departmentsService.GetAllUsersForDepartmentAsync(DepartmentId);

            var units = await _unitsService.GetUnitsForDepartmentAsync(DepartmentId);

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

            Parallel.ForEach(users, u =>
            {
                var log = (from l in actionLogs
                           where l.UserId == u.UserId
                           select l).FirstOrDefault();

                var state = (from l in userStates
                             where l.UserId == u.UserId
                             select l).FirstOrDefault();

                var s = new StationResult();
                s.Id  = u.UserId.ToString();
                s.Typ = 1;

                if (log != null)
                {
                    s.Sts = log.ActionTypeId;
                    s.Stm = log.Timestamp.TimeConverter(department);

                    if (log.DestinationId.HasValue)
                    {
                        if (log.ActionTypeId == (int)ActionTypes.RespondingToStation)
                        {
                            s.Did = log.DestinationId.GetValueOrDefault();

                            var group = stations.First(x => x.DepartmentGroupId == log.DestinationId.Value);
                            s.Dnm     = group.Name;
                        }
                        else if (log.ActionTypeId == (int)ActionTypes.AvailableStation)
                        {
                            s.Did = log.DestinationId.GetValueOrDefault();

                            var group = stations.First(x => x.DepartmentGroupId == log.DestinationId.Value);
                            s.Dnm     = group.Name;
                        }
                    }
                }
                else
                {
                    s.Sts = (int)ActionTypes.StandingBy;
                    s.Stm = DateTime.UtcNow.TimeConverter(department);
                }

                if (s.Did == 0)
                {
                    if (userGroups.ContainsKey(u.UserId))
                    {
                        var homeGroup = userGroups[u.UserId];
                        if (homeGroup != null && homeGroup.Type.HasValue &&
                            ((DepartmentGroupTypes)homeGroup.Type) == DepartmentGroupTypes.Station)
                        {
                            s.Did = homeGroup.DepartmentGroupId;
                            s.Dnm = homeGroup.Name;
                        }
                    }
                }

                if (state != null)
                {
                    s.Ste = state.State;
                    s.Stt = state.Timestamp.TimeConverter(department);
                }
                else
                {
                    s.Ste = (int)UserStateTypes.Available;
                    s.Stt = DateTime.UtcNow.TimeConverter(department);
                }

                if (!String.IsNullOrWhiteSpace(s.Dnm))
                {
                    result.Add(s);
                }
            });

            Parallel.ForEach(unitStatuses, unit =>
            {
                var unitResult = new StationResult();
                var savedUnit  = units.FirstOrDefault(x => x.UnitId == unit.UnitId);

                if (savedUnit != null)
                {
                    unitResult.Id = savedUnit.UnitId.ToString();
                    //unitResult.Nme = savedUnit.Name;
                    unitResult.Typ = 2;
                    unitResult.Sts = unit.State;
                    unitResult.Stm = unit.Timestamp.TimeConverter(department);

                    if (savedUnit.StationGroupId.HasValue)
                    {
                        unitResult.Did = savedUnit.StationGroupId.Value;
                        unitResult.Dnm = stations.First(x => x.DepartmentGroupId == savedUnit.StationGroupId.Value).Name;

                        result.Add(unitResult);
                    }
                }
            });

            return(Ok(result));
        }
Пример #10
0
        public async Task <ActionResult <NewCallPayloadResult> > GetNewCallData()
        {
            var results = new NewCallPayloadResult();

            results.Personnel    = new List <PersonnelInfoResult>();
            results.Groups       = new List <GroupInfoResult>();
            results.Units        = new List <UnitInfoResult>();
            results.Roles        = new List <RoleInfoResult>();
            results.Statuses     = new List <CustomStatusesResult>();
            results.UnitStatuses = new List <UnitStatusCoreResult>();
            results.UnitRoles    = new List <UnitRoleResult>();
            results.Priorities   = new List <CallPriorityResult>();
            results.CallTypes    = new List <CallTypeResult>();

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

            var users = await _departmentsService.GetAllUsersForDepartmentAsync(DepartmentId);

            var groups = await _departmentGroupsService.GetAllDepartmentGroupsForDepartmentAsync(DepartmentId);

            var rolesForUsersInDepartment = await _personnelRolesService.GetAllRolesForUsersInDepartmentAsync(DepartmentId);

            var allRoles = await _personnelRolesService.GetRolesForDepartmentAsync(DepartmentId);

            var allProfiles = await _userProfileService.GetAllProfilesForDepartmentAsync(DepartmentId);

            var allGroups = await _departmentGroupsService.GetAllGroupsForDepartmentAsync(DepartmentId);

            var units = await _unitsService.GetUnitsForDepartmentAsync(DepartmentId);

            var unitTypes = await _unitsService.GetUnitTypesForDepartmentAsync(DepartmentId);

            var callPriorites = await _callsService.GetActiveCallPrioritiesForDepartmentAsync(DepartmentId);

            var callTypes = await _callsService.GetCallTypesForDepartmentAsync(DepartmentId);


            foreach (var user in users)
            {
                //var profile = _userProfileService.GetProfileByUserId(user.UserId);
                //var group = _departmentGroupsService.GetGroupForUser(user.UserId);

                UserProfile profile = null;
                if (allProfiles.ContainsKey(user.UserId))
                {
                    profile = allProfiles[user.UserId];
                }

                DepartmentGroup group = null;
                if (groups.ContainsKey(user.UserId))
                {
                    group = groups[user.UserId];
                }

                //var roles = _personnelRolesService.GetRolesForUser(user.UserId);

                List <PersonnelRole> roles = null;
                if (rolesForUsersInDepartment.ContainsKey(user.UserId))
                {
                    roles = rolesForUsersInDepartment[user.UserId];
                }

                var result = new PersonnelInfoResult();

                if (profile != null)
                {
                    result.Fnm = profile.FirstName;
                    result.Lnm = profile.LastName;
                    result.Id  = profile.IdentificationNumber;
                    result.Mnu = profile.MobileNumber;
                }
                else
                {
                    result.Fnm = "Unknown";
                    result.Lnm = "Check Profile";
                    result.Id  = "";
                    result.Mnu = "";
                }

                result.Eml = user.Email;
                result.Did = DepartmentId;
                result.Uid = user.UserId.ToString();

                if (group != null)
                {
                    result.Gid = group.DepartmentGroupId;
                    result.Gnm = group.Name;
                }

                result.Roles = new List <string>();
                if (roles != null && roles.Count > 0)
                {
                    foreach (var role in roles)
                    {
                        if (role != null)
                        {
                            result.Roles.Add(role.Name);
                        }
                    }
                }

                results.Personnel.Add(result);
            }

            foreach (var group in allGroups)
            {
                var groupInfo = new GroupInfoResult();
                groupInfo.Gid = group.DepartmentGroupId;
                groupInfo.Nme = group.Name;

                if (group.Type.HasValue)
                {
                    groupInfo.Typ = group.Type.Value;
                }

                if (group.Address != null)
                {
                    groupInfo.Add = group.Address.FormatAddress();
                }

                results.Groups.Add(groupInfo);
            }

            foreach (var unit in units)
            {
                var unitResult = new UnitInfoResult();
                unitResult.Uid = unit.UnitId;
                unitResult.Did = DepartmentId;
                unitResult.Nme = unit.Name;
                unitResult.Typ = unit.Type;

                if (!string.IsNullOrWhiteSpace(unit.Type))
                {
                    var unitType = unitTypes.FirstOrDefault(x => x.Type == unit.Type);

                    if (unitType != null)
                    {
                        unitResult.Cid = unitType.CustomStatesId.GetValueOrDefault();
                    }
                }
                else
                {
                    unitResult.Cid = 0;
                }

                if (unit.StationGroup != null)
                {
                    unitResult.Sid = unit.StationGroup.DepartmentGroupId;
                    unitResult.Snm = unit.StationGroup.Name;
                }

                results.Units.Add(unitResult);

                // Add unit roles for this unit
                var roles = await _unitsService.GetRolesForUnitAsync(unit.UnitId);

                foreach (var role in roles)
                {
                    var roleResult = new UnitRoleResult();
                    roleResult.Name       = role.Name;
                    roleResult.UnitId     = role.UnitId;
                    roleResult.UnitRoleId = role.UnitRoleId;

                    results.UnitRoles.Add(roleResult);
                }
            }

            var unitStatuses = await _unitsService.GetAllLatestStatusForUnitsByDepartmentIdAsync(DepartmentId);

            foreach (var us in unitStatuses)
            {
                var unitStatus = new UnitStatusCoreResult();
                unitStatus.UnitId      = us.UnitId;
                unitStatus.StateType   = (UnitStateTypes)us.State;
                unitStatus.StateTypeId = us.State;
                unitStatus.Type        = us.Unit.Type;
                unitStatus.Timestamp   = us.Timestamp.TimeConverter(department);
                unitStatus.Name        = us.Unit.Name;
                unitStatus.Note        = us.Note;

                if (us.DestinationId.HasValue)
                {
                    unitStatus.DestinationId = us.DestinationId.Value;
                }

                if (us.LocalTimestamp.HasValue)
                {
                    unitStatus.LocalTimestamp = us.LocalTimestamp.Value;
                }

                if (us.Latitude.HasValue)
                {
                    unitStatus.Latitude = us.Latitude.Value;
                }

                if (us.Longitude.HasValue)
                {
                    unitStatus.Longitude = us.Longitude.Value;
                }

                results.UnitStatuses.Add(unitStatus);
            }

            foreach (var role in allRoles)
            {
                var roleResult = new RoleInfoResult();
                roleResult.Rid = role.PersonnelRoleId;
                roleResult.Nme = role.Name;

                results.Roles.Add(roleResult);
            }

            var customStates = await _customStateService.GetAllActiveCustomStatesForDepartmentAsync(DepartmentId);

            foreach (var customState in customStates)
            {
                if (customState.IsDeleted)
                {
                    continue;
                }

                foreach (var stateDetail in customState.GetActiveDetails())
                {
                    if (stateDetail.IsDeleted)
                    {
                        continue;
                    }

                    var customStateResult = new CustomStatusesResult();
                    customStateResult.Id      = stateDetail.CustomStateDetailId;
                    customStateResult.Type    = customState.Type;
                    customStateResult.StateId = stateDetail.CustomStateId;
                    customStateResult.Text    = stateDetail.ButtonText;
                    customStateResult.BColor  = stateDetail.ButtonColor;
                    customStateResult.Color   = stateDetail.TextColor;
                    customStateResult.Gps     = stateDetail.GpsRequired;
                    customStateResult.Note    = stateDetail.NoteType;
                    customStateResult.Detail  = stateDetail.DetailType;

                    results.Statuses.Add(customStateResult);
                }
            }

            foreach (var priority in callPriorites)
            {
                var priorityResult = new CallPriorityResult();
                priorityResult.Id           = priority.DepartmentCallPriorityId;
                priorityResult.DepartmentId = priority.DepartmentId;
                priorityResult.Name         = priority.Name;
                priorityResult.Color        = priority.Color;
                priorityResult.Sort         = priority.Sort;
                priorityResult.IsDeleted    = priority.IsDeleted;
                priorityResult.IsDefault    = priority.IsDefault;

                results.Priorities.Add(priorityResult);
            }

            if (callTypes != null && callTypes.Any())
            {
                foreach (var callType in callTypes)
                {
                    var type = new CallTypeResult();
                    type.Id   = callType.CallTypeId;
                    type.Name = callType.Type;

                    results.CallTypes.Add(type);
                }
            }


            return(results);
        }
Пример #11
0
        public async Task <Tuple <bool, string> > Process(CalendarNotifierQueueItem item)
        {
            bool   success = true;
            string result  = "";

            if (item?.CalendarItem?.Attendees != null && item.CalendarItem.Attendees.Any())
            {
                try
                {
                    var message  = String.Empty;
                    var title    = String.Empty;
                    var profiles = await _userProfileService.GetSelectedUserProfilesAsync(item.CalendarItem.Attendees.Select(x => x.UserId).ToList());

                    var departmentNumber = await _departmentSettingsService.GetTextToCallNumberForDepartmentAsync(item.CalendarItem.DepartmentId);

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

                    var adjustedDateTime = item.CalendarItem.Start.TimeConverter(department);

                    title = string.Format("Upcoming: {0}", item.CalendarItem.Title);

                    if (String.IsNullOrWhiteSpace(item.CalendarItem.Location))
                    {
                        message = $"on {adjustedDateTime.ToShortDateString()} - {adjustedDateTime.ToShortTimeString()}";
                    }
                    else
                    {
                        message = $"on {adjustedDateTime.ToShortDateString()} - {adjustedDateTime.ToShortTimeString()} at {item.CalendarItem.Location}";
                    }

                    foreach (var person in item.CalendarItem.Attendees)
                    {
                        var profile = profiles.FirstOrDefault(x => x.UserId == person.UserId);
                        await _communicationService.SendNotificationAsync(person.UserId, item.CalendarItem.DepartmentId, message, departmentNumber, title, profile);
                    }
                }
                catch (Exception ex)
                {
                    success = false;
                    result  = ex.ToString();

                    Logging.LogException(ex);
                }

                await _calendarService.MarkAsNotifiedAsync(item.CalendarItem.CalendarItemId);
            }
            else if (!String.IsNullOrWhiteSpace(item?.CalendarItem?.Entities))
            {
                var items = item.CalendarItem.Entities.Split(char.Parse(","));

                var message  = String.Empty;
                var title    = String.Empty;
                var profiles = await _userProfileService.GetAllProfilesForDepartmentAsync(item.CalendarItem.DepartmentId);

                var departmentNumber = await _departmentSettingsService.GetTextToCallNumberForDepartmentAsync(item.CalendarItem.DepartmentId);

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

                var adjustedDateTime = item.CalendarItem.Start.TimeConverter(department);
                title = $"Upcoming: {item.CalendarItem.Title}";

                if (String.IsNullOrWhiteSpace(item.CalendarItem.Location))
                {
                    message = $"on {adjustedDateTime.ToShortDateString()} - {adjustedDateTime.ToShortTimeString()}";
                }
                else
                {
                    message = $"on {adjustedDateTime.ToShortDateString()} - {adjustedDateTime.ToShortTimeString()} at {item.CalendarItem.Location}";
                }

                if (items.Any(x => x.StartsWith("D:")))
                {
                    // Notify the entire department
                    foreach (var profile in profiles)
                    {
                        await _communicationService.SendNotificationAsync(profile.Key, item.CalendarItem.DepartmentId, message, departmentNumber, title, profile.Value);
                    }
                }
                else
                {
                    var groups = await _departmentGroupsService.GetAllGroupsForDepartmentAsync(item.CalendarItem.DepartmentId);

                    foreach (var val in items)
                    {
                        int groupId = 0;
                        if (int.TryParse(val.Replace("G:", ""), out groupId))
                        {
                            var group = groups.FirstOrDefault(x => x.DepartmentGroupId == groupId);

                            if (group != null)
                            {
                                foreach (var member in group.Members)
                                {
                                    if (profiles.ContainsKey(member.UserId))
                                    {
                                        await _communicationService.SendNotificationAsync(member.UserId, item.CalendarItem.DepartmentId, message, departmentNumber, title, profiles[member.UserId]);
                                    }
                                    else
                                    {
                                        await _communicationService.SendNotificationAsync(member.UserId, item.CalendarItem.DepartmentId, message, departmentNumber, title, null);
                                    }
                                }
                            }
                        }
                    }
                }

                await _calendarService.MarkAsNotifiedAsync(item.CalendarItem.CalendarItemId);
            }

            return(new Tuple <bool, string>(success, result));
        }
Пример #12
0
        public async Task <ActionResult <CoreDataResult> > GetCoreData()
        {
            var results = new CoreDataResult();

            results.Personnel   = new List <PersonnelInfoResult>();
            results.Groups      = new List <GroupInfoResult>();
            results.Units       = new List <UnitInfoResult>();
            results.Roles       = new List <RoleInfoResult>();
            results.Statuses    = new List <CustomStatusesResult>();
            results.Priorities  = new List <CallPriorityResult>();
            results.Departments = new List <JoinedDepartmentResult>();
            results.PersonnelListStatusOrders = new List <PersonnelListStatusOrder>();

            var users = await _departmentsService.GetAllUsersForDepartmentAsync(DepartmentId);

            var groups = await _departmentGroupsService.GetAllDepartmentGroupsForDepartmentAsync(DepartmentId);

            var rolesForUsersInDepartment = await _personnelRolesService.GetAllRolesForUsersInDepartmentAsync(DepartmentId);

            var allRoles = await _personnelRolesService.GetRolesForDepartmentAsync(DepartmentId);

            var allProfiles = await _userProfileService.GetAllProfilesForDepartmentAsync(DepartmentId);

            var allGroups = await _departmentGroupsService.GetAllGroupsForDepartmentAsync(DepartmentId);

            var units = await _unitsService.GetUnitsForDepartmentAsync(DepartmentId);

            var unitTypes = await _unitsService.GetUnitTypesForDepartmentAsync(DepartmentId);

            var callPriorites = await _callsService.GetCallPrioritiesForDepartmentAsync(DepartmentId);

            var personnelListStatusOrderings = await _departmentSettingsService.GetDepartmentPersonnelListStatusSortOrderAsync(DepartmentId);

            var personnelListSortOrder = await _departmentSettingsService.GetDepartmentPersonnelSortOrderAsync(DepartmentId);


            if (personnelListStatusOrderings != null)
            {
                results.PersonnelListStatusOrders = personnelListStatusOrderings;
            }

            results.PersonnelNameSorting = (int)personnelListSortOrder;

            foreach (var user in users)
            {
                UserProfile profile = null;
                if (allProfiles.ContainsKey(user.UserId))
                {
                    profile = allProfiles[user.UserId];
                }

                DepartmentGroup group = null;
                if (groups.ContainsKey(user.UserId))
                {
                    group = groups[user.UserId];
                }

                List <PersonnelRole> roles = null;
                if (rolesForUsersInDepartment.ContainsKey(user.UserId))
                {
                    roles = rolesForUsersInDepartment[user.UserId];
                }

                var result = new PersonnelInfoResult();

                if (profile != null)
                {
                    result.Fnm = profile.FirstName;
                    result.Lnm = profile.LastName;
                    result.Id  = profile.IdentificationNumber;


                    result.Mnu = profile.MobileNumber;
                }
                else
                {
                    result.Fnm = "Unknown";
                    result.Lnm = "Check Profile";
                    result.Id  = "";
                    result.Mnu = "";
                }

                if (user != null)
                {
                    result.Eml = user.Email;
                }

                result.Did = DepartmentId;
                result.Uid = user.UserId.ToString();

                if (group != null)
                {
                    result.Gid = group.DepartmentGroupId;
                    result.Gnm = group.Name;
                }

                result.Roles = new List <string>();
                if (roles != null && roles.Count > 0)
                {
                    foreach (var role in roles)
                    {
                        if (role != null)
                        {
                            result.Roles.Add(role.Name);
                        }
                    }
                }

                results.Personnel.Add(result);
            }


            results.Rights = new DepartmentRightsResult();
            var currentUser = await _usersService.GetUserByNameAsync(UserName);

            if (currentUser == null)
            {
                return(Unauthorized());
            }

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

            results.Rights.Adm  = department.IsUserAnAdmin(currentUser.UserId);
            results.Rights.Grps = new List <GroupRight>();

            var currentGroup = await _departmentGroupsService.GetGroupForUserAsync(currentUser.UserId, DepartmentId);

            if (currentGroup != null)
            {
                var groupRight = new GroupRight();
                groupRight.Gid = currentGroup.DepartmentGroupId;
                groupRight.Adm = currentGroup.IsUserGroupAdmin(currentUser.UserId);

                results.Rights.Grps.Add(groupRight);
            }

            foreach (var group in allGroups)
            {
                var groupInfo = new GroupInfoResult();
                groupInfo.Gid = group.DepartmentGroupId;
                groupInfo.Nme = group.Name;

                if (group.Type.HasValue)
                {
                    groupInfo.Typ = group.Type.Value;
                }

                if (group.Address != null)
                {
                    groupInfo.Add = group.Address.FormatAddress();
                }

                results.Groups.Add(groupInfo);
            }

            foreach (var unit in units)
            {
                var unitResult = new UnitInfoResult();
                unitResult.Uid = unit.UnitId;
                unitResult.Did = DepartmentId;
                unitResult.Nme = unit.Name;
                unitResult.Typ = unit.Type;

                if (!string.IsNullOrWhiteSpace(unit.Type))
                {
                    var unitType = unitTypes.FirstOrDefault(x => x.Type == unit.Type);

                    if (unitType != null)
                    {
                        unitResult.Cid = unitType.CustomStatesId.GetValueOrDefault();
                    }
                }
                else
                {
                    unitResult.Cid = 0;
                }

                if (unit.StationGroup != null)
                {
                    unitResult.Sid = unit.StationGroup.DepartmentGroupId;
                    unitResult.Snm = unit.StationGroup.Name;
                }

                results.Units.Add(unitResult);
            }

            foreach (var role in allRoles)
            {
                var roleResult = new RoleInfoResult();
                roleResult.Rid = role.PersonnelRoleId;
                roleResult.Nme = role.Name;

                results.Roles.Add(roleResult);
            }

            var customStates = await _customStateService.GetAllActiveCustomStatesForDepartmentAsync(DepartmentId);

            foreach (var customState in customStates)
            {
                if (customState != null)
                {
                    if (customState.IsDeleted || customState.Details == null)
                    {
                        continue;
                    }

                    foreach (var stateDetail in customState.Details)
                    {
                        if (stateDetail == null || stateDetail.IsDeleted)
                        {
                            continue;
                        }

                        var customStateResult = new CustomStatusesResult();
                        customStateResult.Id      = stateDetail.CustomStateDetailId;
                        customStateResult.Type    = customState.Type;
                        customStateResult.StateId = stateDetail.CustomStateId;
                        customStateResult.Text    = stateDetail.ButtonText;
                        customStateResult.BColor  = stateDetail.ButtonColor;
                        customStateResult.Color   = stateDetail.TextColor;
                        customStateResult.Gps     = stateDetail.GpsRequired;
                        customStateResult.Note    = stateDetail.NoteType;
                        customStateResult.Detail  = stateDetail.DetailType;

                        if (customState.IsDeleted)
                        {
                            customStateResult.IsDeleted = true;
                        }
                        else
                        {
                            customStateResult.IsDeleted = stateDetail.IsDeleted;
                        }

                        results.Statuses.Add(customStateResult);
                    }
                }
            }

            foreach (var priority in callPriorites)
            {
                var priorityResult = new CallPriorityResult();
                priorityResult.Id           = priority.DepartmentCallPriorityId;
                priorityResult.DepartmentId = priority.DepartmentId;
                priorityResult.Name         = priority.Name;
                priorityResult.Color        = priority.Color;
                priorityResult.Sort         = priority.Sort;
                priorityResult.IsDeleted    = priority.IsDeleted;
                priorityResult.IsDefault    = priority.IsDefault;

                results.Priorities.Add(priorityResult);
            }

            var members = await _departmentsService.GetAllDepartmentsForUserAsync(UserId);

            foreach (var member in members)
            {
                if (member.IsDeleted)
                {
                    continue;
                }

                if (member.IsDisabled.GetValueOrDefault())
                {
                    continue;
                }

                var depRest = new JoinedDepartmentResult();
                depRest.Did = member.DepartmentId;
                depRest.Nme = member.Department.Name;

                results.Departments.Add(depRest);
            }

            return(Ok(results));
        }
Пример #13
0
        public override async Task <ClaimsPrincipal> CreateAsync(TUser user)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            var userId = await UserManager.GetUserIdAsync(user);

            var userName = await UserManager.GetUserNameAsync(user);

            var profile = await _userProfileService.GetProfileByUserIdAsync(userId);

            var id = new ClaimsIdentity(
                CookieAuthenticationDefaults.AuthenticationScheme,
                Options.ClaimsIdentity.UserNameClaimType,
                Options.ClaimsIdentity.RoleClaimType
                );

            id.AddClaim(new Claim(Options.ClaimsIdentity.UserIdClaimType, userId));
            id.AddClaim(new Claim(Options.ClaimsIdentity.UserNameClaimType, userName));

            if (UserManager.SupportsUserSecurityStamp)
            {
                id.AddClaim(new Claim(Options.ClaimsIdentity.SecurityStampClaimType,
                                      await UserManager.GetSecurityStampAsync(user)));
            }

            if (UserManager.SupportsUserRole)
            {
                var roles = await _claimsRepository.GetRolesAsync(user);

                foreach (var roleName in roles)
                {
                    id.AddClaim(new Claim(Options.ClaimsIdentity.RoleClaimType, roleName));
                }
            }

            ClaimsPrincipal principal = new ClaimsPrincipal(id);

            if (principal.Identity is ClaimsIdentity)
            {
                ClaimsIdentity identity = (ClaimsIdentity)principal.Identity;

                if (profile != null)
                {
                    Claim displayNameClaim = new Claim("DisplayName", profile.FullName.AsFirstNameLastName);
                    if (!identity.HasClaim(displayNameClaim.Type, displayNameClaim.Value))
                    {
                        identity.AddClaim(displayNameClaim);
                    }
                }

                Claim emailClaim = new Claim(ClaimTypes.Email, user.Email);
                if (!identity.HasClaim(emailClaim.Type, emailClaim.Value))
                {
                    identity.AddClaim(emailClaim);
                }

                if (_usersService.IsUserInRole(user.Id, _usersService.AdminRoleId))
                {
                    ClaimsLogic.AddSystemAdminClaims(id, userName, user.Id, "System Admin");
                }
                else if (_usersService.IsUserInRole(user.Id, _usersService.AffiliateRoleId))
                {
                    ClaimsLogic.AddAffiliteClaims(id, userName,
                                                  user.Id, profile.FullName.AsFirstNameLastName);
                }
                else
                {
                    var department = await _departmentsService.GetDepartmentForUserAsync(userName);

                    if (department == null)
                    {
                        return(null);
                    }

                    var group = await _departmentGroupsService.GetGroupForUserAsync(user.Id, department.DepartmentId);

                    var departmentAdmin = department.IsUserAnAdmin(user.Id);
                    var permissions     = await _permissionsService.GetAllPermissionsForDepartmentAsync(department.DepartmentId);

                    var roles = await _personnelRolesService.GetRolesForUserAsync(user.Id, department.DepartmentId);

                    ClaimsLogic.AddDepartmentClaim(id, department.DepartmentId,
                                                   departmentAdmin);
                    //ClaimsLogic.DepartmentName = department.Name;

                    DateTime signupDate;
                    if (department.CreatedOn.HasValue)
                    {
                        signupDate = department.CreatedOn.Value;
                    }
                    else
                    {
                        signupDate = DateTime.UtcNow;
                    }

                    //ClaimsLogic.DepartmentId = department.DepartmentId;

                    var name = user.UserName;
                    if (profile != null && !String.IsNullOrWhiteSpace(profile.LastName))
                    {
                        name = profile.FullName.AsFirstNameLastName;
                    }

                    ClaimsLogic.AddGeneralClaims(id, userName,
                                                 user.Id, name, department.DepartmentId, department.Name, user.Email,
                                                 signupDate);

                    bool isGroupAdmin = false;

                    if (group != null)
                    {
                        isGroupAdmin = group.IsUserGroupAdmin(user.Id);
                    }

                    if (departmentAdmin)
                    {
                        var groups = await _departmentGroupsService.GetAllGroupsForDepartmentAsync(department.DepartmentId);

                        if (groups != null)
                        {
                            foreach (var departmentGroup in groups)
                            {
                                ClaimsLogic.AddGroupClaim(id, departmentGroup.DepartmentGroupId, true);
                            }
                        }
                    }
                    else
                    {
                        if (group != null)
                        {
                            ClaimsLogic.AddGroupClaim(id, group.DepartmentGroupId, isGroupAdmin);
                        }
                    }

                    ClaimsLogic.AddCallClaims(id, departmentAdmin, permissions, isGroupAdmin, roles);
                    ClaimsLogic.AddActionClaims(id);
                    ClaimsLogic.AddLogClaims(id, departmentAdmin, permissions, isGroupAdmin, roles);
                    ClaimsLogic.AddStaffingClaims(id);
                    ClaimsLogic.AddPersonnelClaims(id, departmentAdmin, permissions, isGroupAdmin, roles);
                    ClaimsLogic.AddUnitClaims(id, departmentAdmin);
                    ClaimsLogic.AddUnitLogClaims(id);
                    ClaimsLogic.AddMessageClaims(id, departmentAdmin, permissions, isGroupAdmin, roles);
                    ClaimsLogic.AddRoleClaims(id, departmentAdmin);
                    ClaimsLogic.AddProfileClaims(id);
                    ClaimsLogic.AddReportsClaims(id);
                    ClaimsLogic.AddGenericGroupClaims(id, departmentAdmin);
                    ClaimsLogic.AddDocumentsClaims(id, departmentAdmin, permissions, isGroupAdmin, roles);
                    ClaimsLogic.AddNotesClaims(id, departmentAdmin, permissions, isGroupAdmin, roles);
                    ClaimsLogic.AddScheduleClaims(id, departmentAdmin, permissions, isGroupAdmin, roles);
                    ClaimsLogic.AddShiftClaims(id, departmentAdmin, permissions, isGroupAdmin, roles);
                    ClaimsLogic.AddTrainingClaims(id, departmentAdmin, permissions, isGroupAdmin, roles);
                    ClaimsLogic.AddPIIClaims(id, departmentAdmin, permissions, isGroupAdmin, roles);
                    ClaimsLogic.AddInventoryClaims(id, departmentAdmin, permissions, isGroupAdmin, roles);
                    ClaimsLogic.AddConnectClaims(id, departmentAdmin);
                    ClaimsLogic.AddCommandClaims(id, departmentAdmin);
                    ClaimsLogic.AddProtocolClaims(id, departmentAdmin);
                }
            }

            return(principal);
        }
Пример #14
0
        public async Task <IActionResult> GetUserStatusTable()
        {
            var model = new UserStatusTableModel();

            model.Department = await _departmentsService.GetDepartmentByIdAsync(DepartmentId, false);

            model.LastUserActionlogs = await _actionLogsService.GetLastActionLogsForDepartmentAsync(DepartmentId);

            model.UserStates       = new List <UserState>();
            model.DepartmentGroups = await _departmentGroupsService.GetAllGroupsForDepartmentAsync(DepartmentId);

            model.Stations = await _departmentGroupsService.GetAllStationGroupsForDepartmentAsync(DepartmentId);

            model.UsersGroup = await _departmentGroupsService.GetGroupForUserAsync(UserId, DepartmentId);

            model.States = await _customStateService.GetActivePersonnelStateForDepartmentAsync(DepartmentId);

            model.StaffingLevels = await _customStateService.GetActiveStaffingLevelsForDepartmentAsync(DepartmentId);

            var personnelSortOrder = await _departmentSettingsService.GetDepartmentPersonnelSortOrderAsync(DepartmentId);

            var personnelStatusSortOrder = await _departmentSettingsService.GetDepartmentPersonnelListStatusSortOrderAsync(DepartmentId);

            var userStates = await _userStateService.GetLatestStatesForDepartmentAsync(DepartmentId);

            var allUsers = _usersService.GetUserGroupAndRolesByDepartmentId(DepartmentId, false, false, false);

            model.ExcludedUsers = await _departmentsService.GetAllDisabledOrHiddenUsersAsync(DepartmentId);

            List <string> groupedUserIds = new List <string>();

            foreach (var dg in model.DepartmentGroups)
            {
                UserStatusGroup group = new UserStatusGroup();
                group.Group = dg;

                var membersToProcess = from member in dg.Members
                                       where !(model.ExcludedUsers.Any(item2 => item2 == member.UserId))
                                       select member;

                foreach (var u in membersToProcess)
                {
                    if (allUsers.Any(x => x.UserId == u.UserId))
                    {
                        groupedUserIds.Add(u.UserId);
                        var userInfo = allUsers.FirstOrDefault(x => x.UserId == u.UserId);

                        UserState state = userStates.FirstOrDefault(x => x.UserId == u.UserId);

                        if (state == null)
                        {
                            state               = new UserState();
                            state.UserId        = u.UserId;
                            state.AutoGenerated = true;
                            state.Timestamp     = DateTime.UtcNow;
                            state.State         = (int)UserStateTypes.Available;
                        }

                        if (!model.DepartmentUserStates.ContainsKey(u.UserId))
                        {
                            model.DepartmentUserStates.Add(u.UserId, state);
                        }

                        var al = model.LastUserActionlogs.FirstOrDefault(x => x.UserId == u.UserId);

                        UserStatus userStatus = new UserStatus();
                        userStatus.UserInfo        = userInfo;
                        userStatus.CurrentStatus   = al;
                        userStatus.CurrentStaffing = state;

                        if (al != null)
                        {
                            if (personnelStatusSortOrder != null && personnelStatusSortOrder.Any())
                            {
                                var statusSorting = personnelStatusSortOrder.FirstOrDefault(x => x.StatusId == al.ActionTypeId);
                                if (statusSorting != null)
                                {
                                    userStatus.Weight = statusSorting.Weight;
                                }
                                else
                                {
                                    userStatus.Weight = 9000;
                                }
                            }
                            else
                            {
                                userStatus.Weight = 9000;
                            }
                        }
                        else
                        {
                            userStatus.Weight = 9000;
                        }

                        group.UserStatuses.Add(userStatus);
                    }
                }

                switch (personnelSortOrder)
                {
                case PersonnelSortOrders.Default:
                    group.UserStatuses = group.UserStatuses.OrderBy(x => x.Weight).ToList();
                    break;

                case PersonnelSortOrders.FirstName:
                    group.UserStatuses = group.UserStatuses.OrderBy(x => x.Weight).ThenBy(x => x.UserInfo.FirstName).ToList();
                    break;

                case PersonnelSortOrders.LastName:
                    group.UserStatuses = group.UserStatuses.OrderBy(x => x.Weight).ThenBy(x => x.UserInfo.LastName).ToList();
                    break;

                default:
                    group.UserStatuses = group.UserStatuses.OrderBy(x => x.Weight).ToList();
                    break;
                }

                model.UserStatusGroups.Add(group);

                var allGroupMembers = new List <DepartmentGroupMember>(dg.Members);
            }

            var ungroupedUsers = from u in allUsers
                                 where !(groupedUserIds.Contains(u.UserId)) && !(model.ExcludedUsers.Any(item2 => item2 == u.UserId))
                                 select u;

            UserStatusGroup unGroupedUsersGroup = new UserStatusGroup();

            unGroupedUsersGroup.Group = null;
            foreach (var u in ungroupedUsers)
            {
                model.UnGroupedUsers.Add(u.UserId);

                UserState state    = userStates.FirstOrDefault(x => x.UserId == u.UserId);
                var       userInfo = allUsers.FirstOrDefault(x => x.UserId == u.UserId);

                if (state == null)
                {
                    state               = new UserState();
                    state.UserId        = u.UserId;
                    state.AutoGenerated = true;
                    state.Timestamp     = DateTime.UtcNow;
                    state.State         = (int)UserStateTypes.Available;
                }

                var al = model.LastUserActionlogs.FirstOrDefault(x => x.UserId == u.UserId);

                UserStatus userStatus = new UserStatus();
                userStatus.UserInfo        = userInfo;
                userStatus.CurrentStatus   = al;
                userStatus.CurrentStaffing = state;

                if (al != null)
                {
                    if (personnelStatusSortOrder != null && personnelStatusSortOrder.Any())
                    {
                        var statusSorting = personnelStatusSortOrder.FirstOrDefault(x => x.StatusId == al.ActionTypeId);
                        if (statusSorting != null)
                        {
                            userStatus.Weight = statusSorting.Weight;
                        }
                        else
                        {
                            userStatus.Weight = 9000;
                        }
                    }
                    else
                    {
                        userStatus.Weight = 9000;
                    }
                }
                else
                {
                    userStatus.Weight = 9000;
                }

                unGroupedUsersGroup.UserStatuses.Add(userStatus);
            }

            switch (personnelSortOrder)
            {
            case PersonnelSortOrders.Default:
                unGroupedUsersGroup.UserStatuses = unGroupedUsersGroup.UserStatuses.OrderBy(x => x.Weight).ToList();
                break;

            case PersonnelSortOrders.FirstName:
                unGroupedUsersGroup.UserStatuses = unGroupedUsersGroup.UserStatuses.OrderBy(x => x.Weight).ThenBy(x => x.UserInfo.FirstName).ToList();
                break;

            case PersonnelSortOrders.LastName:
                unGroupedUsersGroup.UserStatuses = unGroupedUsersGroup.UserStatuses.OrderBy(x => x.Weight).ThenBy(x => x.UserInfo.LastName).ToList();
                break;

            default:
                unGroupedUsersGroup.UserStatuses = unGroupedUsersGroup.UserStatuses.OrderBy(x => x.Weight).ToList();
                break;
            }
            model.UserStatusGroups.Add(unGroupedUsersGroup);

            return(PartialView("_UserStatusTablePartial", model));
        }
Пример #15
0
        private async Task <List <FilterResult> > GetFilterOptions()
        {
            var result = new List <FilterResult>();

            var stations = await _departmentGroupsService.GetAllGroupsForDepartmentAsync(DepartmentId);

            var roles = await _personnelRolesService.GetRolesForDepartmentAsync(DepartmentId);

            foreach (var s in stations)
            {
                var respondingTo = new FilterResult();
                respondingTo.Id   = string.Format("G:{0}", s.DepartmentGroupId);
                respondingTo.Type = "Group";
                respondingTo.Name = s.Name;

                result.Add(respondingTo);
            }

            foreach (var r in roles)
            {
                var respondingTo = new FilterResult();
                respondingTo.Id   = string.Format("R:{0}", r.PersonnelRoleId);
                respondingTo.Type = "Role";
                respondingTo.Name = r.Name;

                result.Add(respondingTo);
            }

            var status1 = new FilterResult();

            status1.Id   = string.Format("U:{0}", (int)UserStateTypes.Available);
            status1.Type = "Staffing";
            status1.Name = UserStateTypes.Available.GetDisplayString();
            result.Add(status1);

            var status2 = new FilterResult();

            status2.Id   = string.Format("U:{0}", (int)UserStateTypes.Delayed);
            status2.Type = "Staffing";
            status2.Name = UserStateTypes.Delayed.GetDisplayString();
            result.Add(status2);

            var status3 = new FilterResult();

            status3.Id   = string.Format("U:{0}", (int)UserStateTypes.Committed);
            status3.Type = "Staffing";
            status3.Name = UserStateTypes.Committed.GetDisplayString();
            result.Add(status3);

            var status4 = new FilterResult();

            status4.Id   = string.Format("U:{0}", (int)UserStateTypes.OnShift);
            status4.Type = "Staffing";
            status4.Name = UserStateTypes.OnShift.GetDisplayString();
            result.Add(status4);

            var status5 = new FilterResult();

            status5.Id   = string.Format("U:{0}", (int)UserStateTypes.Unavailable);
            status5.Type = "Staffing";
            status5.Name = UserStateTypes.Unavailable.GetDisplayString();
            result.Add(status5);

            return(result);
        }
Пример #16
0
        public async Task <IActionResult> GetPersonnelList(int linkId)
        {
            var link = await _departmentLinksService.GetLinkByIdAsync(linkId);

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

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

            var allUsers = await _departmentsService.GetAllUsersForDepartmentAsync(link.DepartmentId);

            var lastUserActionlogs = await _actionLogsService.GetAllActionLogsForDepartmentAsync(link.DepartmentId);

            var departmentGroups = await _departmentGroupsService.GetAllGroupsForDepartmentAsync(link.DepartmentId);

            var lastUserStates = await _userStateService.GetLatestStatesForDepartmentAsync(link.DepartmentId);

            var personnelNames = await _departmentsService.GetAllPersonnelNamesForDepartmentAsync(link.DepartmentId);

            var calls = await _callsService.GetActiveCallsByDepartmentAsync(link.DepartmentId);

            var stations = await _departmentGroupsService.GetAllStationGroupsForDepartmentAsync(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(await _userStateService.GetLastUserStateByUserIdAsync(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, await 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 = await _departmentGroupsService.GetGroupForUserAsync(u.UserId, DepartmentId)
                                       //let groupName = userGroup == null ? "" : userGroup.Name
                                       //let roles = await _personnelRolesService.GetRolesForUserAsync(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 weight, name ascending
                select new
            {
                Name = name,
                User = u,
                //Group = userGroup,
                Roles = new List <PersonnelRole>()
            };



            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();
                u.Roles.AddRange(await _personnelRolesService.GetRolesForUserAsync(u.User.UserId, DepartmentId));
                var group = await _departmentGroupsService.GetGroupForUserAsync(u.User.UserId, DepartmentId);

                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     = await Models.BigBoardX.PersonnelViewModel.Create(u.Name, al, us, department, respondingToDepartment, group, u.Roles, callNumber);

                personnelViewModels.Add(personnelViewModel);
            }

            return(Json(personnelViewModels));
        }