protected override void Seed(CarRentalSystemContext context) { List <CarState> carStates = context.States.ToList(); if (carStates.Count == 0) { string[] states = new string[] { "free", "rented" }; foreach (string state in states) { CarState carState = new CarState() { Value = state }; context.States.Add(carState); } context.SaveChanges(); } CarState carFreeState = context.States.FirstOrDefault(cs => cs.Value == "free"); List <Store> stores = context.Stores.ToList(); if (stores.Count == 0) { string[] storeNames = new string[] { "Store1", "Store2", "Store3" }; foreach (string storeName in storeNames) { Store store = new Store() { Name = storeName, Latitude = 23.333m, Longitude = 41.111m }; context.Stores.Add(store); for (int i = 0; i < 5; i++) { Car car = new Car() { Make = "CarMake" + i, Model = "Model" + i, Year = 1982 + i, Power = 74 + i * 10, Engine = 2000 + i * 100, Store = store, State = carFreeState }; context.Cars.Add(car); } } } context.SaveChanges(); }
public override void CreateRole(string roleName) { Role newRole = new Role() { Name = roleName }; CarRentalSystemContext db = new CarRentalSystemContext(); db.Roles.Add(newRole); db.SaveChanges(); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { User user = null; using (CarRentalSystemContext db = new CarRentalSystemContext()) { user = unit.Users.GetAll().FirstOrDefault(u => u.Email == model.Email); } if (user == null) { // создаем нового пользователя using (CarRentalSystemContext db = new CarRentalSystemContext()) { unit.Users.Create(new User { Email = model.Email, Password = model.Password, FirstName = model.FirstName, LastName = model.LastName, ConfirmPassword = model.ConfirmPassword, Gender = model.Gender, Skype = model.Skype, Telephone = model.Telephone, RoleId = 2 }); unit.Save(); //db.SaveChanges(); user = unit.Users.GetAll().Where(u => u.Email == model.Email && u.Password == model.Password).FirstOrDefault(); } // если пользователь удачно добавлен в бд if (user != null) { FormsAuthentication.SetAuthCookie(model.Email, true); return(RedirectToAction("Index", "Home")); } } else { ModelState.AddModelError("", "Пользователь с таким логином уже существует"); } } return(View(model)); }
public override string[] GetRolesForUser(string username) { string[] role = new string[] { }; using (CarRentalSystemContext db = new CarRentalSystemContext()) { // Получаем пользователя User user = db.Users.FirstOrDefault(u => u.Email == username); if (user != null) { // получаем роль Role userRole = db.Roles.Find(user.RoleId); if (userRole != null) { role = new string[] { userRole.Name } } ; } } return(role);; }
public override bool IsUserInRole(string username, string roleName) { bool outputResult = false; // Находим пользователя using (CarRentalSystemContext db = new CarRentalSystemContext()) { // Получаем пользователя User user = db.Users.FirstOrDefault(u => u.Email == username); if (user != null) { // получаем роль Role userRole = db.Roles.Find(user.RoleId); //сравниваем if (userRole != null && userRole.Name == roleName) { outputResult = true; } } } return(outputResult); }
public ActionResult Login(LoginModel model) { if (ModelState.IsValid) { // поиск пользователя в бд User user = null; using (CarRentalSystemContext db = new CarRentalSystemContext()) { user = unit.Users.GetAll().FirstOrDefault(u => u.Email == model.Email && u.Password == model.Password); } if (user != null) { FormsAuthentication.SetAuthCookie(model.Email, true); return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", "Пользователя с таким логином и паролем нет"); } } return(View(model)); }
public TransmissionRepository(CarRentalSystemContext context) { this._applicationDbContext = context; }
public DriveUnitRepository(CarRentalSystemContext context) { this._applicationDbContext = context; }
public MarkRepository(CarRentalSystemContext context) { this._applicationDbContext = context; }
public OrderHistoryRepository(CarRentalSystemContext context) { this._applicationDbContext = context; }
public CarPicturesRepository(CarRentalSystemContext context) { this._applicationDbContext = context; }