ErrorResponse object that will be sent to the client for all the errors that are generated in the service
        public void OnException(ExceptionContext context)
        {
            this._logger.LogError("MatterCenterExceptionFilter", context.Exception);
            var stackTrace = new StackTrace(context.Exception, true);
            StackFrame stackFrameInstance = null;

            if(stackTrace.GetFrames().Length>0)
            {
                for(int i=0; i< stackTrace.GetFrames().Length; i++)
                {
                    if(stackTrace.GetFrames()[i].ToString().Contains("Microsoft.Legal.Matter"))
                    {
                        stackFrameInstance = stackTrace.GetFrames()[i];
                        break;
                    }
                }
            }

            var response = new ErrorResponse()
            {
                Message = context.Exception.Message,
                StackTrace = context.Exception.ToString(),
                Description = "Error occured in the system. Please contact the administrator",
                //Exception = context.Exception.ToString(),
                LineNumber = stackFrameInstance?.GetFileLineNumber(),
                MethodName = stackFrameInstance?.GetMethod().Name,
                ClassName = stackFrameInstance?.GetMethod().DeclaringType.Name,
                ErrorCode = ((int)HttpStatusCode.InternalServerError).ToString()
            };
            context.Result = new ObjectResult(response)
            {
                StatusCode = (int)HttpStatusCode.InternalServerError,
                DeclaredType = typeof(ErrorResponse)                
            };
        }
 /// <summary>
 /// Function to validate client information
 /// </summary>
 /// <param name="client">Client object</param>
 /// <param name="methodNumber">Number indicating which method needs to be validated</param>
 /// <returns>ErrorResponse that contains error message with error code</returns>
 internal static ErrorResponse ValidateClientInformation(Client client, int methodNumber)
 {
     ErrorResponse errorResponse = new ErrorResponse();
     if (string.IsNullOrWhiteSpace(client.Url))
     {                
         errorResponse.ErrorCode = ErrorSettings.IncorrectInputClientUrlCode;
         errorResponse.Message = ErrorSettings.IncorrectInputClientUrlMessage;                
     }
     //else if (int.Parse(ConstantStrings.ProvisionMatterCreateMatter, CultureInfo.InvariantCulture) == methodNumber || 
     //    int.Parse(ConstantStrings.ProvisionMatterAssignContentType, CultureInfo.InvariantCulture) == methodNumber || 
     //    int.Parse(ConstantStrings.ProvisionMatterUpdateMetadataForList, CultureInfo.InvariantCulture) == methodNumber)
     //{
     //    if (string.IsNullOrWhiteSpace(client.Id))
     //    {
     //        result = string.Format(CultureInfo.InvariantCulture, ConstantStrings.ServiceResponse, 
     //            TextConstants.IncorrectInputClientIdCode, TextConstants.IncorrectInputClientIdMessage);
     //    }
     //    else if (string.IsNullOrWhiteSpace(client.Name))
     //    {
     //        result = string.Format(CultureInfo.InvariantCulture, 
     //            ConstantStrings.ServiceResponse, TextConstants.IncorrectInputClientNameCode, 
     //            TextConstants.IncorrectInputClientNameMessage);
     //    }
     //}
     return errorResponse;
 }
