Ejemplo n.º 1
0
        private List <FilterResult> GetFilterOptions()
        {
            var result = new List <FilterResult>();

            var stations = _departmentGroupsService.GetAllGroupsForDepartment(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);
            });

            /*
             * 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);
             * }
             */
            return(result);
        }
Ejemplo n.º 2
0
        public IActionResult GetDepartmentEnitites()
        {
            List <DepartmentEntitiesJson> items = new List <DepartmentEntitiesJson>();

            var department = _departmentsService.GetDepartmentById(DepartmentId);
            var groups     = _departmentGroupsService.GetAllGroupsForDepartment(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));
        }
Ejemplo n.º 3
0
        public IActionResult Index()
        {
            var model = new UnitsIndexView();

            model.Department       = _departmentsService.GetDepartmentById(DepartmentId);
            model.CanUserAddUnit   = _limitsService.CanDepartentAddNewUnit(DepartmentId);
            model.Groups           = _departmentGroupsService.GetAllGroupsForDepartment(DepartmentId);
            model.Units            = _unitsService.GetUnitsForDepartment(DepartmentId);
            model.States           = _unitsService.GetAllLatestStatusForUnitsByDepartmentId(DepartmentId);
            model.UnitStatuses     = _customStateService.GetAllActiveUnitStatesForDepartment(DepartmentId);
            model.UnitCustomStates = new Dictionary <int, CustomState>();

            foreach (var unit in model.Units)
            {
                var type = _unitsService.GetUnitTypeByName(DepartmentId, unit.Type);
                if (type != null && type.CustomStatesId.HasValue)
                {
                    var customStates = _customStateService.GetCustomSateById(type.CustomStatesId.Value);

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

            return(View(model));
        }
Ejemplo n.º 4
0
        public ChatDataResult GetResponderChatSettings()
        {
            var result = new ChatDataResult();

            // Load Twilio configuration from Web.config
            var accountSid    = _appOptionsAccessor.Value.TwilioAccountSid;
            var apiKey        = _appOptionsAccessor.Value.TwilioApiKey;
            var apiSecret     = _appOptionsAccessor.Value.TwilioApiSecret;
            var ipmServiceSid = _appOptionsAccessor.Value.TwilioIpmServiceSid;

            // Create an Access Token generator
            var token = new AccessToken(accountSid, apiKey, apiSecret);

            token.Identity = UserId.ToString();

            // Create an IP messaging grant for this token
            var grant = new IpMessagingGrant();

            grant.EndpointId = $"ResponderDepChat:{UserId}:ResponderApp";
            grant.ServiceSid = ipmServiceSid;
            token.AddGrant(grant);

            var department = _departmentsService.GetDepartmentById(DepartmentId);
            var groups     = _departmentGroupsService.GetAllGroupsForDepartment(DepartmentId);

            result.Channels = SetupTwilioChatForDepartment(department, groups);

            result.Did  = department.DepartmentId;
            result.Name = department.Name;

            result.Groups = new List <GroupInfoResult>();
            if (department.IsUserAnAdmin(UserId))
            {
                foreach (var group in groups)
                {
                    result.Groups.Add(new GroupInfoResult()
                    {
                        Gid = group.DepartmentGroupId, Nme = group.Name
                    });
                }
            }
            else
            {
                var group = _departmentGroupsService.GetGroupForUser(UserId, DepartmentId);
                if (group != null)
                {
                    result.Groups.Add(new GroupInfoResult()
                    {
                        Gid = group.DepartmentGroupId, Nme = group.Name
                    });
                }
            }

            result.Token = token.ToJWT();

            return(result);
        }
Ejemplo n.º 5
0
        public GroupsModel GetGroups()
        {
            var result = new GroupsModel();

            result.Groups = new List <GroupInfoResult>();
            var groups = _departmentGroupsService.GetAllGroupsForDepartment(DepartmentId);

            foreach (var group in groups)
            {
                var newGroup = new GroupInfoResult();
                newGroup.Gid = group.DepartmentGroupId;
                newGroup.Nme = group.Name;
                newGroup.Typ = group.Type.GetValueOrDefault();

                result.Groups.Add(newGroup);
            }

            return(result);
        }
Ejemplo n.º 6
0
        public List <StationResult> GetStationResources()
        {
            var result = new List <StationResult>();

            var        unitStatuses = _unitsService.GetAllLatestStatusForUnitsByDepartmentId(DepartmentId);
            var        actionLogs   = _actionLogsService.GetActionLogsForDepartment(DepartmentId);
            var        userStates   = _userStateService.GetLatestStatesForDepartment(DepartmentId);
            var        stations     = _departmentGroupsService.GetAllGroupsForDepartment(DepartmentId);
            var        userGroups   = _departmentGroupsService.GetAllDepartmentGroupsForDepartment(DepartmentId);
            var        users        = _departmentsService.GetAllUsersForDepartment(DepartmentId);
            var        units        = _unitsService.GetUnitsForDepartment(DepartmentId);
            Department department   = _departmentsService.GetDepartmentById(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(result);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets the department and group information needed to seed the initial standard groups for chat
        /// </summary>
        /// <returns></returns>
        public ResponderChatResult GetResponderChatInfo()
        {
            var result = new ResponderChatResult();

            result.UserId = UserId;

            var department = _departmentsService.GetDepartmentById(DepartmentId);
            var groups     = _departmentGroupsService.GetAllGroupsForDepartment(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 = _departmentGroupsService.GetGroupForUser(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(result);
        }
Ejemplo n.º 8
0
        public 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 <CallResult>();
            results.UnitStatuses = new List <UnitStatusCoreResult>();
            results.UnitRoles    = new List <UnitRoleResult>();

            var users  = _departmentsService.GetAllUsersForDepartment(DepartmentId);
            var groups = _departmentGroupsService.GetAllDepartmentGroupsForDepartment(DepartmentId);
            var rolesForUsersInDepartment = _personnelRolesService.GetAllRolesForUsersInDepartment(DepartmentId);
            var allRoles    = _personnelRolesService.GetRolesForDepartment(DepartmentId);
            var allProfiles = _userProfileService.GetAllProfilesForDepartment(DepartmentId);
            var allGroups   = _departmentGroupsService.GetAllGroupsForDepartment(DepartmentId);
            var units       = _unitsService.GetUnitsForDepartment(DepartmentId);
            var unitTypes   = _unitsService.GetUnitTypesForDepartment(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 = _usersService.GetUserByName(UserName);

            if (currentUser == null)
            {
                throw HttpStatusCode.Unauthorized.AsException();
            }

            var department = _departmentsService.GetDepartmentById(DepartmentId, false);

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

            var currentGroup = _departmentGroupsService.GetGroupForUser(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 = _unitsService.GetRolesForUnit(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 = _unitsService.GetAllLatestStatusForUnitsByDepartmentId(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 = _customStateService.GetAllActiveCustomStatesForDepartment(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 = _callsService.GetActiveCallsByDepartment(DepartmentId).OrderByDescending(x => x.LoggedOn);

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

                    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 = _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 CallResult();
                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(results);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Gets all the meta-data around a call, dispatched personnel, units, groups and responses
        /// </summary>
        /// <param name="callId">CallId to get data for</param>
        /// <returns></returns>
        public CallDataResult GetCallExtraData(int callId)
        {
            var result = new CallDataResult();

            var call       = _callsService.GetCallById(callId);
            var groups     = _departmentGroupsService.GetAllGroupsForDepartment(DepartmentId);
            var units      = _unitsService.GetUnitsForDepartment(call.DepartmentId);
            var unitStates = _unitsService.GetUnitStatesForCall(call.DepartmentId, callId).OrderBy(x => x.UnitId).OrderBy(y => y.Timestamp).ToList();
            var actionLogs = _actionLogsService.GetActionLogsForCall(call.DepartmentId, callId).OrderBy(x => x.UserId).OrderBy(y => y.Timestamp).ToList();
            var names      = _usersService.GetUserGroupAndRolesByDepartmentId(DepartmentId, true, true, true);
            var priority   = _callsService.GetCallPrioritesById(call.DepartmentId, call.Priority, false);

            if (priority != null)
            {
                result.Priority                         = new CallPriorityDataResult();
                result.Priority.Id                      = priority.DepartmentCallPriorityId;
                result.Priority.DepartmentId            = priority.DepartmentId;
                result.Priority.Name                    = priority.Name;
                result.Priority.Color                   = priority.Color;
                result.Priority.Sort                    = priority.Sort;
                result.Priority.IsDeleted               = priority.IsDeleted;
                result.Priority.IsDefault               = priority.IsDefault;
                result.Priority.DispatchPersonnel       = priority.DispatchPersonnel;
                result.Priority.DispatchUnits           = priority.DispatchUnits;
                result.Priority.ForceNotifyAllPersonnel = priority.ForceNotifyAllPersonnel;
                result.Priority.Tone                    = priority.Tone;
                result.Priority.IsSystemPriority        = priority.IsSystemPriority;
            }

            foreach (var actionLog in actionLogs)
            {
                var eventResult = new DispatchedEventResult();
                eventResult.Id        = actionLog.ActionLogId.ToString();
                eventResult.Timestamp = actionLog.Timestamp;
                eventResult.Type      = "User";

                var name = names.FirstOrDefault(x => x.UserId == actionLog.UserId);
                if (name != null)
                {
                    eventResult.Name = name.Name;

                    if (name.DepartmentGroupId.HasValue)
                    {
                        eventResult.GroupId = name.DepartmentGroupId.Value;
                        eventResult.Group   = name.DepartmentGroupName;
                    }
                }
                else
                {
                    eventResult.Name = "Unknown User";
                }

                eventResult.StatusId = actionLog.ActionTypeId;
                eventResult.Location = actionLog.GeoLocationData;
                eventResult.Note     = actionLog.Note;

                result.Activity.Add(eventResult);
            }

            foreach (var unitLog in unitStates)
            {
                var eventResult = new DispatchedEventResult();
                eventResult.Id        = unitLog.UnitStateId.ToString();
                eventResult.Timestamp = unitLog.Timestamp;
                eventResult.Type      = "Unit";
                eventResult.Name      = unitLog.Unit.Name;

                var group = groups.FirstOrDefault(x => x.DepartmentGroupId == unitLog.Unit.StationGroupId);
                if (group != null)
                {
                    eventResult.GroupId = group.DepartmentGroupId;
                    eventResult.Group   = group.Name;
                }

                eventResult.StatusId = eventResult.StatusId;
                eventResult.Location = eventResult.Location;
                eventResult.Note     = eventResult.Note;

                result.Activity.Add(eventResult);
            }

            foreach (var dispatch in call.Dispatches)
            {
                var eventResult = new DispatchedEventResult();
                eventResult.Id = dispatch.UserId;
                if (dispatch.LastDispatchedOn.HasValue)
                {
                    eventResult.Timestamp = dispatch.LastDispatchedOn.Value;
                }
                eventResult.Type = "User";

                var name = names.FirstOrDefault(x => x.UserId == dispatch.UserId);
                if (name != null)
                {
                    eventResult.Name = name.Name;

                    if (name.DepartmentGroupId.HasValue)
                    {
                        eventResult.GroupId = name.DepartmentGroupId.Value;
                        eventResult.Group   = name.DepartmentGroupName;
                    }
                }
                else
                {
                    eventResult.Name = "Unknown User";
                }

                result.Dispatches.Add(eventResult);
            }

            if (call.GroupDispatches != null && call.GroupDispatches.Any())
            {
                foreach (var groupDispatch in call.GroupDispatches)
                {
                    var eventResult = new DispatchedEventResult();
                    eventResult.Id = groupDispatch.DepartmentGroupId.ToString();
                    if (groupDispatch.LastDispatchedOn.HasValue)
                    {
                        eventResult.Timestamp = groupDispatch.LastDispatchedOn.Value;
                    }
                    eventResult.Type = "Group";

                    var name = groups.FirstOrDefault(x => x.DepartmentGroupId == groupDispatch.DepartmentGroupId);
                    if (name != null)
                    {
                        eventResult.Name    = name.Name;
                        eventResult.GroupId = name.DepartmentGroupId;
                        eventResult.Group   = name.Name;
                    }
                    else
                    {
                        eventResult.Name = "Unknown Group";
                    }

                    result.Dispatches.Add(eventResult);
                }
            }

            if (call.UnitDispatches != null && call.UnitDispatches.Any())
            {
                foreach (var unitDispatch in call.UnitDispatches)
                {
                    var eventResult = new DispatchedEventResult();
                    eventResult.Id = unitDispatch.UnitId.ToString();
                    if (unitDispatch.LastDispatchedOn.HasValue)
                    {
                        eventResult.Timestamp = unitDispatch.LastDispatchedOn.Value;
                    }
                    eventResult.Type = "Unit";

                    var unit = units.FirstOrDefault(x => x.UnitId == unitDispatch.UnitId);
                    if (unit != null)
                    {
                        eventResult.Name = unit.Name;

                        if (unit.StationGroupId.HasValue)
                        {
                            var group = groups.FirstOrDefault(x => x.DepartmentGroupId == unit.StationGroupId.GetValueOrDefault());
                            if (group != null)
                            {
                                eventResult.GroupId = group.DepartmentGroupId;
                                eventResult.Group   = group.Name;
                            }
                        }
                    }
                    else
                    {
                        eventResult.Name = "Unknown Unit";
                    }

                    result.Dispatches.Add(eventResult);
                }
            }

            return(result);
        }
Ejemplo n.º 10
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 = _userProfileService.GetProfileByUserId(userId);

            var id = new ClaimsIdentity(
                options.Cookies.ApplicationCookie.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);                // UserManager.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 = _departmentsService.GetDepartmentForUser(userName);

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

                    var group           = _departmentGroupsService.GetGroupForUser(user.Id, department.DepartmentId);
                    var departmentAdmin = department.IsUserAnAdmin(user.Id);
                    var permissions     = _permissionsService.GetAllPermissionsForDepartment(department.DepartmentId);
                    var roles           = _personnelRolesService.GetRolesForUser(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 = _departmentGroupsService.GetAllGroupsForDepartment(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);
        }
Ejemplo n.º 11
0
        public IActionResult GetPersonnelList(int linkId)
        {
            var link = _departmentLinksService.GetLinkById(linkId);

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

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

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

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

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

            var userStates = new List <UserState>();

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

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

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

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

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

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

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

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

                personnelViewModels.Add(personnelViewModel);
            }

            return(Json(personnelViewModels));
        }
Ejemplo n.º 12
0
        private List <FilterResult> GetFilterOptions()
        {
            var result = new List <FilterResult>();

            var stations = _departmentGroupsService.GetAllGroupsForDepartment(DepartmentId);
            var roles    = _personnelRolesService.GetRolesForDepartment(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);
        }
Ejemplo n.º 13
0
        public 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 = _departmentsService.GetDepartmentById(DepartmentId, false);
            var users      = _departmentsService.GetAllUsersForDepartment(DepartmentId);
            var groups     = _departmentGroupsService.GetAllDepartmentGroupsForDepartment(DepartmentId);
            var rolesForUsersInDepartment = _personnelRolesService.GetAllRolesForUsersInDepartment(DepartmentId);
            var allRoles      = _personnelRolesService.GetRolesForDepartment(DepartmentId);
            var allProfiles   = _userProfileService.GetAllProfilesForDepartment(DepartmentId);
            var allGroups     = _departmentGroupsService.GetAllGroupsForDepartment(DepartmentId);
            var units         = _unitsService.GetUnitsForDepartment(DepartmentId);
            var unitTypes     = _unitsService.GetUnitTypesForDepartment(DepartmentId);
            var callPriorites = _callsService.GetCallPrioritesForDepartment(DepartmentId);
            var callTypes     = _callsService.GetCallTypesForDepartment(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 = _unitsService.GetRolesForUnit(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 = _unitsService.GetAllLatestStatusForUnitsByDepartmentId(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 = _customStateService.GetAllActiveCustomStatesForDepartment(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);
        }
Ejemplo n.º 14
0
        public IActionResult NewGroup(NewGroupView model, IFormCollection collection)
        {
            model.Users  = _departmentsService.GetAllUsersForDepartment(DepartmentId);
            model.Groups = _departmentGroupsService.GetAllGroupsForDepartment(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 (_departmentGroupsService.IsUserInAGroup(groupUser, DepartmentId))
                {
                    var profile = _userProfileService.GetProfileByUserId(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);

                _departmentGroupsService.Save(model.NewGroup);

                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));
        }
Ejemplo n.º 15
0
        public 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>();

            var users  = _departmentsService.GetAllUsersForDepartment(DepartmentId);
            var groups = _departmentGroupsService.GetAllDepartmentGroupsForDepartment(DepartmentId);
            var rolesForUsersInDepartment = _personnelRolesService.GetAllRolesForUsersInDepartment(DepartmentId);
            var allRoles      = _personnelRolesService.GetRolesForDepartment(DepartmentId);
            var allProfiles   = _userProfileService.GetAllProfilesForDepartment(DepartmentId);
            var allGroups     = _departmentGroupsService.GetAllGroupsForDepartment(DepartmentId);
            var units         = _unitsService.GetUnitsForDepartment(DepartmentId);
            var unitTypes     = _unitsService.GetUnitTypesForDepartment(DepartmentId);
            var callPriorites = _callsService.GetCallPrioritesForDepartment(DepartmentId);

            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 = _usersService.GetUserByName(UserName);

            if (currentUser == null)
            {
                throw HttpStatusCode.Unauthorized.AsException();
            }

            var department = _departmentsService.GetDepartmentById(DepartmentId, false);

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

            var currentGroup = _departmentGroupsService.GetGroupForUser(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 = _customStateService.GetAllActiveCustomStatesForDepartment(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 = _departmentsService.GetAllDepartmentsForUser(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(results);
        }
Ejemplo n.º 16
0
        public 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         = _userProfileService.GetSelectedUserProfiles(item.CalendarItem.Attendees.Select(x => x.UserId).ToList());
                    var departmentNumber = _departmentSettingsService.GetTextToCallNumberForDepartment(item.CalendarItem.DepartmentId);
                    var department       = _departmentsService.GetDepartmentById(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);
                        _communicationService.SendNotification(person.UserId, item.CalendarItem.DepartmentId, message, departmentNumber, title, profile);
                    }
                }
                catch (Exception ex)
                {
                    success = false;
                    result  = ex.ToString();

                    Logging.LogException(ex);
                }

                _calendarService.MarkAsNotified(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         = _userProfileService.GetAllProfilesForDepartment(item.CalendarItem.DepartmentId);
                var departmentNumber = _departmentSettingsService.GetTextToCallNumberForDepartment(item.CalendarItem.DepartmentId);
                var department       = _departmentsService.GetDepartmentById(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)
                    {
                        _communicationService.SendNotification(profile.Key, item.CalendarItem.DepartmentId, message, departmentNumber, title, profile.Value);
                    }
                }
                else
                {
                    var groups = _departmentGroupsService.GetAllGroupsForDepartment(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))
                                    {
                                        _communicationService.SendNotification(member.UserId, item.CalendarItem.DepartmentId, message, departmentNumber, title, profiles[member.UserId]);
                                    }
                                    else
                                    {
                                        _communicationService.SendNotification(member.UserId, item.CalendarItem.DepartmentId, message, departmentNumber, title, null);
                                    }
                                }
                            }
                        }
                    }
                }

                _calendarService.MarkAsNotified(item.CalendarItem.CalendarItemId);
            }

            return(new Tuple <bool, string>(success, result));
        }
Ejemplo n.º 17
0
        private ClaimsPrincipal DressUpPrincipal(String userName)
        {
            if (String.IsNullOrWhiteSpace(userName))
            {
                return(null);
            }

            var identiy = new ResgridIdentity();

            _usersService = ServiceLocator.Current.GetInstance <IUsersService>();

            var user = _usersService.GetUserByName(userName);

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

            _departmentsService      = ServiceLocator.Current.GetInstance <IDepartmentsService>();
            _departmentGroupsService = ServiceLocator.Current.GetInstance <IDepartmentGroupsService>();
            _userProfileService      = ServiceLocator.Current.GetInstance <IUserProfileService>();
            _permissionsService      = ServiceLocator.Current.GetInstance <IPermissionsService>();
            _personnelRolesService   = ServiceLocator.Current.GetInstance <IPersonnelRolesService>();

            var profile = _userProfileService.GetProfileByUserId(user.UserId);

            string fullName = String.Empty;

            if (profile == null || String.IsNullOrWhiteSpace(profile.FirstName))
            {
                var pfile = ProfileBase.Create(user.UserName, true);
                fullName = pfile.GetPropertyValue("Name").ToString();
            }
            else
            {
                fullName = string.Format("{0} {1}", profile.FirstName, profile.LastName);
            }

            identiy.FullName = fullName;
            identiy.UserName = userName;
            identiy.UserId   = user.UserId;

            if (_usersService.IsUserInRole(user.UserId, _usersService.AdminRoleId))
            {
                identiy.AddSystemAdminClaims(userName, user.UserId, fullName);
            }
            else if (_usersService.IsUserInRole(user.UserId, _usersService.AffiliateRoleId))
            {
                identiy.AddAffiliteClaims(userName, user.UserId, fullName);
            }
            else
            {
                var department = _departmentsService.GetDepartmentForUser(userName);

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

                var group           = _departmentGroupsService.GetGroupForUser(user.UserId, department.DepartmentId);
                var departmentAdmin = department.IsUserAnAdmin(user.UserId);
                var permissions     = _permissionsService.GetAllPermissionsForDepartment(department.DepartmentId);
                var roles           = _personnelRolesService.GetRolesForUser(user.UserId, department.DepartmentId);

                identiy.AddDepartmentClaim(department.DepartmentId, departmentAdmin);
                identiy.DepartmentName = department.Name;

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

                identiy.DepartmentId = department.DepartmentId;

                string email = String.Empty;

                if (profile != null && !String.IsNullOrWhiteSpace(profile.MembershipEmail))
                {
                    email = profile.MembershipEmail;
                }
                else if (!String.IsNullOrWhiteSpace(user.Email))
                {
                    email = user.Email;
                }

                identiy.AddGeneralClaims(userName, user.UserId, fullName, department.DepartmentId, department.Name, email, signupDate);

                bool isGroupAdmin = false;

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

                if (departmentAdmin)
                {
                    var groups = _departmentGroupsService.GetAllGroupsForDepartment(department.DepartmentId);
                    if (groups != null)
                    {
                        foreach (var departmentGroup in groups)
                        {
                            identiy.AddGroupClaim(departmentGroup.DepartmentGroupId, true);
                        }
                    }
                }
                else
                {
                    if (group != null)
                    {
                        identiy.AddGroupClaim(group.DepartmentGroupId, isGroupAdmin);
                    }
                }

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

            return(new ClaimsPrincipal(identiy));
        }