From 79ab2b304d93b1029515bd3f954db4e5a73f4168 Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 30 Jan 2020 20:26:52 +0800 Subject: ... --- Timeline/Services/DatabaseExtensions.cs | 36 --------------------------------- 1 file changed, 36 deletions(-) delete mode 100644 Timeline/Services/DatabaseExtensions.cs (limited to 'Timeline/Services/DatabaseExtensions.cs') diff --git a/Timeline/Services/DatabaseExtensions.cs b/Timeline/Services/DatabaseExtensions.cs deleted file mode 100644 index e77dd01a..00000000 --- a/Timeline/Services/DatabaseExtensions.cs +++ /dev/null @@ -1,36 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using System; -using System.Linq; -using System.Threading.Tasks; -using Timeline.Entities; -using Timeline.Models.Validation; - -namespace Timeline.Services -{ - internal static class DatabaseExtensions - { - private static readonly UsernameValidator usernameValidator = new UsernameValidator(); - - /// - /// Check the existence and get the id of the user. - /// - /// The username of the user. - /// The user id. - /// Thrown if is null. - /// Thrown if is of bad format. - /// Thrown if user does not exist. - internal static async Task CheckAndGetUser(DbSet userDbSet, string? username) - { - if (username == null) - throw new ArgumentNullException(nameof(username)); - var (result, message) = usernameValidator.Validate(username); - if (!result) - throw new UsernameBadFormatException(username, message); - - var userId = await userDbSet.Where(u => u.Username == username).Select(u => u.Id).SingleOrDefaultAsync(); - if (userId == 0) - throw new UserNotExistException(username); - return userId; - } - } -} -- cgit v1.2.3