50 lines
1.4 KiB
C#
50 lines
1.4 KiB
C#
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;
|
|
}
|
|
}
|