public HttpResponseMessage GetResource(Guid resourceId, Guid resourceGroupId)
        {
            try
            {
                if (!Common.HasGroupReadPermission(resourceGroupId))
                    Request.CreateResponse(HttpStatusCode.Unauthorized, new { Message =App_GlobalResources.Errors.ErrorNotAuthorized });

                ResourceViewModel resource;

                if (resourceId.Equals(Guid.Empty))
                    resource = new ResourceViewModel
                    {
                        ResourceId = resourceId,
                        ResourceGroupId = resourceGroupId,
                        ResourceGroupName = GroupRepository.Instance.GetGroup(resourceGroupId).ResourceName,
                        ResourceKey = string.Empty,
                        ResourceValue = string.Empty
                    };
                else
                {
                    resource = new ResourceViewModel(_repository.GetResource(resourceId), ActiveModule.ModuleID, true);

                    Components.Common.WritteEventLog($"{App_GlobalResources.Errors.Decrypted} '{resource.ResourceKey}' {App_GlobalResources.Errors.By} {Common.CurrentUser.Username} ({Common.CurrentUser.DisplayName})", EventLogController.EventLogType.ADMIN_ALERT);
                }

                return Request.CreateResponse(HttpStatusCode.OK, new
                {
                    Success = true,
                    Resource = resource,
                    ResourceEncriptedValue = UrlUtils.EncryptParameter(resource.ResourceValue, Common.GetDecryptionKey()),
                    PostBackUrl = Components.Common.GroupsUrl(ActiveModule.ModuleID)
                });
            }
            catch (Exception)
            {
                return Request.CreateResponse(HttpStatusCode.InternalServerError, App_GlobalResources.Errors.ErrorGeneric);
            }
        }
        public HttpResponseMessage Save(ResourceViewModel viewModel)
        {
            try
            {
                if (!Common.HasGroupWritePermission(viewModel.ResourceGroupId))
                    return Request.CreateResponse(HttpStatusCode.Unauthorized, new { Message =App_GlobalResources.Errors.ErrorNotAuthorized });

                var reg = new Regex(@"<script[^>]*>[\s\S]*?</script>");

                viewModel.ResourceValue = reg.Replace(viewModel.ResourceValue, "");

                return Request.CreateResponse(HttpStatusCode.OK, new
                {
                    Success = true,
                    Resource = viewModel.ResourceId.Equals(Guid.Empty)
                    ? new ResourceViewModel(_repository.GetResource(_repository.Create(CreateResource(viewModel)).ResourceId), ActiveModule.ModuleID, true)
                    : new ResourceViewModel(_repository.GetResource(_repository.Update(UpdateResource(viewModel)).ResourceId), ActiveModule.ModuleID, true)
                });
            }
            catch (Exception)
            {
                return Request.CreateResponse(HttpStatusCode.InternalServerError, App_GlobalResources.Errors.ErrorGeneric);
            }
        }
 public HttpResponseMessage Delete(ResourceViewModel viewModel)
 {
     try
     {
         return !Common.HasGroupWritePermission(viewModel.ResourceGroupId) 
             ? Request.CreateResponse(HttpStatusCode.Unauthorized, new { Message = App_GlobalResources.Errors.ErrorNotAuthorized }) 
             : Request.CreateResponse(HttpStatusCode.OK, new { Success = _repository.Delete(viewModel.ResourceId) });
     }
     catch (Exception)
     {
         return Request.CreateResponse(HttpStatusCode.InternalServerError, App_GlobalResources.Errors.ErrorGeneric);
     }
 }
 /// <summary>
 /// Upgrade a resource of resources.
 /// </summary>
 /// <param name="viewModel">Upgrade a resource of resources.</param>
 /// <returns></returns>
 private static Resource UpdateResource(ResourceViewModel viewModel)
 {
     return new Resource
     {
         ResourceId = viewModel.ResourceId,
         ResourceGroupId = viewModel.ResourceGroupId,
         ResourceKey = UrlUtils.EncryptParameter(viewModel.ResourceKey, Common.GetDecryptionKey()),
         ResourceValue = string.IsNullOrEmpty(viewModel.ResourceValue) ? string.Empty : UrlUtils.EncryptParameter(viewModel.ResourceValue, Common.GetDecryptionKey())
     };
 }