Ejemplo n.º 1
0
        public async Task <HttpResponseMessage> UpdateSPRole([ModelBinder(typeof(IocCustomCreationConverter))] ISPRole roleEntity)
        {
            try
            {
                var permissionsEntity = roleEntity.SPRolePermissions;
                var updationResponse  = await roleService.UpdateRole(roleEntity);

                if (updationResponse == false)
                {
                    return(CreateHttpResponse <ISPRole>(HttpStatusCode.Accepted, HttpCustomStatus.Success, null, GetLocalisedString("msgRoleDuplicate")));
                }

                foreach (var item in permissionsEntity)
                {
                    item.RoleId = roleEntity.Id;
                    await rolePermissionService.UpdatePermission(item);
                }

                return(CreateHttpResponse <ISPRole>(HttpStatusCode.OK, HttpCustomStatus.Success, null, GetLocalisedString("msgRoleUpdation")));
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                return(CreateHttpResponse <ISPRole>(HttpStatusCode.InternalServerError, HttpCustomStatus.Failure, null, GetLocalisedString("msgWebServiceError")));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Edit Role
        /// </summary>
        /// <param name="role">The role</param>
        /// <returns>ISP Role</returns>
        public async Task <bool> UpdateRole(ISPRole role)
        {
            var result  = sproleFeatureDataService.DeleteExistingRolePermissions(role.Id);
            var success = await sproleDataService.EditRole(role);

            var permissions = role.SPRolePermissions;

            foreach (var item in permissions)
            {
                item.RoleId = role.Id;
                sproleFeatureDataService.CreateRolePermission(item);
            }

            return(success);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Edits the SP role.
        /// </summary>
        /// <param name="role">The role.</param>
        /// <returns>
        /// boolean value
        /// </returns>
        public async Task <bool> EditRole(ISPRole role)
        {
            try
            {
                bool exists = false;

                var roleList = new List <ISPRole>(await roles.GetAllAsync());
                if (roleList.Count() > 1)
                {
                    var item = roleList.FirstOrDefault(x => x.Id == role.Id);
                    roleList.Remove(item);
                    exists = roleList.Where(x => x.RoleName.Trim().ToLower() == role.RoleName.Trim().ToLower()).Any();
                }

                if (!exists)
                {
                    var roleEntity = await roles.GetByIdAsync(role.Id);

                    roleEntity.Id                = role.Id;
                    roleEntity.RoleName          = role.RoleName;
                    roleEntity.SPRolePermissions = role.SPRolePermissions;
                    roleEntity.ActiveStatus      = role.ActiveStatus;
                    roleEntity.Description       = role.Description;
                    roleEntity.EditedDate        = role.EditedDate;
                    roleEntity.FeatureId         = role.FeatureId;
                    roleEntity.HierarchyId       = role.HierarchyId;
                    roles.Update(roleEntity);
                    var updatedrole = UnitOfWork.Commit();
                    return(true);
                }

                return(false);
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                throw ex;
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Creates the role.
 /// </summary>
 /// <param name="role">The role.</param>
 /// <returns>
 /// ISP Role
 /// </returns>
 public ISPRole CreateRole(ISPRole role)
 {
     try
     {
         var exists = roles.Entities
                      .Where(x => (x.RoleName.Trim().ToLower() == role.RoleName && x.HierarchyId == role.HierarchyId))
                      .Any();
         if (!exists)
         {
             var savedRole = roles.Add(role);
             UnitOfWork.Commit();
             return(savedRole);
         }
         else
         {
             return(null);
         }
     }
     catch (Exception ex)
     {
         logger.Error(ex.Message);
         throw ex;
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Create Role
 /// </summary>
 /// <param name="role">The role</param>
 /// <returns>ISP Role</returns>
 public ISPRole CreateRole(ISPRole role)
 {
     role.CreatedDate = DateTime.Now;
     role.EditedDate  = DateTime.Now;
     return(sproleDataService.CreateRole(role));
 }