public void DeleteUnit(int unitId) { ApartmentsDbContext con = new ApartmentsDbContext(); Unit unit = con.Units.FirstOrDefault(unit => unit.Id == unitId); con.Units.Remove(unit); con.SaveChanges(); }
public void DeleteGroup(int groupId) { ApartmentsDbContext con = new ApartmentsDbContext(); UnitGroup unitGroup = con.UnitGroups.FirstOrDefault(unitGroup => unitGroup.Id == groupId); con.UnitGroups.Remove(unitGroup); con.SaveChanges(); }
public static void SetUserIdByApplicationUser(ApplicationUser applicationUser) { var dbContext = new ApartmentsDbContext(); //TODO Metoda z repa, pokud zustanou dve DB var user = dbContext.Users.FirstOrDefault(usr => usr.Username == applicationUser.UserName); if (user == null) // does not exist yet { user = new User { Username = applicationUser.UserName, Email = applicationUser.Email, IsAdmin = false, Password = "******" }; dbContext.Users.Add(user); dbContext.SaveChanges(); } UserId = user.Id; }
public bool SaveChanges() { return(_context.SaveChanges() >= 0); }
public void Insert(Apartment entity) { _context.Apartments.Add(entity); _context.SaveChanges(); }