public IActionResult Add([FromForm] Models.Trbovlje.StorageLocationViewModel storageLocation) { if (!ModelState.IsValid) { return(View(storageLocation)); } StorageLocation dbStorageLocation = new StorageLocation(); _mapper.Map(storageLocation, dbStorageLocation); _dbContext.StorageLocations.Add(dbStorageLocation); _dbContext.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult StorageLocation([FromForm] Models.Trbovlje.StorageLocationViewModel storageLocation) { if (!ModelState.IsValid) { return(View(storageLocation)); } var dbStorageLocation = _dbContext.StorageLocations.FirstOrDefault(u => u.Id == storageLocation.Id); if (dbStorageLocation == null) { return(RedirectToAction("Index")); } _mapper.Map(storageLocation, dbStorageLocation); _dbContext.StorageLocations.Update(dbStorageLocation); _dbContext.SaveChanges(); return(RedirectToAction("Index")); }