예제 #3
0
        /// <summary>
        /// This method will generate error response that will be sent to the client
        /// </summary>
        /// <param name="ex">Exception object that occured </param>
        /// <returns></returns>
        public ErrorResponse GenerateErrorResponse(Exception ex)
        {
            var stackTrace = new StackTrace(ex, true);
            StackFrame stackFrameInstance = null;

            if (stackTrace.GetFrames().Length > 0)
            {
                for (int i = 0; i < stackTrace.GetFrames().Length; i++)
                {
                    if (stackTrace.GetFrames()[i].ToString().Contains("Microsoft.Legal.Matter"))
                    {
                        stackFrameInstance = stackTrace.GetFrames()[i];
                        break;
                    }
                }
            }
            //Create custom exception response that needs to be send to client
            var response = new ErrorResponse()
            {
                Message = ex.Message,
                StackTrace = ex.StackTrace.ToString(),
                Description = "Error occured in the system. Please contact the administrator",
                Exception = ex,
                LineNumber = stackFrameInstance?.GetFileLineNumber(),
                MethodName = stackFrameInstance?.GetMethod().Name,
                ClassName = stackFrameInstance?.GetMethod().DeclaringType.Name,
                ErrorCode = ((int)HttpStatusCode.InternalServerError).ToString(),
                IsErrror = true
            };
            return response;
        }
 public async Task Invoke(HttpContext context)
 {
     if(!context.Request.Headers.Keys.Contains("Authorization"))
     {
         var response = new ErrorResponse()
         {
             Message = "UnAuthorized",                    
             Description = "The request object doesnot contain any authorization header",
             ErrorCode = "401",
             IsTokenValid = false
         };
         string message = JsonConvert.SerializeObject(response);
         context.Response.StatusCode = 401;
         await context.Response.WriteAsync(message);
         return;
     }
     string authorization = context.Request.Headers["Authorization"];
     if(!ValidateToken(authorization))
     {
         var response = new ErrorResponse()
         {
             Message = "UnAuthorized",
             Description = "The authorization header contains invalid token",
             ErrorCode = "401",
             IsTokenValid = false
         };
         string message = JsonConvert.SerializeObject(response);
         context.Response.StatusCode = 401;
         await context.Response.WriteAsync(message);
         return;
     }
     await _next.Invoke(context);
 }
        /// <summary>
        /// Implement OnException method of IExceptionFilter which will be invoked
        /// for all unhandled exceptions
        /// </summary>
        /// <param name="context"></param>
        public void OnException(ExceptionContext context)
        {
            this._logger.LogError("MatterCenterExceptionFilter", context.Exception);
            var stackTrace = new StackTrace(context.Exception, true);
            StackFrame stackFrameInstance = null;

            if(stackTrace.GetFrames().Length>0)
            {
                for(int i=0; i< stackTrace.GetFrames().Length; i++)
                {
                    if(stackTrace.GetFrames()[i].ToString().Contains("Microsoft.Legal.Matter"))
                    {
                        stackFrameInstance = stackTrace.GetFrames()[i];
                        break;
                    }
                }
            }
            //Create custom exception response that needs to be send to client
            var response = new ErrorResponse()
            {
                Message = context.Exception.Message,
                StackTrace = context.Exception.ToString(),
                Description = "Error occured in the system. Please contact the administrator",
                //Exception = context.Exception.ToString(),
                LineNumber = stackFrameInstance?.GetFileLineNumber(),
                MethodName = stackFrameInstance?.GetMethod().Name,
                ClassName = stackFrameInstance?.GetMethod().DeclaringType.Name,
                ErrorCode = ((int)HttpStatusCode.InternalServerError).ToString()
            };

            //Create properties that need to be added to application insights
            var properties = new Dictionary<string, string>();
            properties.Add("StackTrace", response.StackTrace);
            properties.Add("LineNumber", response.LineNumber.ToString());
            properties.Add("MethodName", response.MethodName.ToString());
            properties.Add("ClassName", response.ClassName.ToString());
            properties.Add("ErrorCode", response.ErrorCode.ToString());           

            //Create Telemetry object to add exception to the application insights
            var ai = new TelemetryClient();
            ai.InstrumentationKey = instrumentationKey;
            if(ai.IsEnabled())
            {
                //add exception to the Application Insights
                ai.TrackException(context.Exception, properties);
            }           
            
            //Send the exceptin object to the client
            context.Result = new ObjectResult(response)
            {
                StatusCode = (int)HttpStatusCode.InternalServerError,
                DeclaredType = typeof(ErrorResponse)                
            };
        }
 /// <summary>
 /// This method will validate the client object and if there are any errors in the client inout object, the method will
 /// return ErrorResponse object or it will return null
 /// </summary>
 /// <param name="client">Contains the information such as ClientId, ClientUrl etc</param>
 /// <returns>ErrorResponse</returns>
 internal static ErrorResponse TaxonomyValidation(Client client)
 {
     if(client!=null)
     {
         return ValidateClientInformation(client, 0);
     }
     else
     {
         ErrorResponse errorResponse = new ErrorResponse();
         errorResponse.ErrorCode = "";
         errorResponse.Message = ErrorSettings.MessageNoInputs;
         return errorResponse;
     }
     return null;
 }
예제 #7
0
 /// <summary>
 /// unpin the matter
 /// </summary>        
 /// <param name="client">Client object containing Client data</param>
 /// <param name="details">Term Store object containing Term store data</param>
 /// <returns>Returns JSON object to the client</returns>        ///
 public async Task<IActionResult> GetRoles([FromBody]Client client)
 {
     try
     {
         spoAuthorization.AccessToken = HttpContext.Request.Headers["Authorization"];
         #region Error Checking                
         ErrorResponse errorResponse = null;
         //if the token is not valid, immediately return no authorization error to the user
         if (errorResponse != null && !errorResponse.IsTokenValid)
         {
             return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.Unauthorized);
         }
         if (client == null)
         {
             errorResponse = new ErrorResponse()
             {
                 Message = errorSettings.MessageNoInputs,
                 ErrorCode = HttpStatusCode.BadRequest.ToString(),
                 Description = "No input data is passed"
             };
             return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.BadRequest);
         }
         #endregion
         IList<Role> roles = new List<Role>();
         string result = ServiceUtility.GetDataFromAzureRedisCache(ServiceConstants.CACHE_ROLES);
         if (string.IsNullOrEmpty(result))
         {
             roles = await matterRepositoy.GetRolesAsync(client);
             ServiceUtility.SetDataIntoAzureRedisCache<IList<Role>>(ServiceConstants.CACHE_ROLES, roles);
         }
         else
         {
             roles = JsonConvert.DeserializeObject<IList<Role>>(result);
         }
         return matterCenterServiceFunctions.ServiceResponse(roles, (int)HttpStatusCode.OK);
     }
     catch (Exception ex)
     {
         customLogger.LogError(ex, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
         throw;
     }
 }
