✨
This commit is contained in:
49
StopShopping.Services/Extensions/EnumExtensions.cs
Normal file
49
StopShopping.Services/Extensions/EnumExtensions.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using StopShopping.Services.Models;
|
||||
|
||||
namespace StopShopping.Services.Extensions;
|
||||
|
||||
public static class EnumExtensions
|
||||
{
|
||||
public static string GetTargetDirectory(this UploadScences uploadScences)
|
||||
{
|
||||
return uploadScences switch
|
||||
{
|
||||
UploadScences.Avatar => "avatar",
|
||||
UploadScences.Product => "product",
|
||||
UploadScences.Category => "category",
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(uploadScences))
|
||||
};
|
||||
}
|
||||
|
||||
public static char GetValue(this UserRoles userRoles)
|
||||
{
|
||||
return userRoles switch
|
||||
{
|
||||
UserRoles.Seller => 's',
|
||||
UserRoles.Buyer => 'c',
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(userRoles))
|
||||
};
|
||||
}
|
||||
|
||||
public static UserRoles ToUserRoles(this char userRole)
|
||||
{
|
||||
return userRole switch
|
||||
{
|
||||
's' => UserRoles.Seller,
|
||||
'c' => UserRoles.Buyer,
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(userRole), "valid: 'c','s'")
|
||||
};
|
||||
}
|
||||
|
||||
public static bool CanDelete(this RequestStatus requestStatus)
|
||||
{
|
||||
return requestStatus == RequestStatus.Publish
|
||||
|| requestStatus == RequestStatus.Replied;
|
||||
}
|
||||
|
||||
public static bool CanReply(this RequestStatus requestStatus)
|
||||
{
|
||||
return requestStatus == RequestStatus.Publish
|
||||
|| requestStatus == RequestStatus.Replied;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user