Ejemplo n.º 1
0
        public static void RememberUser(Activity activity
                                        , ITurnContext <IMessageActivity> turnContext = null)
        {
            if (activity != null)
            {
                try
                {
                    var db      = new SqlUserRepository();
                    var hasUser = db.GetAll().Any(x => x.UserId == activity.From.Id &&
                                                  x.UserName == activity.From.Name &&
                                                  x.ChannelId == activity.ChannelId);

                    if (!hasUser)
                    {
                        db.Add(new User(activity));
                        db.Save();
                    }
                }
                catch (Exception ex)
                {
                    if (turnContext != null)
                    {
                        turnContext.SendActivityAsync(MessageFactory.Text(ex.Message));
                    }
                    Console.WriteLine(ex);
                }
            }
        }
Ejemplo n.º 2
0
        public static bool User_TryAddNew([NotNull] UserEntry newUser)
        {
            var db          = new SqlUserRepository();
            var isUserExist = db.GetAll().Any(o => o.Login == newUser.Login);

            if (!isUserExist)
            {
                newUser.CreatedAtUtcTicks = DateTime.UtcNow.Ticks;
                db.Add(newUser);
                return(true);
            }
            return(false);
        }