public async Task UpdateStorageUnit(int id, StorageUnitViewModel viewModel) { var storageUnit = _mapper.Map <StorageUnit>(viewModel); storageUnit.Id = id; _context.StorageUnits.Update(storageUnit); await _context.SaveChangesAsync(); }
public async Task <StorageUnit> CreateStorageUnit(StorageUnitViewModel viewModel) { var storageUnit = _mapper.Map <StorageUnit>(viewModel); _context.StorageUnits.Add(storageUnit); await _context.SaveChangesAsync(); return(storageUnit); }
public async Task <StorageUnitViewModel> GetRelatedEntities() { var viewModel = new StorageUnitViewModel() { Warehouses = await _context.Warehouses.ToListAsync(), Sectors = await _context.Sectors.ToListAsync() }; return(viewModel); }
public async Task FillWarehouseAddress(StorageUnitViewModel viewModel, int?storageUnitId) { var storageUnit = await _context.StorageUnits.FindAsync(storageUnitId); var address = await _context.Addresses .SingleOrDefaultAsync(a => a.WarehouseId == storageUnit.WarehouseId); viewModel.WarehouseAddress .Add(storageUnit.WarehouseId, address.Location); }
public void GetStorageUnitSectors(StorageUnitViewModel viewModel) { var storageUnitSectors = ""; foreach (var sector in viewModel.Sectors) { storageUnitSectors += $"{sector.Id}, "; } viewModel.StorageUnitSectors = storageUnitSectors == "" ? "no sectors" : storageUnitSectors.Substring(0, storageUnitSectors.Length - 2); }
public async Task <IActionResult> Edit(int id, StorageUnitViewModel viewModel) { if (ModelState.IsValid) { await _service.UpdateStorageUnit(id, viewModel); return(RedirectToAction(nameof(Index))); } return(View(viewModel)); }
public async Task FillWarehouseAddresses(StorageUnitViewModel viewModel) { var address = new Address(); foreach (var warehouse in viewModel.Warehouses) { address = await _context.Addresses .SingleOrDefaultAsync(a => a.WarehouseId == warehouse.Id); viewModel.WarehouseAddress.Add(warehouse.Id, address.Location); } }
public async Task CreateStorageUnitSector(StorageUnitViewModel viewModel, int storageUnitId) { for (int i = 0; i < viewModel.NumberOfSectors; i++) { await _context.Sectors .AddAsync(new Sector() { StorageUnitId = storageUnitId }); } await _context.SaveChangesAsync(); }
public async Task <IActionResult> Create(StorageUnitViewModel viewModel) { if (ModelState.IsValid) { var storageUnit = await _service.CreateStorageUnit(viewModel); await _service.CreateStorageUnitSector(viewModel, storageUnit.Id); return(RedirectToAction(nameof(Index))); } return(View(viewModel)); }