public async Task <bool> UpdateCrypto(CryptoEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Cryptos .Single(c => c.CryptoID == model.CryptoID && c.OwnerID == _userId); entity.Name = model.Name; entity.Symbol = model.Symbol; return(await ctx.SaveChangesAsync() == 1); } }
public async Task <ActionResult> Edit(int id) { var service = CreateCryptoService(); var detail = await service.GetCryptoByID(id); var model = new CryptoEdit { CryptoID = detail.CryptoID, Name = detail.Name, Symbol = detail.Symbol }; return(View(model)); }
public async Task <ActionResult> Edit(int id, CryptoEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.CryptoID != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateCryptoService(); if (await service.UpdateCrypto(model)) { TempData["SaveResult"] = "The Crypto was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "The Crypto could not be updated."); return(View()); }