/// <summary>
 /// Инициализация по имени
 /// </summary>
 /// <param name="email">имя пользователя [email]</param>
 public void Init(string email, IRepository repository)
 {
     if (!string.IsNullOrEmpty(email))
     {
         User = repository.GetUser(email);
     }
 }
Example #2
0
 public bool ChangePassword(User instance)
 {
     var cache = Db.Users.FirstOrDefault(p => p.ID == instance.ID);
     if (cache != null)
     {
         cache.Password = instance.Password;
         Db.Users.Context.SubmitChanges();
         return true;
     }
     return false;
 }
Example #3
0
 public bool ChangeLanguage(User instance, string LangCode)
 {
     var cache = Db.Users.FirstOrDefault(p => p.ID == instance.ID);
     var newLang = Db.Languages.FirstOrDefault(p => p.Code == LangCode);
     if (cache != null && newLang != null)
     {
         cache.Language = newLang;
         Db.Users.Context.SubmitChanges();
         return true;
     }
     return false;
 }
Example #4
0
        public bool ActivateUser(User instance)
        {
            var cache = Db.Users.FirstOrDefault(p => p.ID == instance.ID);
            if (cache != null)
            {
                cache.ActivatedDate = DateTime.Now;
                Db.Users.Context.SubmitChanges();
                return true;
            }

            return false;
        }
Example #5
0
        public void GenerateUsers()
        {
            Users = new List<User>();

            var admin = new User()
            {
                ID = 1,
                ActivatedDate = DateTime.Now,
                ActivatedLink = "",
                Email = "admin",
                FirstName = "",
                LastName = "",
                Password = "******",
                LastVisitDate = DateTime.Now,
            };

            var role = Roles.First(p => p.Code == "admin");
            var userRole = new UserRole()
            {
                User = admin,
                UserID = admin.ID,
                Role = role,
                RoleID = role.ID
            };

            admin.UserRoles =
                new EntitySet<UserRole>() {
                    userRole
                };
            Users.Add(admin);

            Users.Add(new User()
            {
                ID = 2,
                ActivatedDate = DateTime.Now,
                ActivatedLink = "",
                Email = "*****@*****.**",
                FirstName = "Andrey",
                LastName = "Chernikov",
                Password = "******",
                LastVisitDate = DateTime.Now
            });

            this.Setup(p => p.Users).Returns(Users.AsQueryable());
            this.Setup(p => p.GetUser(It.IsAny<string>())).Returns((string email) =>
                Users.FirstOrDefault(p => string.Compare(p.Email, email, 0) == 0));
        }
Example #6
0
        public bool CreateUser(User instance)
        {
            if (instance.ID == 0)
            {
                instance.AddedDate = DateTime.Now;
                instance.LastVisitDate = DateTime.Now;
                instance.ActivatedLink = StringExtension.GenerateNewFile();
                Db.Users.InsertOnSubmit(instance);
                Db.Users.Context.SubmitChanges();

                var lang = Db.Languages.FirstOrDefault(p => p.ID == instance.CurrentLang);
                if (lang != null)
                {
                    CreateOrChangeUserLang(instance, null, lang);
                    return true;
                }

                return true;
            }

            return false;
        }
 partial void DeleteUser(User instance);
 partial void UpdateUser(User instance);
 partial void InsertUser(User instance);
		private void detach_Users(User entity)
		{
			this.SendPropertyChanging();
			entity.Language = null;
		}
		private void attach_Users(User entity)
		{
			this.SendPropertyChanging();
			entity.Language = this;
		}
Example #12
0
        public bool UpdateUser(User instance)
        {
            var cache = Db.Users.FirstOrDefault(p => p.ID == instance.ID);
            if (cache != null)
            {
                cache.Email = instance.Email;
                cache.AvatarPath = instance.AvatarPath;
                Db.Users.Context.SubmitChanges();

                var lang = Db.Languages.FirstOrDefault(p => p.ID == instance.CurrentLang);
                if (lang != null)
                {
                    CreateOrChangeUserLang(instance, cache, lang);
                    return true;
                }

                return true;
            }
            return false;
        }
Example #13
0
 private void CreateOrChangeUserLang(User instance, User cache, Language lang)
 {
     UserLang postLang = null;
     if (cache != null)
     {
         postLang = Db.UserLangs.FirstOrDefault(p => p.UserID == cache.ID && p.LanguageID == lang.ID);
     }
     if (postLang == null)
     {
         var newuserLang = new UserLang
         {
             UserID = instance.ID,
             LanguageID = lang.ID,
             FirstName = instance.FirstName,
             LastName = instance.LastName
         };
         Db.UserLangs.InsertOnSubmit(newuserLang);
     }
     else
     {
         postLang.FirstName = instance.FirstName;
         postLang.LastName = instance.LastName;
     }
     Db.UserLangs.Context.SubmitChanges();
 }