예제 #8
0
        /// <summary>
        /// unpin the matter
        /// </summary>        
        /// <param name="client">Client object containing Client data</param>
        /// <param name="details">Term Store object containing Term store data</param>
        /// <returns>Returns JSON object to the client</returns>        ///
        public async Task<IActionResult> GetPin([FromBody]Client client)
        {
            try
            {
                spoAuthorization.AccessToken = HttpContext.Request.Headers["Authorization"];
                #region Error Checking                
                ErrorResponse errorResponse = null;
                //if the token is not valid, immediately return no authorization error to the user
                if (errorResponse != null && !errorResponse.IsTokenValid)
                {
                    return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.Unauthorized);
                }
                if (client == null)
                {
                    errorResponse = new ErrorResponse()
                    {
                        Message = errorSettings.MessageNoInputs,
                        ErrorCode = HttpStatusCode.BadRequest.ToString(),
                        Description = "No input data is passed"
                    };
                    return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.BadRequest);
                }
                #endregion

                var pinResponseVM = await matterRepositoy.GetPinnedRecordsAsync(client);
                if (pinResponseVM != null && pinResponseVM.TotalCount == 0)
                {
                    errorResponse = new ErrorResponse()
                    {
                        Message = pinResponseVM.NoPinnedMessage,
                        ErrorCode = ((int)HttpStatusCode.NotFound).ToString(),
                        Description = "No resource found for your search criteria"
                    };
                    return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.NotFound);
                }
                return matterCenterServiceFunctions.ServiceResponse(pinResponseVM, (int)HttpStatusCode.OK);
            }
            catch (Exception ex)
            {
                customLogger.LogError(ex, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
                throw;
            }
        }
예제 #9
0
        /// <summary>
        /// unpin the matter
        /// </summary>        
        /// <param name="client">Client object containing Client data</param>
        /// <param name="details">Term Store object containing Term store data</param>
        /// <returns>Returns JSON object to the client</returns>        ///
        public async Task<IActionResult> UnPin([FromBody]PinRequestMatterVM pinRequestMatterVM)
        {
            try
            {
                spoAuthorization.AccessToken = HttpContext.Request.Headers["Authorization"];
                #region Error Checking                
                ErrorResponse errorResponse = null;
                //if the token is not valid, immediately return no authorization error to the user
                if (errorResponse != null && !errorResponse.IsTokenValid)
                {
                    return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.Unauthorized);
                }
                if (pinRequestMatterVM == null && pinRequestMatterVM.Client == null && pinRequestMatterVM.MatterData == null)
                {
                    errorResponse = new ErrorResponse()
                    {
                        Message = errorSettings.MessageNoInputs,
                        ErrorCode = HttpStatusCode.BadRequest.ToString(),
                        Description = "No input data is passed"
                    };
                    return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.BadRequest);
                }
                #endregion
                var isMatterUnPinned = await matterRepositoy.UnPinRecordAsync<PinRequestMatterVM>(pinRequestMatterVM);
                var matterUnPinned = new
                {
                    IsMatterUnPinned = isMatterUnPinned
                };
                return matterCenterServiceFunctions.ServiceResponse(matterUnPinned, (int)HttpStatusCode.OK);

            }
            catch (Exception ex)
            {
                customLogger.LogError(ex, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
                throw;
            }
        }
예제 #10
0
        public async Task<IActionResult> Get([FromBody] String filter)
        {
            string result = string.Empty;
            try
            {
                #region Error Checking                
                ErrorResponse errorResponse = null;

                if (filter == null)
                {
                    errorResponse = new ErrorResponse()
                    {
                        Message = errorSettings.MessageNoInputs,
                        ErrorCode = HttpStatusCode.BadRequest.ToString(),
                        Description = "No filter was passed"
                    };
                    return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.OK);
                }
                #endregion
                var configResultsVM = await configRepository.GetConfigurationsAsync(filter);
                CreateConfig(configResultsVM, "uiconfig.js", false);
                return matterCenterServiceFunctions.ServiceResponse(configResultsVM, (int)HttpStatusCode.OK);
            }
            catch (Exception exception)
            {
                customLogger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
                throw;
            }
        }
예제 #11
0
 /// <summary>
 /// get users
 /// </summary>        
 /// <param name="client">Client object containing Client data</param>
 /// <param name="details">Term Store object containing Term store data</param>
 /// <returns>Returns JSON object to the client</returns>        ///
 public async Task<IActionResult> GetConfigurations([FromBody]string siteCollectionPath)
 {
     try
     {
         spoAuthorization.AccessToken = HttpContext.Request.Headers["Authorization"];
         #region Error Checking                
         ErrorResponse errorResponse = null;
         //if the token is not valid, immediately return no authorization error to the user
         if (errorResponse != null && !errorResponse.IsTokenValid)
         {
             return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.Unauthorized);
         }
         if (string.IsNullOrWhiteSpace(siteCollectionPath))
         {
             errorResponse = new ErrorResponse()
             {
                 Message = errorSettings.MessageNoInputs,
                 ErrorCode = HttpStatusCode.BadRequest.ToString(),
                 Description = "No input data is passed"
             };
             return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.BadRequest);
         }
         #endregion
         GenericResponseVM genericResponseVM = await matterRepositoy.GetConfigurationsAsync(siteCollectionPath);
         return matterCenterServiceFunctions.ServiceResponse(genericResponseVM, (int)HttpStatusCode.OK);
     }
     catch (Exception ex)
     {
         customLogger.LogError(ex, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
         throw;
     }
 }
