Source

main / Source / Excel / Excel.BizLogic / Models / ServiceResponse.cs

using System;

namespace DataUp.Excel.BizLogic
{
    public class ServiceResponse
    {
        /// <summary>
        /// Gets or sets the value indicating whether the operation is successful or not.
        /// </summary>
        public bool IsSuccess { get; set; }

        /// <summary>
        /// Gets or sets the message of the response.
        /// </summary>
        public string Message { get; set; }

        /// <summary>
        /// Create Failure status.
        /// </summary>
        /// <param name="exception">Exception instance.</param>
        /// <returns>Service response instance.</returns>
        public static ServiceResponse CreateFailureStatus(Exception exception)
        {
            return new ServiceResponse() { IsSuccess = false, Message = exception.Message };
        }

        /// <summary>
        /// Create failure status.
        /// </summary>
        /// <param name="customMessage">Custom message.</param>
        /// <returns>Service response instance.</returns>
        public static ServiceResponse CreateFailureStatus(string customMessage)
        {
            return new ServiceResponse() { IsSuccess = false, Message = customMessage };
        }

        /// <summary>
        /// Create success status.
        /// </summary>
        /// <param name="customMessage"></param>
        /// <returns>Service response instance.</returns>
        public static ServiceResponse CreateSuccessStatus(string customMessage)
        {
            return new ServiceResponse() { IsSuccess = true, Message = customMessage };
        }

        /// <summary>
        /// Create success status.
        /// </summary>
        /// <returns>Service response instance.</returns>
        public static ServiceResponse CreateSuccessStatus()
        {
            return new ServiceResponse() { IsSuccess = true };
        }

        /// <summary>
        /// Create success status.
        /// </summary>
        /// <param name="message">Custom message.</param>
        /// <returns>Service response instance.</returns>
        public static ServiceResponse CreateStatus(string message)
        {
            ServiceResponse status = new ServiceResponse();

            string[] respose = message.Split('|');

            if (respose.Length > 1)
            {
                bool success;
                bool.TryParse(respose[0], out success);

                status.IsSuccess = success;
                status.Message = respose[1];
            }
            else
            {
                status.IsSuccess = true;
                status.Message = message;
            }

            return status;
        }
    }
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.