<commit_before>﻿using System;
using System.Collections.Generic;
using Infopulse.EDemocracy.Data.Interfaces;
using Infopulse.EDemocracy.Model;
using System.Data;
using System.Data.Entity;
using System.Data.SqlClient;
using System.Linq;
using System.Runtime.CompilerServices;

namespace Infopulse.EDemocracy.Data.Repositories
{
	public class UserDetailRepository : BaseRepository, IUserDetailRepository
	{
		public int GetUserId(string userEmail)
		{
			using (var db = new EDEntities())
			{
				var userID = db.Database.SqlQuery<int>(
					"sp_User_GetIdByEmail @UserEmail",
					new SqlParameter()
					{
						ParameterName = "UserEmail",
						DbType = DbType.String,
						Value = userEmail,
						Direction = ParameterDirection.Input
					});

				return userID.SingleOrDefault();
			}
		}

		public UserDetail Update(UserDetail user)
		{
			using (var db = new EDEntities())
			{
				var userDetailFromDb = db.UserDetails.SingleOrDefault(ud => ud.UserID == user.UserID);
				if (userDetailFromDb == null && user.User != null && !string.IsNullOrWhiteSpace(user.User.Email))
				{
					userDetailFromDb = db.UserDetails.SingleOrDefault(ud => ud.User.Email == user.User.Email);
				}

				if (userDetailFromDb == null)
				{
					user.CreatedBy = this.UnknownAppUser;
					user.CreatedDate = DateTime.UtcNow;<commit_msg>Fix issue when no UserDetails created yet and get current user info is requested.<commit_after>﻿using System;
using System.Collections.Generic;
using Infopulse.EDemocracy.Data.Interfaces;
using Infopulse.EDemocracy.Model;
using System.Data;
using System.Data.Entity;
using System.Data.SqlClient;
using System.Linq;
using System.Runtime.CompilerServices;

namespace Infopulse.EDemocracy.Data.Repositories
{
	public class UserDetailRepository : BaseRepository, IUserDetailRepository
	{
		public int GetUserId(string userEmail)
		{
			using (var db = new EDEntities())
			{
				var userID = db.Database.SqlQuery<int>(
					"sp_User_GetIdByEmail @UserEmail",
					new SqlParameter()
					{
						ParameterName = "UserEmail",
						DbType = DbType.String,
						Value = userEmail,
						Direction = ParameterDirection.Input
					});

				return userID.SingleOrDefault();
			}
		}

		public UserDetail Update(UserDetail user)
		{
			using (var db = new EDEntities())
			{
				var userDetailFromDb = db.UserDetails.SingleOrDefault(ud => ud.UserID == user.UserID);
				if (userDetailFromDb == null && user.User != null && !string.IsNullOrWhiteSpace(user.User.Email))
				{
					userDetailFromDb = db.UserDetails.SingleOrDefault(ud => ud.User.Email == user.User.Email);
				}

				if (userDetailFromDb == null)
				{
					user.CreatedBy = this.UnknownAppUser;
					user.CreatedDate = DateTime.UtcNow;
					user.User = null;
{'fraction_non_alphanumeric': 0.10668615272195835, 'fraction_numerical': 0.0, 'mean_word_length': 3.720689655172414, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6539808', 'n_tokens_mistral': 1033, 'n_tokens_neox': 845, 'n_words': 178}