public async Task <IActionResult> PutStaff(int id, Staff staff) { if (id != staff.StaffId) { return(BadRequest()); } _context.Entry(staff).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StaffExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutAsset(Guid id, Asset asset) { if (id != asset.AssetId) { _logger.LogDebug($"Invalid asset {id} provided."); return(BadRequest()); } _context.Entry(asset).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException ex) { if (!AssetExists(id)) { _logger.LogError($"Asset with ID {id} does not exist. Details: {ex.Message}"); return(NotFound()); } else { _logger.LogError($"Details: {ex.Message}"); throw; } } return(NoContent()); }
public async Task <IActionResult> PutAsset(Guid id, Asset asset) { if (id != asset.AssetId) { return(BadRequest()); } _context.Entry(asset).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AssetExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutInventory(int id, Inventory inventory) { if (id != inventory.InventoryId) { return(BadRequest()); } _context.Entry(inventory).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!InventoryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task Delete(int?id) { if (await Exist(id)) { var entity = await Find(id); _ctx.Remove(entity); await _ctx.SaveChangesAsync(); } }
public async Task <IActionResult> Create([Bind("DepreciationID,DepreciationName,DepreciationDescription")] Depreciation depreciation) { if (ModelState.IsValid) { _context.Add(depreciation); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(depreciation)); }
public async Task <IActionResult> Create([Bind("CountryId,CountryName,CountryDescription,CountryVisible")] Country country) { if (ModelState.IsValid) { _context.Add(country); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(country)); }
public async Task <IActionResult> Create([Bind("CategoryId,CategoryName,CategoryEOLMonths,CategoryActive,CategoryComment")] Category category) { if (ModelState.IsValid) { _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Create([Bind("CurrencyID,CurrencyName,CurrencyDescription,ExchangeRate,CurrencyDefault,CurrencyActive")] Currency currency) { if (ModelState.IsValid) { _context.Add(currency); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(currency)); }
public async Task <IActionResult> Create([Bind("AssetId,MimeType,Country,FileName,CreatedBy,Email,Description,CreatedOn")] Asset asset) { if (ModelState.IsValid) { asset.AssetId = Guid.NewGuid(); _context.Add(asset); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(asset)); }
public async Task <IActionResult> Create([Bind("OfficeId,OfficeName,OfficeCountry,CurrencyId")] Office office) { if (ModelState.IsValid) { _context.Add(office); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CurrencyId"] = new SelectList(_context.Currencies, "Id", "Id", office.CurrencyId); return(View(office)); }
public async Task <IActionResult> Create([Bind("SupplierID,SupplierName,SupplierDescription,SupplierEmail,SupplierContactFirstName,SupplierContactLastName,SupplierContactEmail,SupplierCity,CountryID,SupplierAddress,SupplierActive")] Supplier supplier) { if (ModelState.IsValid) { _context.Add(supplier); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CountryID"] = new SelectList(_context.Countries, "CountryId", "CountryDescription", supplier.CountryID); return(View(supplier)); }
public async Task <IActionResult> Create([Bind("Id,CurrencyName,CurrensyToUSD,CurrencyComment")] Currency currency) { if (ModelState.IsValid) { currency.CurrensyToUSD = currency.CurrensyToUSD / 100; _context.Add(currency); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(currency)); }
public async Task <IActionResult> Create([Bind("CategoryId,CategoryName,CategoryEOLMonths,CategoryActive,CategoryComment,DepreciationID")] Category category) { if (ModelState.IsValid) { _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["DepreciationID"] = new SelectList(_context.Depreciations, "DepreciationID", "DepreciationDescription", category.DepreciationID); return(View(category)); }
public async Task <IActionResult> Create([Bind("OfficeID,OfficeName,OfficeDescription,CountryID,CurrencyID,OfficeActive")] Office office) { if (ModelState.IsValid) { _context.Add(office); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CountryID"] = new SelectList(_context.Countries, "CountryId", "CountryDescription", office.CountryID); ViewData["CurrencyID"] = new SelectList(_context.Currencies, "CurrencyID", "CurrencyName", office.CurrencyID); return(View(office)); }
public async Task <IActionResult> Create([Bind("ReplacementID,CatalogueID,ReplacingID")] Replacement replacement) { if (ModelState.IsValid) { _context.Add(replacement); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CatalogueID"] = new SelectList(_context.Catalogues.Where(a => a.Obsolete == true), "CatalogueID", "ProductName", replacement.CatalogueID); ViewData["ReplacingID"] = new SelectList(_context.Catalogues.Where(a => a.Obsolete == false), "CatalogueID", "ProductName", replacement.ReplacingID); return(View(replacement)); }
public async Task <IActionResult> Create([Bind("CatalogueID,ProductName,ProductDescription,CategoryID,CataloguePrice,SupplierProductID,SupplierID,Obsolete,CatalogueItemActive")] Catalogue catalogue) { if (ModelState.IsValid) { _context.Add(catalogue); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CategoryID"] = new SelectList(_context.Categories, "CategoryId", "CategoryName", catalogue.CategoryID); ViewData["SupplierID"] = new SelectList(_context.Suppliers, "SupplierID", "SupplierName", catalogue.SupplierID); return(View(catalogue)); }
public override async Task <int> Save(Asset asset) { await _ctx.Assets.AddAsync(asset); await _ctx.SaveChangesAsync(); return(asset.Id); }
public async Task <IActionResult> Create([Bind("AssetID,CatalogueID,AssetPurchaseDate,AssetExpirationDate,AssetPrice,AssetValue,AssetActive,OfficeID")] Asset asset) { if (ModelState.IsValid) { // Select Catalogue item to populate price and EOL lifespan from Category var catalogueItem = await _context.Catalogues.Include(b => b.Category).FirstOrDefaultAsync(a => a.CatalogueID == asset.CatalogueID); asset.AssetExpirationDate = asset.AssetPurchaseDate.AddMonths(catalogueItem.Category.CategoryEOLMonths); asset.AssetPrice = catalogueItem.CataloguePrice; _context.Add(asset); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CatalogueID"] = new SelectList(_context.Catalogues.Where(a => a.Obsolete == false), "CatalogueID", "ProductName", asset.CatalogueID); ViewData["OfficeID"] = new SelectList(_context.Offices.Where(a => a.OfficeActive == true), "OfficeID", "OfficeName", asset.OfficeID); return(View(asset)); }
public async Task DeleteAssetAsync(int assetId) { var context = new AssetContext(); var asset = new Asset { Id = assetId }; context.Assets.Attach(asset); context.Entry(asset).State = EntityState.Deleted; await context.SaveChangesAsync(); }
public async Task <Users> Register(Users user, string password) { byte[] passwordHash, passwordSalt; CreatePasswordhash(password, out passwordHash, out passwordSalt); user.PasswordHash = passwordHash; user.PasswordSalt = passwordSalt; await _context.Users.AddAsync(user); await _context.SaveChangesAsync(); return(user); }
public async Task <IActionResult> ActivateAsset(int id) { var asset = await _context.Assets.FirstOrDefaultAsync(a => a.AssetId == id); asset.AssetActive = true; _context.Update(asset); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(InactiveAssets))); }
public async Task <int> SaveAssetAsync(Asset model) { var context = new AssetContext(); if (model.Id == 0) { context.Assets.Add(model); } else { context.Assets.Attach(model); context.Entry(model).State = EntityState.Modified; } await context.SaveChangesAsync(); return(model.Id); }
public async Task CreateAsset(Asset asset) { _assetContext.Assets.Add(asset); await _assetContext.SaveChangesAsync(); }