private void PopulateLogViewModel(NewLogView model) { model.Department = _departmentsService.GetDepartmentByUserId(UserId); model.User = _usersService.GetUserById(UserId); model.Types = model.LogType.ToSelectList(); model.CallPriorities = model.CallPriority.ToSelectList(); model.Users.Add(String.Empty, "Not Applicable"); model.SetUsers(_departmentsService.GetAllUsersForDepartment(DepartmentId)); var groups = new List <DepartmentGroup>(); groups.Add(new DepartmentGroup { Name = "Not Applicable" }); groups.AddRange(_departmentGroupsService.GetAllStationGroupsForDepartment(DepartmentId)); model.Stations = groups; List <CallType> types = new List <CallType>(); types.Add(new CallType { CallTypeId = 0, Type = "No Type" }); types.AddRange(_callsService.GetCallTypesForDepartment(DepartmentId)); model.CallTypes = new SelectList(types, "Type", "Type"); }
public IActionResult New() { var model = new NewCommandView(); model.Command = new CommandDefinition(); model.CallTypes = _callsService.GetCallTypesForDepartment(DepartmentId); var types = new List <CallType>(); types.Add(new CallType() { Type = "Any Call Type" }); types.AddRange(model.CallTypes); model.Types = new SelectList(types, "CallTypeId", "Type"); return(View(model)); }
public IActionResult New() { var model = new NewTemplateModel(); model.Template = new CallQuickTemplate(); var priorites = _callsService.GetCallPrioritesForDepartment(DepartmentId); model.CallPriorities = new SelectList(priorites, "DepartmentCallPriorityId", "Name", priorites.FirstOrDefault(x => x.IsDefault)); List <CallType> types = new List <CallType>(); types.Add(new CallType { CallTypeId = 0, Type = "No Type" }); types.AddRange(_callsService.GetCallTypesForDepartment(DepartmentId)); model.CallTypes = new SelectList(types, "Type", "Type"); return(View(model)); }
public IActionResult New() { var model = new NewProtocolModel(); model.Protocol = new DispatchProtocol(); var priorites = _callsService.GetCallPrioritesForDepartment(DepartmentId); model.CallPriorities = new SelectList(priorites, "DepartmentCallPriorityId", "Name", priorites.FirstOrDefault(x => x.IsDefault)); List <CallType> types = new List <CallType>(); types.Add(new CallType { CallTypeId = 0, Type = "No Type" }); types.AddRange(_callsService.GetCallTypesForDepartment(DepartmentId)); model.CallTypes = new SelectList(types, "Type", "Type"); model.TriggerTypes = model.TriggerTypesEnum.ToSelectList(); return(View(model)); }
public HttpResponseMessage SaveCall([FromBody] NewCallInput newCallInput) { if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } var call = new Call { DepartmentId = DepartmentId, ReportingUserId = UserId, Priority = (int)Enum.Parse(typeof(CallPriority), newCallInput.Pri), Name = newCallInput.Nme, NatureOfCall = newCallInput.Noc }; if (!string.IsNullOrWhiteSpace(newCallInput.CNme)) { call.ContactName = newCallInput.CNme; } if (!string.IsNullOrWhiteSpace(newCallInput.CNum)) { call.ContactName = newCallInput.CNum; } if (!string.IsNullOrWhiteSpace(newCallInput.Cid)) { call.IncidentNumber = newCallInput.Cid; } if (!string.IsNullOrWhiteSpace(newCallInput.Add)) { call.Address = newCallInput.Add; } if (!string.IsNullOrWhiteSpace(newCallInput.W3W)) { call.W3W = newCallInput.W3W; } //if (call.Address.Equals("Current Coordinates", StringComparison.InvariantCultureIgnoreCase)) // call.Address = ""; if (!string.IsNullOrWhiteSpace(newCallInput.Not)) { call.Notes = newCallInput.Not; } if (!string.IsNullOrWhiteSpace(newCallInput.Geo)) { call.GeoLocationData = newCallInput.Geo; } 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 = _geoLocationProvider.GetCoordinatesFromW3W(call.W3W); if (coords != null) { call.GeoLocationData = $"{coords.Latitude},{coords.Longitude}"; } } call.LoggedOn = DateTime.UtcNow; if (!String.IsNullOrWhiteSpace(newCallInput.Typ) && newCallInput.Typ != "No Type") { var callTypes = _callsService.GetCallTypesForDepartment(DepartmentId); var type = callTypes.FirstOrDefault(x => x.Type == newCallInput.Typ); if (type != null) { call.Type = type.Type; } } var users = _departmentsService.GetAllUsersForDepartment(DepartmentId); call.Dispatches = new Collection <CallDispatch>(); call.GroupDispatches = new List <CallDispatchGroup>(); call.RoleDispatches = new List <CallDispatchRole>(); if (string.IsNullOrWhiteSpace(newCallInput.Dis) || newCallInput.Dis == "0") { // Use case, existing clients and non-ionic2 app this will be null dispatch all users. Or we've specified everyone (0). foreach (var u in users) { var cd = new CallDispatch { UserId = u.UserId }; call.Dispatches.Add(cd); } } else { var dispatch = newCallInput.Dis.Split(char.Parse("|")); try { var usersToDispatch = dispatch.Where(x => x.StartsWith("P:")).Select(y => y.Replace("P:", "")); foreach (var user in usersToDispatch) { var cd = new CallDispatch { UserId = user }; call.Dispatches.Add(cd); } } catch (Exception ex) { Logging.LogException(ex); } try { var groupsToDispatch = dispatch.Where(x => x.StartsWith("G:")).Select(y => int.Parse(y.Replace("G:", ""))); foreach (var group in groupsToDispatch) { var cd = new CallDispatchGroup { DepartmentGroupId = group }; call.GroupDispatches.Add(cd); } } catch (Exception ex) { Logging.LogException(ex); } try { var rolesToDispatch = dispatch.Where(x => x.StartsWith("R:")).Select(y => int.Parse(y.Replace("R:", ""))); foreach (var role in rolesToDispatch) { var cd = new CallDispatchRole { RoleId = role }; call.RoleDispatches.Add(cd); } } catch (Exception ex) { Logging.LogException(ex); } } var savedCall = _callsService.SaveCall(call); OutboundEventProvider.CallAddedTopicHandler handler = new OutboundEventProvider.CallAddedTopicHandler(); handler.Handle(new CallAddedEvent() { DepartmentId = DepartmentId, Call = savedCall }); var profiles = new List <string>(); if (call.Dispatches != null && call.Dispatches.Any()) { profiles.AddRange(call.Dispatches.Select(x => x.UserId).ToList()); } if (call.GroupDispatches != null && call.GroupDispatches.Any()) { foreach (var groupDispatch in call.GroupDispatches) { var group = _departmentGroupsService.GetGroupById(groupDispatch.DepartmentGroupId); if (group != null && group.Members != null) { profiles.AddRange(group.Members.Select(x => x.UserId)); } } } if (call.RoleDispatches != null && call.RoleDispatches.Any()) { foreach (var roleDispatch in call.RoleDispatches) { var members = _personnelRolesService.GetAllMembersOfRole(roleDispatch.RoleId); if (members != null) { profiles.AddRange(members.Select(x => x.UserId).ToList()); } } } var cqi = new CallQueueItem(); cqi.Call = savedCall; cqi.Profiles = _userProfileService.GetSelectedUserProfiles(profiles); _queueService.EnqueueCallBroadcast(cqi); return(Request.CreateResponse(HttpStatusCode.Created)); }
public UnitAppPayloadResult GetUnitAppCoreData() { 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>(); results.Priorities = new List <CallPriorityResult>(); results.Departments = new List <JoinedDepartmentResult>(); results.CallTypes = new List <CallTypeResult>(); 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); } 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; 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); } } var calls = _callsService.GetActiveCallsByDepartment(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 = _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; c.Protocols = _callsService.GetCallProtocolsByCallId(c.CallId); call.Protocols = new List <CallProtocolResult>(); if (c.Protocols != null && c.Protocols.Any()) { foreach (var protocol in c.Protocols) { var p = new CallProtocolResult(); p.Id = protocol.DispatchProtocolId; p.Code = protocol.Protocol.Code; p.Name = protocol.Protocol.Name; call.Protocols.Add(p); } } 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); } 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); } 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); }
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); }