public static void SetUserIdByUsername(string username) { using (var dbContext = new ApartmentsDbContext()) { var user = dbContext.Users.FirstOrDefault(usr => usr.Username == username); UserId = user.Id; } }
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 void DeleteUnit(int unitId) { ApartmentsDbContext con = new ApartmentsDbContext(); Unit unit = con.Units.FirstOrDefault(unit => unit.Id == unitId); con.Units.Remove(unit); con.SaveChanges(); }
public ActionResult <int> GetFirstUnitGroupIdByUserId(int userId) { ApartmentsDbContext con = new ApartmentsDbContext(); UnitGroup unitGroup = con.UnitGroups.FirstOrDefault(unitGroup => unitGroup.UserId == userId); if (unitGroup == null) { return(NotFound()); } return(unitGroup.Id); }
public async Task <IActionResult> DeleteEquipment(int equipmentId, int unitId) { var dbContext = new ApartmentsDbContext(); var equipments = await _equipmentFacade.GetEquipmentsByUnitIdAsync <EquipmentDTO>(unitId); var equipment = equipments.Where(e => e.Id == equipmentId).FirstOrDefault(); // TODO specify amount of items to be deleted equipment.UnitEquipments = new List <UnitEquipment>(); var equipmentDTO = new EquipmentDTO { Id = equipment.Id, Type = equipment.Type, UnitEquipments = equipment.UnitEquipments }; await _equipmentFacade.UpdateEquipmentAsync(equipmentDTO); await _equipmentFacade.DeleteEquipmentAsync(equipmentId); return(RedirectToAction(nameof(ShowEquipments), new { unitId })); }
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; }
// Constructor public UnitOfWork() { _dbContext = new ApartmentsDbContext(); // Initialization AddressRepository = new Repository <Address>(_dbContext); EquipmentRepository = new Repository <Equipment>(_dbContext); SpecificationRepository = new Repository <Specification>(_dbContext); UnitRepository = new Repository <Unit>(_dbContext); UnitGroupRepository = new Repository <UnitGroup>(_dbContext); UnitTypeRepository = new Repository <UnitType>(_dbContext); UserRepository = new Repository <User>(_dbContext); ColorRepository = new Repository <Color>(_dbContext); CostRepository = new Repository <Cost>(_dbContext); UnitGroupsWithUsersWithSpecificationsQuery = new UnitGroupsWithUsersWithSpecificationsQuery(_dbContext); UnitGroupsWithUsersQuery = new UnitGroupsWithUsersQuery(_dbContext); UserQuery = new UserQuery(_dbContext); UsersUnitGroupsWithUnitsQuery = new UsersUnitGroupsWithUnitsQuery(_dbContext); UnitsWithUnitGroupsQuery = new UnitsWithUnitGroupsQuery(_dbContext); CostQuery = new CostQuery(_dbContext); EquipmentQuery = new EquipmentQuery(_dbContext); }
public async Task <IActionResult> CreateEquipment(int unitId, string type) { // TODO specify amount of items to be created var dbContext = new ApartmentsDbContext(); var equipments = dbContext.Equipments.Where(equipment => equipment.Type == type).ToList(); var equipmentDTO = new EquipmentDTO(); if (equipments.Count == 0) { equipmentDTO.Type = type; equipmentDTO.UnitEquipments = new List <UnitEquipment>(); await _equipmentFacade.CreateEquipmentAsync(equipmentDTO); equipments = dbContext.Equipments.Where(equipment => equipment.Type == type).ToList(); } var equipment = equipments.First(); equipmentDTO.Type = equipment.Type; equipmentDTO.UnitEquipments = equipment.UnitEquipments; equipmentDTO.Id = equipment.Id; var unitEquipment = new UnitEquipment { EquipmentId = equipment.Id, UnitId = unitId }; equipmentDTO.UnitEquipments.Add(unitEquipment); await _equipmentFacade.UpdateEquipmentAsync(equipmentDTO); return(RedirectToAction(nameof(ShowEquipments), new { unitId })); }
public UserQuery(ApartmentsDbContext dbContext) : base(dbContext) { }
public AddressQuery(ApartmentsDbContext dbContext) : base(dbContext) { }
public EquipmentQuery(ApartmentsDbContext apartmentsDbContext) : base(apartmentsDbContext) { _query = _query.Include(equipment => equipment.UnitEquipments); }
public Query(ApartmentsDbContext dbContext) { _query = dbContext.Set <TEntity>(); }
public CostQuery(ApartmentsDbContext apartmentsDbContext) : base(apartmentsDbContext) { }
public SpecificationQuery(ApartmentsDbContext dbContext) : base(dbContext) { }
public UnitTypeQuery(ApartmentsDbContext context) : base(context) { }
public UnitGroupsWithUsersWithSpecificationsQuery(ApartmentsDbContext apartmentsDbContext) : base(apartmentsDbContext) { _query = _query.Include(unitGroup => unitGroup.User); _query = _query.Include(unitGroup => unitGroup.Specification); }
public UnitGroupQuery(ApartmentsDbContext context) : base(context) { }
public Repository(ApartmentsDbContext context) { _context = context; }
public UnitsWithUnitGroupsQuery(ApartmentsDbContext apartmentsDbContext) : base(apartmentsDbContext) { _query = _query.Include(unit => unit.UnitGroup); }
public ListingService(ApartmentsDbContext context, IWebHostEnvironment env) { _context = context; _env = env; }
public UnitGroupsWithUsersQuery(ApartmentsDbContext apartmentsDbContext) : base(apartmentsDbContext) { _query = _query.Include(unitGroup => unitGroup.User); }