Beispiel #1
0
        protected DataResult <TResult> CreateDataResult <TResult>(string functionName, int rowCount,
                                                                  TResult value, DataResultType resultType, string friendlyMessage, string internalMessage,
                                                                  int?valueId = null, Exception exception = null)
        {
            if (rowCount > 0)
            {
                resultType      = DataResultType.Success;
                friendlyMessage = !string.IsNullOrWhiteSpace(friendlyMessage) ? friendlyMessage : Success;
                internalMessage = !string.IsNullOrWhiteSpace(internalMessage) ? internalMessage : $"Procedure {functionName} completed successfully.";
            }
            else if (resultType.Equals(DataResultType.Success) &&
                     !functionName.ToLower().Contains("return") &&
                     !functionName.ToLower().Contains("set") &&
                     !functionName.ToLower().Contains("delete"))
            {
                resultType      = DataResultType.NotRequired;
                friendlyMessage = !string.IsNullOrWhiteSpace(friendlyMessage) && !friendlyMessage.Equals(Success) ? friendlyMessage : "No actions required";
                internalMessage = !string.IsNullOrWhiteSpace(internalMessage) ? internalMessage : $"Procedure {functionName} did not require any changes.";
            }
            else if (resultType.Equals(DataResultType.Success))
            {
                resultType      = DataResultType.NoRecordsFound;
                friendlyMessage = "Sorry, no results were returned.";
                internalMessage = $"Procedure {functionName} returned 0 records.";
            }

            var dataResult = new DataResult <TResult>(value, resultType, friendlyMessage, internalMessage, exception);

            dataResult.Data.Add("Command Details", functionName);

            if (valueId.HasValue)
            {
                dataResult.ValueId = valueId.Value;
            }

            exception?.Data.Add("ExceptionData.StringValue", functionName);

            UnitOfWork.AddDataResult(dataResult);

            return(dataResult);
        }