예제 #12
0
        public async Task<IActionResult> UrlExists(Client client, string oneNoteUrl, string matterLandingPageUrl)
        {
            string result = string.Empty;
            
            try
            {

                spoAuthorization.AccessToken = HttpContext.Request.Headers["Authorization"];
                #region Error Checking                
                ErrorResponse errorResponse = null;
                //if the token is not valid, immediately return no authorization error to the user
                if (errorResponse != null && !errorResponse.IsTokenValid)
                {
                    return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.Unauthorized);
                }

                if (client == null && string.IsNullOrEmpty(oneNoteUrl) && string.IsNullOrEmpty(matterLandingPageUrl))
                {
                    errorResponse = new ErrorResponse()
                    {
                        Message = errorSettings.MessageNoInputs,
                        ErrorCode = HttpStatusCode.BadRequest.ToString(),
                        Description = "No input data is passed"
                    };
                    return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.NotFound);
                }
                #endregion
                var oneNoteUrlExists = await sharedRepository.UrlExistsAsync(client, oneNoteUrl);
                var matterLandingUrlExists = await sharedRepository.UrlExistsAsync(client, matterLandingPageUrl);
                var urlExists = new
                {
                    OneNoteExists = oneNoteUrlExists,
                    MatterLandingExists = matterLandingUrlExists
                };
                return matterCenterServiceFunctions.ServiceResponse(urlExists, (int)HttpStatusCode.OK);
            }
            catch (Exception exception)
            {
                customLogger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
                throw;
            }
        }
예제 #13
0
        public async Task<IActionResult> Help(Client client, string selectedPage)
        {
            string result = string.Empty;
            try
            {

                spoAuthorization.AccessToken = HttpContext.Request.Headers["Authorization"];
                #region Error Checking                
                ErrorResponse errorResponse = null;
                //if the token is not valid, immediately return no authorization error to the user
                if (errorResponse != null && !errorResponse.IsTokenValid)
                {
                    return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.Unauthorized);
                }

                if (client == null && string.IsNullOrWhiteSpace(selectedPage))
                {
                    errorResponse = new ErrorResponse()
                    {
                        Message = errorSettings.MessageNoInputs,
                        ErrorCode = HttpStatusCode.BadRequest.ToString(),
                        Description = "No input data is passed"
                    };
                    return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.NotFound);
                }
                #endregion
                List<ContextHelpData> contextHelpCollection = new List<ContextHelpData>();
                string[] pageNames = sharedSettings.MatterCenterPages.Split(';');
                switch (selectedPage)
                {
                    case "1":
                        selectedPage = pageNames[1];
                        break;
                    case "2":
                        selectedPage = pageNames[2];
                        break;
                    case "4":
                        selectedPage = pageNames[4];
                        break;
                    default:
                        selectedPage = pageNames[0];
                        break;
                }
                string cacheKey = string.Concat(selectedPage, ServiceConstants.LINKS_STATIC_STRING);
                result = ServiceUtility.GetDataFromAzureRedisCache(cacheKey);
                if(string.IsNullOrEmpty(result))
                {
                    contextHelpCollection = await sharedRepository.GetMatterHelpAsync(client, selectedPage);
                    ServiceUtility.SetDataIntoAzureRedisCache<List<ContextHelpData>>(cacheKey, contextHelpCollection);
                }
                else
                {
                    contextHelpCollection = JsonConvert.DeserializeObject<List<ContextHelpData>>(result);
                }
                return matterCenterServiceFunctions.ServiceResponse(contextHelpCollection, (int)HttpStatusCode.OK);
            }
            catch (Exception exception)
            {
                customLogger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
                throw;
            }
        }
예제 #14
0
 /// <summary>
 /// Gets  the line number where exception has occurred.
 /// </summary>
 /// <param name="exception">Exception object</param>
 /// <param name="className">Class Name where exception occur</param>
 /// <param name="methodName">Name of the method.</param>
 /// <param name="logTableName">Name of the log table.</param>
 /// <returns>ErrorResponse</returns>
 public ErrorResponse LogError(Exception exception, string className, string methodName, string logTableName)
 {
     
     try
     {
         StackTrace trace = new System.Diagnostics.StackTrace(exception, true);
         int lineNumber = trace.GetFrame(trace.FrameCount - 1).GetFileLineNumber();
         errorResponse = MatterCenterExceptions(exception, className, methodName, logTableName, lineNumber);
         
     }
     catch (Exception ex)
     {
         System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(ex, true);
         int lineNumber = trace.GetFrame(trace.FrameCount - 1).GetFileLineNumber();
         errorResponse = MatterCenterExceptions(ex, className, methodName, logTableName, lineNumber);
         
     }
     return errorResponse;
 }
