Spaces:
Running
Running
File size: 5,422 Bytes
3418204 8c88a89 3418204 cb307da 3418204 8c88a89 3418204 8c88a89 3418204 8c88a89 3418204 8c88a89 3418204 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | using System;
using TaskTrackingSystem.Shared.Localization;
namespace TaskTrackingSystem.Shared
{
public class Result<T>
{
public bool IsSuccess { get; set; }
public T? Value { get; set; }
public string? ErrorMessage { get; set; }
public int StatusCode { get; set; }
public static Result<T> Success(T value, int statusCode = 200)
{
return new Result<T>
{
IsSuccess = true,
Value = value,
StatusCode = statusCode
};
}
public static Result<T> Failure(string errorMessage, int statusCode = 400)
{
return new Result<T>
{
IsSuccess = false,
ErrorMessage = errorMessage,
StatusCode = statusCode
};
}
}
public class Result
{
public bool IsSuccess { get; set; }
public string? ErrorMessage { get; set; }
public int StatusCode { get; set; }
public static Result Success(int statusCode = 200)
{
return new Result
{
IsSuccess = true,
StatusCode = statusCode
};
}
public static Result Failure(string errorMessage, int statusCode = 400)
{
return new Result
{
IsSuccess = false,
ErrorMessage = errorMessage,
StatusCode = statusCode
};
}
}
public static class ResultMessages
{
// Auth
public const string InvalidCredentials = "Invalid username/email or password.";
public const string ParseAuthResponseFailed = "Failed to parse authentication response tokens.";
// Project
public const string ProjectNameRequired = "Project name is required.";
public const string FailedToUpdateProject = "Failed to update project.";
public const string FailedToCreateProject = "Failed to create project.";
public static string ProjectNotFound(long id) => AppLocalization.Text("result.projectNotFound", $"Project with ID {id} not found.").Replace("{id}", id.ToString());
public const string UserIdsCannotBeNull = "User IDs cannot be null.";
public static string InvalidUserIds(string ids) => $"The following user IDs are invalid or deleted: {ids}";
public static string UserNotProjectMember(long userId, long projectId) => $"User with ID {userId} is not a member of project with ID {projectId}.";
// Task
public const string TaskTitleRequired = "Task title is required.";
public const string SelectProjectRequired = "Please select a project.";
public const string FailedToUpdateTask = "Failed to update task.";
public const string FailedToCreateTask = "Failed to create task.";
public static string TaskNotFound(long id) => AppLocalization.Text("result.taskNotFound", $"Task with ID {id} not found.").Replace("{id}", id.ToString());
public static string TaskNotFoundOrDeleted(long id) => AppLocalization.Text("result.taskNotFoundOrDeleted", $"Task with ID {id} not found or already deleted.").Replace("{id}", id.ToString());
// Role/Permission
public const string RoleNameRequired = "Role name is required.";
public const string FailedToUpdateRole = "Failed to update role.";
public const string FailedToCreateRole = "Failed to create role.";
public static string RoleNotFound(long id) => AppLocalization.Text("result.roleNotFound", $"Role with ID {id} not found.").Replace("{id}", id.ToString());
public static string AccessCodesCannotBeNull => AppLocalization.Text("result.accessCodesCannotBeNull", "Access codes cannot be null.");
public static string InvalidAccessCodes(string ids) => AppLocalization.Text("result.invalidAccessCodes", $"The following access codes are invalid or deleted: {ids}").Replace("{ids}", ids);
// User
public const string FillAllFields = "Please fill in all required fields.";
public const string FailedToUpdateUser = "Failed to update user.";
public const string PasswordMinLength = "Password must be at least 6 characters.";
public const string FailedToCreateUser = "Failed to create user.";
public static string UserNotFound(long id) => AppLocalization.Text("result.userNotFound", $"User with ID {id} not found.").Replace("{id}", id.ToString());
// Register
public const string ParseRegistrationResponseFailed = "Failed to parse registration response.";
public const string RegistrationFailed = "Registration failed. Please try again.";
// Username Validation Rules
public const string UsernameMinLength = "Username must be at least 3 characters long.";
public const string UsernameNoSpaces = "Username cannot contain spaces.";
public const string UsernameInvalidCharacters = "Username cannot contain spaces, and can only contain letters, numbers, underscores (_), and periods (.).";
// Password Validation Rules
public const string PasswordMinLengthRule = "Password must be at least 8 characters long.";
public const string PasswordComplexityRule = "Password must contain at least one uppercase letter, one lowercase letter, one number, and one special character.";
}
}
|