public static async Task <User> ValidateRegisterAsync(Tourist tourist, LoginData loginData) { var firstName = tourist.FirstName.ToLower(); var secondName = tourist.SecondName.ToLower(); var db = ContextHelper.GetContext(); var t = await db.Tourists.FirstOrDefaultAsync(x => x.FirstName.ToLower().Equals(firstName) && x.SecondName.ToLower().Equals(secondName)); if (t != null) { throw new Exception("Tourist with such data is already in the database!"); } else { UserRole userRole = db.UserRoles.FirstOrDefault(x => x.Name.Equals("User")); User u = new User() { LoginData = loginData, UserRole = userRole }; tourist.User = u; db.Tourists.Add(tourist); db.SaveChanges(); return(u); } }