예제 #15
0
        /// <summary>
        /// Logs error message in Azure table storage or Event Viewer.
        /// </summary>
        /// <param name="exception">Exception object</param>
        /// <param name="className">Class Name where exception occur</param>
        /// <param name="methodName">Name of the method.</param>
        /// <param name="logTableName">Name of the log table.</param>
        /// <param name="lineNumber">Line Number of the log table.</param>
        /// <returns>Error logged in event viewer</returns>
        public ErrorResponse MatterCenterExceptions(Exception exception, string className, string methodName, string logTableName, int lineNumber)
        {
            string errorDate = DateTime.Now.ToString(logTables.AzureRowKeyDateFormat, CultureInfo.InvariantCulture);
            string errorCode = string.Empty;
            string result = string.Empty;
            try
            {
                if (null != exception)
                {
                    if (Convert.ToBoolean(logTables.IsLoggingOnAzure, CultureInfo.InvariantCulture))
                    {
                        //// Log to Azure table storage
                        errorDate = AzureLogger.LogInAzure(exception, className, methodName, logTableName, lineNumber, logTables, generalSettings);
                    }
                    else
                    {                        
                        errorResponse = new ErrorResponse()
                        {
                            Message = exception.Message,
                            ClassName = className,
                            MethodName = methodName,
                            LineNumber = lineNumber

                        };
                        //// Log to event viewer
                        EventViewerLogger.LogInEventViewer(errorResponse.ToString(), ServiceConstants.EVENT_ERROR, logTables);
                    }                    
                    errorResponse = new ErrorResponse()
                    {
                        ErrorCode = exception.HResult.ToString(),
                        ErrorDate = errorDate,
                        Message = ServiceUtility.RemoveEscapeCharacter(exception.Message),
                       
                    };
                }
                else
                {                    
                    errorResponse = new ErrorResponse()
                    {
                        ErrorCode = ServiceConstants.LOGGING_FAILED_CODE.ToString(),
                        ErrorDate = errorDate,
                        Message = ServiceUtility.RemoveEscapeCharacter(exception.Message),
                        Description = ServiceConstants.LOGGING_FAILED_MESSAGE
                    };
                }
            }
            catch (Exception)
            {                
                errorResponse = new ErrorResponse()
                {
                    ErrorCode = ServiceConstants.LOGGING_FAILED_CODE.ToString(),
                    ErrorDate = errorDate,
                    Message = ServiceUtility.RemoveEscapeCharacter(exception.Message),
                    Description = ServiceConstants.LOGGING_FAILED_MESSAGE
                };
            }
            return errorResponse;
        }
예제 #16
0
 /// <summary>
 /// unpin the matter
 /// </summary>        
 /// <param name="client">Client object containing Client data</param>
 /// <param name="details">Term Store object containing Term store data</param>
 /// <returns>Returns JSON object to the client</returns>        ///
 public async Task<IActionResult> GetPermissionLevels([FromBody]Client client)
 {
     try
     {
         spoAuthorization.AccessToken = HttpContext.Request.Headers["Authorization"];
         #region Error Checking                
         ErrorResponse errorResponse = null;
         //if the token is not valid, immediately return no authorization error to the user
         if (errorResponse != null && !errorResponse.IsTokenValid)
         {
             return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.Unauthorized);
         }
         if (client == null)
         {
             errorResponse = new ErrorResponse()
             {
                 Message = errorSettings.MessageNoInputs,
                 ErrorCode = HttpStatusCode.BadRequest.ToString(),
                 Description = "No input data is passed"
             };
             return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.BadRequest);
         }
         #endregion
         IList<Role> roles = new List<Role>();
         roles = await matterRepositoy.GetPermissionLevelsAsync(client);
         return matterCenterServiceFunctions.ServiceResponse(roles, (int)HttpStatusCode.OK);
     }
     catch (Exception ex)
     {
         customLogger.LogError(ex, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
         throw;
     }
 }
예제 #17
0
 /// <summary>
 /// get users
 /// </summary>        
 /// <param name="client">Client object containing Client data</param>
 /// <param name="details">Term Store object containing Term store data</param>
 /// <returns>Returns JSON object to the client</returns>        ///
 public async Task<IActionResult> GetUsers([FromBody]SearchRequestVM searchRequestVM)
 {
     try
     {
         spoAuthorization.AccessToken = HttpContext.Request.Headers["Authorization"];
         #region Error Checking                
         ErrorResponse errorResponse = null;
         //if the token is not valid, immediately return no authorization error to the user
         if (errorResponse != null && !errorResponse.IsTokenValid)
         {
             return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.Unauthorized);
         }
         if (searchRequestVM.Client == null)
         {
             errorResponse = new ErrorResponse()
             {
                 Message = errorSettings.MessageNoInputs,
                 ErrorCode = HttpStatusCode.BadRequest.ToString(),
                 Description = "No input data is passed"
             };
             return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.BadRequest);
         }
         #endregion
         searchRequestVM.SearchObject.SearchTerm = (!string.IsNullOrWhiteSpace(searchRequestVM.SearchObject.SearchTerm)) ? searchRequestVM.SearchObject.SearchTerm : string.Empty;
         IList<Users> users = await matterRepositoy.GetUsersAsync(searchRequestVM);
         if (users != null && users.Count != 0)
         {
             return matterCenterServiceFunctions.ServiceResponse(users, (int)HttpStatusCode.OK);
         }
         else
         {
             Users noResult = new Users()
             {
                 Name = errorSettings.PeoplePickerNoResults,
                 LogOnName = string.Empty,
                 Email = string.Empty,
                 EntityType = string.Empty
             };
             users.Add(noResult);
             return matterCenterServiceFunctions.ServiceResponse(users, (int)HttpStatusCode.OK);
         }
     }
     catch (Exception ex)
     {
         customLogger.LogError(ex, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
         throw;
     }
 }
