Пример #1
0
        public async Task <User> AddUserAsync(User user)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user cannot be null");
            }

            try
            {
                await this.modelContext.AddAsync(user);

                await this.modelContext.SaveChangesAsync();
            }
            // duplicate email
            catch (DbUpdateException exc) when((exc.InnerException as SqlException)?.Number == 2601)
            {
                this.modelContext.Remove(user);
                throw UserException.DuplicateMailException(user.Credentials.Mail);
            }

            return(user);
        }