Пример #1
0
 public static IQueryable GetAllUsers()
 {
     using (var db = new WorkitContext())
     {
         return db.Users.OrderByDescending(u => u.RegistrationDate);
     }
 }
Пример #2
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: Отправка сообщения о подвтерждении
            }
        }
Пример #3
0
 public static User ChecAkuth(User user)
 {
     using (var db = new WorkitContext())
     {
         user.Email = user.Email.ToLower();
         return db.Users.FirstOrDefault(u => u.Email == user.Email && u.Password == user.Password);
     }
 }
Пример #4
0
        protected void Application_Start()
        {
            Database.SetInitializer<WorkitContext>(new WorkitContextInitializer());

            using (var db = new WorkitContext())
            {
                Core.Loggers.ExeptionLogger.AddExeption(new Exception("Start Application"), "ApplicationStart", db);
            }

            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
        }
Пример #5
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;
                }
            }
        }
Пример #6
0
 public static bool MailIsFree(string email)
 {
     email = email.ToLower();
     using (var db = new WorkitContext())
     {
         var user = db.Users.FirstOrDefault(u => u.Email == email);
         return (user == null);
     }
 }
Пример #7
0
 public static User GetUserById(Guid userId)
 {
     using (var db = new WorkitContext())
     {
         return db.Users.FirstOrDefault(u => u.Id == userId);
     }
 }