예제 #18
0
 public async Task<IActionResult> GetDocumentAssets(Client client)
 {
     spoAuthorization.AccessToken = HttpContext.Request.Headers["Authorization"];
     #region Error Checking                
     ErrorResponse errorResponse = null;
     //if the token is not valid, immediately return no authorization error to the user
     if (errorResponse != null && !errorResponse.IsTokenValid)
     {
         return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.Unauthorized);
     }
     if (client == null)
     {
         errorResponse = new ErrorResponse()
         {
             Message = errorSettings.MessageNoInputs,
             ErrorCode = HttpStatusCode.BadRequest.ToString(),
             Description = "No input data is passed"
         };
         return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.BadRequest);
     }
     #endregion
     var documentAsset = await documentRepositoy.GetDocumentAndClientGUIDAsync(client);
     return matterCenterServiceFunctions.ServiceResponse(documentAsset, (int)HttpStatusCode.OK);
 }
예제 #19
0
        public async Task<IActionResult> Get([FromBody]SearchRequestVM searchRequestVM)
        {
            try
            {    
                spoAuthorization.AccessToken = HttpContext.Request.Headers["Authorization"]; 

                #region Error Checking
                ErrorResponse errorResponse = null;
                if (searchRequestVM == null && searchRequestVM.Client == null && searchRequestVM.SearchObject == null)
                {
                    errorResponse = new ErrorResponse()
                    {
                        Message = errorSettings.MessageNoInputs,
                        ErrorCode = HttpStatusCode.BadRequest.ToString(),
                        Description = "No input data is passed"
                    };
                    return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.NotFound);
                }

                #endregion

                var searchObject = searchRequestVM.SearchObject;
                // Encode all fields which are coming from js
                SearchUtility.EncodeSearchDetails(searchObject.Filters, false);
                // Encode Search Term
                searchObject.SearchTerm = (searchObject.SearchTerm != null) ?
                    WebUtility.HtmlEncode(searchObject.SearchTerm).Replace(ServiceConstants.ENCODED_DOUBLE_QUOTES, ServiceConstants.DOUBLE_QUOTE) : string.Empty;

                var searchResultsVM = await matterRepositoy.GetMattersAsync(searchRequestVM);
                return matterCenterServiceFunctions.ServiceResponse(searchResultsVM, (int)HttpStatusCode.OK);
            }
            catch (Exception ex)
            {
                customLogger.LogError(ex, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
                throw;
            }
        }
예제 #20
0
        /// <summary>
        /// Gets the hierarchy of terms along with the specific custom properties of each term from term store.
        /// </summary>        
        /// <param name="client">Client object containing Client data</param>
        /// <param name="details">Term Store object containing Term store data</param>
        /// <returns>Returns JSON object to the client</returns>
        ///
        public async Task<IActionResult> GetTaxonomy([FromBody]TermStoreViewModel termStoreViewModel)
        {
            try
            {
                spoAuthorization.AccessToken = HttpContext.Request.Headers["Authorization"];
                #region Error Checking                
                ErrorResponse errorResponse = null;
                //if the token is not valid, immediately return no authorization error to the user
                if (errorResponse != null && !errorResponse.IsTokenValid)
                {
                    return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.Unauthorized);
                }

                ValidationHelperFunctions.ErrorSettings = errorSettings;
                errorResponse = ValidationHelperFunctions.TaxonomyValidation(termStoreViewModel.Client);
                if (errorResponse != null && !String.IsNullOrWhiteSpace(errorResponse.Message))
                {
                    return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.BadRequest);
                }
                #endregion

                string cacheValue = string.Empty;
                string key = string.Empty;
                var details = termStoreViewModel.TermStoreDetails;
                if (details.TermSetName == taxonomySettings.PracticeGroupTermSetName)
                {
                    key = ServiceConstants.CACHE_MATTER_TYPE;
                }
                else if (details.TermSetName == taxonomySettings.ClientTermSetName)
                {
                    key = ServiceConstants.CACHE_CLIENTS;
                }

                ServiceUtility.GeneralSettings = generalSettings;
                //cacheValue = ServiceUtility.GetDataFromAzureRedisCache(key);
                TaxonomyResponseVM taxonomyRepositoryVM = null;
                if (String.IsNullOrEmpty(cacheValue))
                {
                    taxonomyRepositoryVM = await taxonomyRepository.GetTaxonomyHierarchyAsync(termStoreViewModel);
                    if (termStoreViewModel.TermStoreDetails.TermSetName == taxonomySettings.PracticeGroupTermSetName && taxonomyRepositoryVM.TermSets!=null)
                    {                        
                        ServiceUtility.SetDataIntoAzureRedisCache<TermSets>(key, taxonomyRepositoryVM.TermSets);
                        return matterCenterServiceFunctions.ServiceResponse(taxonomyRepositoryVM.TermSets, (int)HttpStatusCode.OK);
                    }
                    if (termStoreViewModel.TermStoreDetails.TermSetName == taxonomySettings.ClientTermSetName && taxonomyRepositoryVM.ClientTermSets != null)
                    {                        
                        ServiceUtility.SetDataIntoAzureRedisCache<ClientTermSets>(key, taxonomyRepositoryVM.ClientTermSets);
                        return matterCenterServiceFunctions.ServiceResponse(taxonomyRepositoryVM.ClientTermSets, (int)HttpStatusCode.OK);
                    }
                }
                else
                {
                    if (termStoreViewModel.TermStoreDetails.TermSetName == taxonomySettings.PracticeGroupTermSetName)
                    {
                        var pgTermSets = JsonConvert.DeserializeObject<TermSets>(cacheValue);
                        if (pgTermSets == null)
                        {
                            errorResponse = new ErrorResponse()
                            {
                                Message = errorSettings.MessageNoResult,
                                ErrorCode = "404",
                                Description = "No data is present for the given passed input"
                            };
                            return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.NotFound);
                        }
                        return matterCenterServiceFunctions.ServiceResponse(pgTermSets, (int)HttpStatusCode.OK);
                    }
                    if (termStoreViewModel.TermStoreDetails.TermSetName == taxonomySettings.ClientTermSetName)
                    {
                        var clientTermSets = JsonConvert.DeserializeObject<ClientTermSets>(cacheValue);
                        if (clientTermSets == null)
                        {
                            errorResponse = new ErrorResponse()
                            {
                                Message = errorSettings.MessageNoResult,
                                ErrorCode = "404",
                                Description = "No data is present for the given passed input"
                            };
                            return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.NotFound);
                        }
                        return matterCenterServiceFunctions.ServiceResponse(clientTermSets, (int)HttpStatusCode.OK);
                    }
                }
                //If all the above condition fails, return validation error object
                errorResponse = new ErrorResponse()
                {
                    Message = errorSettings.MessageNoResult,
                    ErrorCode = "404",
                    Description = "No data is present for the given passed input"                    
                };
                return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.NotFound);
            }
            catch(Exception ex)
            {
                customLogger.LogError(ex, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
                throw;
            }
            
        }
