public async Task <IActionResult> Create([Bind("PartId,ItemId,PartName,Qty,Barcode,AvgCost,LastCost,SalePrice,More,Active,Starred,Deleted,LastPurchasedDate,AddDate,PartId1")] ItemParts itemParts) { if (ModelState.IsValid) { itemParts.AvgCost = itemParts.Qty * itemParts.SalePrice; // totalPrice = UnitPrice * Quantity _context.Add(itemParts); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index), new { id = itemParts.ItemId })); } else { var invalid = ModelState.Where(p => p.Value.ValidationState == ModelValidationState.Invalid).FirstOrDefault(); ViewData["ErrorMessage"] = "Error:!" + string.Join(",", invalid.Value.Errors.Select(i => i.ErrorMessage)); } var model = new ItemPartsViewModel() { ItemParts = await _context.ItemParts.Include(i => i.Item).Where(p => p.ItemId == itemParts.ItemId).ToListAsync(), ItemPart = new ItemParts() { ItemId = (long)itemParts.ItemId }, Car = await _context.Items.Include(p => p.Make).Include(p => p.Model).FirstOrDefaultAsync(i => i.ItemId == itemParts.ItemId) }; return(View("Index.cshtml", model)); }
/// <summary> /// Initializes a new instance of the <see cref="ConfigurationDictionary"/> class. /// </summary> /// <param name="assetType">Type of the asset.</param> /// <param name="itemPart">The item part.</param> public ConfigurationDictionary(AssetTypes assetType, ItemParts itemPart) { this.dictionary = new Dictionary <string, string>(); this.Changed = true; this.AssetType = assetType; this.ItemPart = itemPart; switch (itemPart) { case ItemParts.Identity: this.assigner = "="; this.separator = ", "; this.preSeparator = null; this.postSeparator = Environment.NewLine; break; case ItemParts.Values: this.assigner = "="; this.separator = Environment.NewLine + "\t"; this.preSeparator = "\t"; this.postSeparator = Environment.NewLine; break; default: this.assigner = "="; this.separator = ", "; this.preSeparator = null; this.postSeparator = null; break; } }
public async Task <IActionResult> Edit(long id, [Bind("PartId,ItemId,PartName,Qty,Barcode,AvgCost,LastCost,SalePrice,More,Active,Starred,Deleted,LastPurchasedDate,AddDate,PartId1")] ItemParts itemParts) { if (id != itemParts.PartId) { return(NotFound()); } if (ModelState.IsValid) { try { itemParts.AvgCost = itemParts.Qty * itemParts.SalePrice; _context.Update(itemParts); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ItemPartsExists(itemParts.PartId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index), new { id = itemParts.ItemId })); } ViewData["ItemId"] = new SelectList(_context.Items, "ItemId", "ItemId", itemParts.ItemId); ViewData["PartId1"] = new SelectList(_context.Parts, "Id", "Name", itemParts.PartId1); return(View(itemParts)); }
public void SetItemPartesFromEnum(Type enumType) { ItemParts.Clear(); if (enumType != null) { // Get all possible enum vals foreach (object item in Enum.GetValues(enumType)) { ItemParts.Add(item.ToString()); } } if (ItemParts.Count > 0) { SelectedItemPart = ItemParts[0]; } }