public async Task <IActionResult> Edit(int id, [Bind("Id,Text,ShopOwnerId")] ShopHashtag shopHashtag) { if (id != shopHashtag.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(shopHashtag); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ShopHashtagExists(shopHashtag.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ShopOwnerId"] = new SelectList(_context.ShopOwners, "Id", "Id", shopHashtag.ShopOwnerId); return(View(shopHashtag)); }
public async Task <IActionResult> Create([Bind("Id,Text")] ShopHashtag shopHashtag) { if (ModelState.IsValid) { var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); var shopOwner = _context.ShopOwners.Where(n => n.ApplicationUserId == userId).FirstOrDefault(); var shopHashtagTexts = shopHashtag.Text.Split(",").ToList(); foreach (var s in shopHashtagTexts) { ShopHashtag newShopHashtag = new ShopHashtag(); newShopHashtag.ShopOwner = shopOwner; newShopHashtag.ShopOwnerId = shopOwner.Id; newShopHashtag.Text = s; newShopHashtag.ZipCode = shopOwner.ZipCode; _context.Add(newShopHashtag); await _context.SaveChangesAsync(); } return(RedirectToAction("Index", "Home")); } ViewData["ShopOwnerId"] = new SelectList(_context.ShopOwners, "Id", "Id", shopHashtag.ShopOwnerId); return(View(shopHashtag)); }