Ejemplo n.º 1
0
        public async Task <IActionResult> PutGroupRight([FromRoute] int id, [FromBody] GroupRight groupRight)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != groupRight.GroupRightId)
            {
                return(BadRequest());
            }

            _context.Entry(groupRight).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GroupRightExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public JsonResult RemoveUserGroupRight(AddRolesRight addRolesRight)
        {
            if (!ModelState.IsValid)
            {
                string result = "<div class=\"alert alert-warning\">Not Allowed!</ div > ";
                return(Json(result));
            }
            else
            {
                GroupRight groupRight = new GroupRight()
                {
                    ActionId   = addRolesRight.ActionId,
                    UserRoleId = addRolesRight.UserRoleId,
                    TimeAdded  = addRolesRight.dateAdded,
                    Status     = addRolesRight.Status
                };
                GroupRight gr = db.GroupRights.Where(p => p.ActionId == groupRight.ActionId && p.UserRoleId == groupRight.UserRoleId).FirstOrDefault();


                if (gr != null)
                {
                    db.GroupRights.Remove(gr);
                    db.SaveChanges();
                    string result = "<div class=\"alert alert-success\"> <b>Successful!!</b><br/> Role Removed Successfully</ div > ";
                    return(Json(result));
                }
                else
                {
                    string result = "<div class=\"alert alert-warning\">Role Doesnt Exist</ div > ";
                    return(Json(result));
                }
            }
        }
        public ActionResult SaveGroupUserRight(AddRolesRight addRolesRight)
        {
            addRolesRight.dateAdded = DateTime.Now.Date;
            if (!ModelState.IsValid)
            {
                string result = "<div class=\"alert alert-warning\">Not Allowed!</ div > ";
                return(Json(result));
            }
            else
            {
                GroupRight groupRight = new GroupRight()
                {
                    ActionId   = addRolesRight.ActionId,
                    UserRoleId = addRolesRight.UserRoleId,
                    TimeAdded  = addRolesRight.dateAdded,
                    Status     = addRolesRight.Status
                };
                GroupRight gr = db.GroupRights.Where(p => p.ActionId == groupRight.ActionId && p.UserRoleId == groupRight.UserRoleId).FirstOrDefault();

                if (gr == null)
                {
                    db.GroupRights.Add(groupRight);
                    db.SaveChanges();
                    string result = "<div class=\"alert alert-success\"> <b>Successful!!</b><br/> Role Assigned </ div > ";
                    return(Json(result));
                }
                else
                {
                    string result = "<div class=\"alert alert-warning\">Role Already Assigned </ div > ";
                    return(Json(result));
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets the current users department rights
        /// </summary>
        /// <returns>DepartmentRightsResult object with the department rights and group memberships</returns>
        public DepartmentRightsResult GetCurrentUsersRights()
        {
            var result               = new DepartmentRightsResult();
            var department           = _departmentsService.GetDepartmentById(DepartmentId, false);
            var departmentMembership = _departmentsService.GetDepartmentMember(UserId, DepartmentId, false);
            var roles = _personnelRolesService.GetRolesForUser(UserId, DepartmentId);

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

            if (departmentMembership.IsAdmin.HasValue)
            {
                result.Adm = departmentMembership.IsAdmin.Value;
            }

            if (department.ManagingUserId == UserId)
            {
                result.Adm = true;
            }

            bool isGroupAdmin = false;

            result.Grps = new List <GroupRight>();

            var group = _departmentGroupsService.GetGroupForUser(UserId, DepartmentId);

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

                if (groupRight.Adm)
                {
                    isGroupAdmin = true;
                }

                result.Grps.Add(groupRight);
            }

            var createCallPermission    = _permissionsService.GetPermisionByDepartmentType(DepartmentId, PermissionTypes.CreateCall);
            var viewPIIPermission       = _permissionsService.GetPermisionByDepartmentType(DepartmentId, PermissionTypes.ViewPersonalInfo);
            var createNotePermission    = _permissionsService.GetPermisionByDepartmentType(DepartmentId, PermissionTypes.CreateNote);
            var createMessagePermission = _permissionsService.GetPermisionByDepartmentType(DepartmentId, PermissionTypes.CreateMessage);

            result.VPii = _permissionsService.IsUserAllowed(viewPIIPermission, result.Adm, isGroupAdmin, roles);
            result.CCls = _permissionsService.IsUserAllowed(createCallPermission, result.Adm, isGroupAdmin, roles);
            result.ANot = _permissionsService.IsUserAllowed(createNotePermission, result.Adm, isGroupAdmin, roles);
            result.CMsg = _permissionsService.IsUserAllowed(createMessagePermission, result.Adm, isGroupAdmin, roles);

            if (!String.IsNullOrWhiteSpace(Config.FirebaseConfig.ResponderJsonFile) && !String.IsNullOrWhiteSpace(Config.FirebaseConfig.ResponderProjectEmail))
            {
                result.FirebaseApiToken = _firebaseService.CreateToken(UserId, null);
            }

            return(result);
        }
 /// <summary>
 /// Добавить право в группу по идентификатору права и группы
 /// </summary>
 /// <param name="rightId">Ид права</param>
 /// <param name="groupId">Ид группы</param>
 /// <returns></returns>
 public async Task AddRightToGroup(Guid rightId, Guid groupId)
 {
     var groupRight = new GroupRight
     {
         GroupId = groupId,
         RightId = rightId
     };
     await _context.AddAsync <GroupRight>(groupRight);
 }
Ejemplo n.º 6
0
        public async Task <IActionResult> PostGroupRight([FromBody] GroupRight groupRight)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.GroupRights.Add(groupRight);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetGroupRight", new { id = groupRight.GroupRightId }, groupRight));
        }
        public GroupRight AddGroupRight(string groupName, string rightName, string resource, bool status)
        {
            var groupRight = new GroupRight
            {
                GroupName  = groupName,
                RightName  = rightName,
                ResourceId = resource,
                Status     = status
            };

            _dataManager.Insert <GroupRight>(groupRight);

            return(groupRight);
        }
        public ActionResult SaveGroupUserRightRefined(AddRolesRightRefined addRolesRightRefined)
        {
            if (!ModelState.IsValid)
            {
                string result = "<div class=\"alert alert-warning\">Not Allowed!</ div > ";
                return(Json(result));
            }
            else
            {
                var roleExists = false;

                GroupRight groupRight = new GroupRight()
                {
                    ActionId    = 0,
                    RoleRightId = addRolesRightRefined.RoleRightId,
                    UserRoleId  = addRolesRightRefined.UserRoleId,
                    TimeAdded   = DateTime.Now,
                    Status      = addRolesRightRefined.Status
                };

                roleExists = db.GroupRights.Any(p => p.RoleRightId == addRolesRightRefined.RoleRightId);



                if (!roleExists)
                {
                    db.GroupRights.Add(groupRight);
                    db.SaveChanges();
                    string result = "<div class=\"alert alert-success\"> <b>Successful!!</b><br/> Role Assigned </ div > ";
                    return(Json(result));
                }
                else
                {
                    string result = "<div class=\"alert alert-warning\">Role Already Assigned </ div > ";
                    return(Json(result));
                }
            }
        }
Ejemplo n.º 9
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.º 10
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);
        }