From a56cf7413461e2e8b6fd8bd157403829cf407aa8 Mon Sep 17 00:00:00 2001
From: Amin <69254513+AminGh05@users.noreply.github.com>
Date: Thu, 10 Apr 2025 22:24:10 +0330
Subject: [PATCH] Update Session04.md
added Result & ResultStatus part
---
.../Session04/Session04.md | 68 +++++++++++++++++--
1 file changed, 62 insertions(+), 6 deletions(-)
diff --git a/02_ProjectOrientedSessions/Session04/Session04.md b/02_ProjectOrientedSessions/Session04/Session04.md
index 1c084fb..52baf78 100644
--- a/02_ProjectOrientedSessions/Session04/Session04.md
+++ b/02_ProjectOrientedSessions/Session04/Session04.md
@@ -32,11 +32,11 @@ public class CityDto
```cs
public class TransportationSearchRequestDto
{
- public short? VehicleTypeId { get; init; }
- public int? FromCityId { get; init; }
- public int? ToCityId { get; init; }
- public DateTime? StartDate { get; init; }
- public DateTime? EndDate { get; init; }
+ public short? VehicleTypeId { get; init; }
+ public int? FromCityId { get; init; }
+ public int? ToCityId { get; init; }
+ public DateTime? StartDate { get; init; }
+ public DateTime? EndDate { get; init; }
}
```
@@ -169,7 +169,63 @@ public class MappingProfile : Profile
.
```
-# Result & Result Status (Amin)
+# Result & Result Status
+
+Result is a template to transfer data between services and controllers (in backend), so will use a generic type
+
+```cs
+public class Result
+{
+ public ResultStatus Status { get; set; }
+ public string? ErrorMessage { get; set; }
+ public T? Data { get; set; }
+ public bool IsSuccess => Status == ResultStatus.Success;
+
+ public static Result Success(T data)
+ {
+ return new Result
+ {
+ Status = ResultStatus.Success,
+ Data = data
+ };
+ }
+
+ public static Result Error(T data)
+ {
+ return new Result
+ {
+ Status = ResultStatus.Error,
+ Data = data
+ };
+ }
+
+ public static Result NotFound(T data)
+ {
+ return new Result
+ {
+ Status = ResultStatus.NotFound,
+ Data = data
+ };
+ }
+}
+```
+
+As you can see, there's a property of type ResultStatus, which is a enum for status of request
+
+```cs
+public enum ResultStatus
+{
+ Success,
+ NotFound,
+ ValidationError,
+ Conflict,
+ Unauthorized,
+ Forbidden,
+ Error
+}
+```
+
+You can read more about enums: [W3Schools](https://www.w3schools.com/cs/cs_enums.php)
# IService & Service (Amin)