/// <summary> /// Инициализация по имени /// </summary> /// <param name="email">имя пользователя [email]</param> public void Init(string email, IRepository repository) { if (!string.IsNullOrEmpty(email)) { User = repository.GetUser(email); } }
public ActionResult CreateUserAndOAuth(FirstUserViewModel model) { if (Db.SingleOrDefault<User>(u => u.Email == model.Email) == null) { var user = new User { Name = "Администратор", Email = model.Email, UserRoles = Db.Select<Role>() }; Db.SaveOrUpdate(user); var setting = Db.SingleOrDefault<Setting>(s => s.Code == "YandexClientId"); setting.Value = model.YandexClientId; Db.SaveOrUpdate(setting); setting = Db.SingleOrDefault<Setting>(s => s.Code == "YandexPassword"); setting.Value = model.YandexPassword; Db.SaveOrUpdate(setting); return RedirectToAction("Logon", "Account"); } return RedirectToAction("List"); }
public ActionResult AddOrEdit(UserViewModel model) { var item = new User(); if (model.Id > 0) { item = Db.Get<User>(model.Id); } item = Mapper.Map(model, item); var result = Db.SaveOrUpdate(item); return RedirectToAction("List"); }
public User CreateFirstUser(string email) { var user = Db.SingleOrDefault<User>(u => u.Email == email); if (user == null) { user = new User { Name = "Администратор", Email = email, UserRoles = Db.Select<Role>() }; Db.SaveOrUpdate(user); _logger.Info($"Создан первый пользователь '{user}'"); } else { _logger.Warn($"Пользователь '{user}' уже существует"); } return user; }