예제 #21
0
        /// <summary>
        /// Updates matter
        /// </summary>        
        /// <param name="client">Client object containing Client data</param>
        /// <param name="details">Term Store object containing Term store data</param>
        /// <returns>Returns JSON object to the client</returns>        ///
        public IActionResult Update([FromBody]MatterInformationVM matterInformation)
        {            
            string editMatterValidation = string.Empty;            
            var matter = matterInformation.Matter;
            var client = matterInformation.Client;
            var userid = matterInformation.UserIds;
            try
            {
                spoAuthorization.AccessToken = HttpContext.Request.Headers["Authorization"];
                #region Error Checking                
                ErrorResponse errorResponse = null;                
                if (matterInformation.Client == null && matterInformation.Matter == null && matterInformation.MatterDetails == null)
                {
                    errorResponse = new ErrorResponse()
                    {
                        Message = errorSettings.MessageNoInputs,
                        ErrorCode = HttpStatusCode.BadRequest.ToString(),
                        Description = "No input data is passed"
                    };
                    return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.BadRequest);
                }
                #endregion

                #region Validations
                GenericResponseVM validationResponse = validationFunctions.IsMatterValid(matterInformation, int.Parse(ServiceConstants.EditMatterPermission), null); 
                if(validationResponse != null)
                {
                    errorResponse = new ErrorResponse()
                    {
                        Message = validationResponse.Value,
                        ErrorCode = validationResponse.Code,                        
                    };
                    return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.BadRequest);
                }

                if (null != matter.Conflict && !string.IsNullOrWhiteSpace(matter.Conflict.Identified))
                {
                    if (matter.AssignUserNames.Count==0)
                    {                        
                        errorResponse = new ErrorResponse()
                        {
                            Message = errorSettings.IncorrectInputUserNamesMessage,
                            ErrorCode = errorSettings.IncorrectInputUserNamesCode,                            
                        };
                        return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.BadRequest);
                    }
                    else
                    {
                        if (Convert.ToBoolean(matter.Conflict.Identified, CultureInfo.InvariantCulture))
                        {
                            validationResponse = editFunctions.CheckSecurityGroupInTeamMembers(client, matter, userid);
                            if (validationResponse != null)
                            {
                                errorResponse = new ErrorResponse()
                                {
                                    Message = validationResponse.Value,
                                    ErrorCode = validationResponse.Code,
                                };
                                return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.BadRequest);
                            }
                        }
                    }
                }
                else
                {                    
                    errorResponse = new ErrorResponse()
                    {
                        Message = errorSettings.IncorrectInputConflictIdentifiedMessage,
                        ErrorCode = errorSettings.IncorrectInputConflictIdentifiedCode,
                    };
                    return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.BadRequest);
                }
                #endregion

                #region Upadte Matter
                GenericResponseVM genericResponse = matterProvision.UpdateMatter(matterInformation);
                if(genericResponse==null)
                {
                    var result = new GenericResponseVM()
                    {
                        Code = "200",
                        Value= "Update Success"
                    };
                    return matterCenterServiceFunctions.ServiceResponse(result, (int)HttpStatusCode.OK);
                }
                else
                {
                    return matterCenterServiceFunctions.ServiceResponse(genericResponse, (int)HttpStatusCode.NotModified);
                }

                #endregion
                
            }
            catch (Exception ex)
            {
                MatterRevertList matterRevertListObject = new MatterRevertList()
                {
                    MatterLibrary = matterInformation.Matter.Name,
                    MatterOneNoteLibrary = matterInformation.Matter.Name + matterSettings.OneNoteLibrarySuffix,
                    MatterCalendar = matterInformation.Matter.Name + matterSettings.CalendarNameSuffix,
                    MatterTask = matterInformation.Matter.Name + matterSettings.TaskNameSuffix,
                    MatterSitePages = matterSettings.MatterLandingPageRepositoryName
                };
                //editFunctions.RevertMatterUpdates(client, matter, matterRevertListObject, loggedInUserName, userPermissionOnLibrary, listItemId, isEditMode);
                customLogger.LogError(ex, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);                
                throw;
            }
            finally
            {

            }
        }
