Example #1
0
        public static bool AddUser(User user)
        {
            using (var db = new WorkitContext())
            {
                var newUser = new User
                                  {
                                      Id = Guid.NewGuid(),
                                      Email = user.Email.ToLower(),
                                      IsActive = false,
                                      Password = user.Password,
                                      RegistrationDate = DateTime.Now
                                  };
                newUser.Token = newUser.Id.ToString().Replace("-", string.Empty).Take(10).ToString().ToLower();

                try
                {
                    db.Users.Add(user);
                    db.SaveChanges();
                    return true;
                }
                catch (Exception ex)
                {
                    Loggers.ExeptionLogger.AddExeption(ex, "AddUser", db);
                    return false;
                }

                //TODO: Отправка сообщения о подвтерждении
            }
        }
Example #2
0
        public static bool ActivateUser(string token)
        {
            token = token.ToUpper();
            using (var db = new WorkitContext())
            {
                var user = db.Users.FirstOrDefault(u => u.Token == token);
                if (user == null) return false;

                user.IsActive = true;
                try
                {
                    db.SaveChanges();
                    return true;
                }
                catch(Exception ex)
                {
                    Loggers.ExeptionLogger.AddExeption(ex, "ActivateUser", db);
                    return false;
                }
            }
        }