Пример #1
0
 internal virtual CoreResult GetResultFromStatusCode(CoreStatusCode statusCode, ActionType _actionType, Exception exception = null)
 {
     return(new CoreResult
     {
         StatusCode = statusCode,
         Message = this.GetMessageByCoreStatusCode(statusCode, _actionType, exception),
         ExceptionError = exception == null ? null : this.GetMessageException(exception)
     });
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="statusCode"></param>
        /// <param name="actionType"></param>
        /// <param name="exception"></param>
        /// <returns></returns>
        internal virtual string GetMessageByCoreStatusCode(CoreStatusCode statusCode, ActionType actionType, Exception exception = null)
        {
            switch (statusCode)
            {
            case CoreStatusCode.OK:
                if (actionType == ActionType.View)
                {
                    return(string.Format("Lấy danh sách {0} thành công.", this.GetNameEntity()));
                }
                else if (actionType == ActionType.Insert)
                {
                    return(string.Format("Thêm mới {0} thành công.", this.GetNameEntity()));
                }
                else if (actionType == ActionType.Edit)
                {
                    return(string.Format("Cập nhật {0} thành công.", this.GetNameEntity()));
                }
                else if (actionType == ActionType.Delete)
                {
                    return(string.Format("Xóa {0} thành công.", this.GetNameEntity()));
                }
                else if (actionType == ActionType.Print)
                {
                    return(string.Format("In {0} thành công.", this.GetNameEntity()));
                }
                else if (actionType == ActionType.Get)
                {
                    return(string.Format("Lấy dữ liệu {0} thành công.", this.GetNameEntity()));
                }
                else
                {
                    return(string.Empty);
                }

            case CoreStatusCode.Existed:
                return(string.Format("{0} đã tồn tại trong hệ thống.", GetNameEntity()));

            case CoreStatusCode.NotFound:
                return(string.Format("{0} không tồn tại trong hệ thống", GetNameEntity()));

            case CoreStatusCode.Failed:
                if (actionType == ActionType.View)
                {
                    return(string.Format("Lấy danh sách {0} không thành công.", this.GetNameEntity()));
                }
                else if (actionType == ActionType.Insert)
                {
                    return(string.Format("Thêm mới {0} không thành công.", this.GetNameEntity()));
                }
                else if (actionType == ActionType.Edit)
                {
                    return(string.Format("Cập nhật {0} không thành công.", this.GetNameEntity()));
                }
                else if (actionType == ActionType.Delete)
                {
                    return(string.Format("Xóa {0} không thành công.", this.GetNameEntity()));
                }
                else if (actionType == ActionType.Print)
                {
                    return(string.Format("In {0} không thành công.", this.GetNameEntity()));
                }
                else if (actionType == ActionType.Get)
                {
                    return(string.Format("Lấy dữ liệu {0} không thành công.", this.GetNameEntity()));
                }
                else
                {
                    return(string.Empty);
                }

            case CoreStatusCode.ModelFailed:
                return(string.Format("Đối tượng {0} không đúng chuẩn dữ liệu.", GetNameEntity()));

            case CoreStatusCode.Exception:
                return(this.GetMessageExceptionString(exception));

            case CoreStatusCode.DontHavePermission:
                return(string.Format("Bạn không có quyền để thực hiện thao tác này.", GetNameEntity()));

            case CoreStatusCode.Used:
                return(string.Format("Đối tượng \"{0}\" đã được sử dụng, không được phép xóa.", GetNameEntity()));

            case CoreStatusCode.SystemError:
                return("Lỗi hệ thống");

            default:
                return(string.Empty);
            }
        }