예제 #22
0
        /// <summary>
        /// Updates matter metadata - Stamps properties to the created matter.
        /// </summary>        
        /// <param name="client">Client object containing Client data</param>
        /// <param name="details">Term Store object containing Term store data</param>
        /// <returns>Returns JSON object to the client</returns>        ///
        public IActionResult UpdateMetadata([FromBody]MatterMetdataVM matterMetdata)
        {
            string editMatterValidation = string.Empty;
            var matter = matterMetdata.Matter;
            var client = matterMetdata.Client;
            
            try
            {
                spoAuthorization.AccessToken = HttpContext.Request.Headers["Authorization"];
                #region Error Checking                
                ErrorResponse errorResponse = null;
                if (matterMetdata.Client == null && matterMetdata.Matter == null && 
                    matterMetdata.MatterDetails == null && matterMetdata.MatterProvisionFlags==null)
                {
                    errorResponse = new ErrorResponse()
                    {
                        Message = errorSettings.MessageNoInputs,
                        ErrorCode = HttpStatusCode.BadRequest.ToString(),
                        Description = "No input data is passed"
                    };
                    return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.BadRequest);
                }
                #endregion

                #region Validations
                MatterInformationVM matterInfo = new MatterInformationVM()
                {
                    Client = matterMetdata.Client,
                    Matter = matterMetdata.Matter,
                    MatterDetails = matterMetdata.MatterDetails
                };
                GenericResponseVM genericResponse = validationFunctions.IsMatterValid(matterInfo, 
                    int.Parse(ServiceConstants.ProvisionMatterUpdateMetadataForList), 
                    matterMetdata.MatterConfigurations);
                if (genericResponse != null)
                {
                    matterProvision.DeleteMatter(client, matter);
                    errorResponse = new ErrorResponse()
                    {
                        Message = genericResponse.Value,
                        ErrorCode = genericResponse.Code,
                    };
                    return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.BadRequest);
                }
                #endregion   
                try
                {
                    genericResponse = matterProvision.UpdateMatterMetadata(matterMetdata);
                    if (genericResponse == null)
                    {
                        var result = new GenericResponseVM()
                        {
                            Code = "200",
                            Value = "Update Success"
                        };
                        return matterCenterServiceFunctions.ServiceResponse(result, (int)HttpStatusCode.OK);
                    }
                    return matterCenterServiceFunctions.ServiceResponse(genericResponse, (int)HttpStatusCode.NotModified);
                }
                catch(Exception ex)
                {
                    matterProvision.DeleteMatter(client, matter);
                    customLogger.LogError(ex, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
                    throw;
                }
            }
            catch (Exception ex)
            {                
                customLogger.LogError(ex, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
                throw;
            }
            
        }
예제 #23
0
        public IActionResult Delete([FromBody] MatterVM matterVM)
        {
            try
            {
                ErrorResponse errorResponse = null;
                if (null == matterVM && null == matterVM.Client && null == matterVM.Matter && string.IsNullOrWhiteSpace(matterVM.Client.Url) && string.IsNullOrWhiteSpace(matterVM.Matter.Name))
                {
                    errorResponse = new ErrorResponse()
                    {
                        Message = errorSettings.MessageNoInputs,
                        ErrorCode = HttpStatusCode.BadRequest.ToString(),
                        Description = "No input data is passed"
                    };
                    return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.BadRequest);
                }

                GenericResponseVM genericResponse = matterProvision.DeleteMatter(matterVM);
                return matterCenterServiceFunctions.ServiceResponse(genericResponse, (int)HttpStatusCode.OK);
            }
            catch (Exception exception)
            {
                customLogger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
                var errResponse = customLogger.GenerateErrorResponse(exception);
                return matterCenterServiceFunctions.ServiceResponse(errResponse, (int)HttpStatusCode.InternalServerError);
            }
        }
예제 #24
0
        public async Task<IActionResult> GetConfigsForSPO([FromBody] String filter)
        {
            string result = string.Empty;

            try
            {
                #region Error Checking                
                ErrorResponse errorResponse = null;

                if (filter == null)
                {
                    errorResponse = new ErrorResponse()
                    {
                        Message = errorSettings.MessageNoInputs,
                        ErrorCode = HttpStatusCode.BadRequest.ToString(),
                        Description = "No filter was passed"
                    };
                    return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.OK);
                }
                #endregion
                var configResultsVM = await configRepository.GetConfigurationsAsync(filter);
                CreateConfig(configResultsVM, "uiconfigforspo.js", true);
                configRepository.UploadConfigFileToSPO(Path.Combine(hostingEnvironment.WebRootPath, "app/config.js"), generalSettings.CentralRepositoryUrl);
                var genericResponse = new GenericResponseVM
                {
                    Code = HttpStatusCode.OK.ToString(),
                    Value = "",
                    IsError = false

                };
                return matterCenterServiceFunctions.ServiceResponse(genericResponse, (int)HttpStatusCode.OK);

            }
            catch (Exception exception)
            {
                customLogger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
                throw;
            }
        }