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("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("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("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("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("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("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 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 ExistSomeAssetsFixture() { AssetContext.Add <Asset>(new Asset() { ID = 1, AssetName = "Test asset", Department = Department.HQ, Broken = false, CountryOfDepartment = "LVA", EMailAdressOfDepartment = "*****@*****.**", PurchaseDate = DateTime.UtcNow }); AssetContext.SaveChanges(); AssetService = new AssetService(Mapper, AssetRepository, UnitOfWork); }
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 <IActionResult> Create([Bind("AssetId,AssetName,AssetPurchaseDate,AssetExpirationDate,AssetWarningDate,AssetPrice,AssetActive,OfficeId,CategoryId")] Asset asset) { if (ModelState.IsValid) { // Calculate End Of Life and Warning date var lifespan = await _context.Categories.FirstOrDefaultAsync(b => b.CategoryId == asset.CategoryId); asset.AssetExpirationDate = asset.AssetPurchaseDate.AddMonths(lifespan.CategoryEOLMonths); asset.AssetWarningDate = asset.AssetPurchaseDate.AddMonths(lifespan.CategoryEOLMonths - 3); _context.Add(asset); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CategoryId"] = new SelectList(_context.Categories, "CategoryId", "CategoryName", asset.CategoryId); ViewData["OfficeId"] = new SelectList(_context.Offices, "OfficeId", "OfficeName", asset.OfficeId); return(View(asset)); }
private void AddWithCategory() { //Get the info, user assigns the values Console.WriteLine("Name of Asset: "); var assetName = Console.ReadLine(); Console.WriteLine("Model of Asset: "); var assetModel = Console.ReadLine(); Console.WriteLine("Category of Asset: "); var assetCategory = Console.ReadLine(); Console.WriteLine("Price of Asset: "); float assetPrice = float.Parse(Console.ReadLine()); //create an asset-object var asset = new Asset { AssetName = assetName, AssetModel = assetModel, CategoryObject = new Category { CategoryName = assetCategory }, price = assetPrice, //purchaseDate = , //expirationDate = 2 , }; //type it out Console.WriteLine(asset.AssetName + asset.AssetModel + asset.CategoryObject.CategoryName + asset.price); //add it to the database context.Add(asset); context.SaveChanges(); PrintList(); Console.ReadKey(); Start(); }