public async Task <IActionResult> Create(Supplier supplier) { try { supplier.createDateTime = DateTimeOffset.Now; supplier.updateDateTime = DateTimeOffset.Now; if (ModelState.IsValid) { //check model has error _floralContext.supplier.Add(supplier); await _floralContext.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } catch (DbUpdateException) { ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); } return(View(supplier)); }
public async Task <IActionResult> Create(PackageType packageType) { if (ModelState.IsValid) { packageType.createDateTime = DateTimeOffset.Now; packageType.updateDateTime = DateTimeOffset.Now; _context.Add(packageType); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(packageType)); }
public async Task <IActionResult> Create(Tag tag) { if (ModelState.IsValid) { tag.createDateTime = DateTimeOffset.Now; tag.updateDateTime = DateTimeOffset.Now; _context.Add(tag); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["tagType"] = new SelectList(_context.tagType, "Id", "name", tag.tagTypeId); return(View(tag)); }
public async Task <IActionResult> Create(ItemGroup itemGroup) { if (ModelState.IsValid) { itemGroup.createDateTime = DateTimeOffset.Now; itemGroup.updateDateTime = DateTimeOffset.Now; _context.itemGroup.Add(itemGroup); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(itemGroup)); }
public async Task <IActionResult> CreateItem(Item item, string[] selectedTag, string[] selectedItem, string[] selectedItemGroup) { if (ModelState.IsValid) { item.createDateTime = DateTimeOffset.Now; item.updateDateTime = DateTimeOffset.Now; item.image = ""; _context.Add(item); _context.SaveChanges(); var getItemId = _context.item.OrderBy(i => i.Id).Single(); if (selectedItem != null) { var itemList = new List <PackageItem>(); foreach (var packageItem in selectedItem) { var packageItemToAdd = new PackageItem { itemId = getItemId.Id, flowerPackageId = 10, createDateTime = DateTimeOffset.Now, updateDateTime = DateTimeOffset.Now }; itemList.Add(packageItemToAdd); } await _context.SaveChangesAsync(); } if (item.isTag == true) { item.ItemTags = new List <ItemTag>(); foreach (var itemTag in selectedTag) { var itemTagToAdd = new ItemTag { itemId = getItemId.Id, tagId = int.Parse(itemTag), createDateTime = DateTimeOffset.Now, updateDateTime = DateTimeOffset.Now }; item.ItemTags.Add(itemTagToAdd); } await _context.SaveChangesAsync(); } if (selectedItemGroup != null) { item.ItemMmItemGroups = new List <ItemMmItemGroup>(); foreach (var itemMmItemGroup in selectedItemGroup) { var itemMmItemGroupToAdd = new ItemMmItemGroup { itemId = getItemId.Id, itemGroupId = int.Parse(itemMmItemGroup), createDateTime = DateTimeOffset.Now, updateDateTime = DateTimeOffset.Now }; item.ItemMmItemGroups.Add(itemMmItemGroupToAdd); } await _context.SaveChangesAsync(); } return(RedirectToAction(nameof(Index))); } ViewData["packageType"] = new SelectList(_context.packageType, "Id", "name"); ViewData["supplier"] = new SelectList(_context.supplier, "Id", "campanyName"); ViewData["ItemGroup"] = _context.itemGroup; ViewData["Tag"] = _context.tag; ViewData["Items"] = _context.item.Where(i => i.isPackage == false); return(View()); }