Exemplo n.º 1
0
 public static IQueryable GetAllUsers()
 {
     using (var db = new WorkitContext())
     {
         return db.Users.OrderByDescending(u => u.RegistrationDate);
     }
 }
Exemplo n.º 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: Отправка сообщения о подвтерждении
            }
        }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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);
        }
Exemplo n.º 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;
                }
            }
        }
Exemplo n.º 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);
     }
 }
Exemplo n.º 7
0
 public static User GetUserById(Guid userId)
 {
     using (var db = new WorkitContext())
     {
         return db.Users.FirstOrDefault(u => u.Id == userId);
     }
 }