public async Task <IActionResult> ProductEditFinal() { try { Item basicItem = await sessionHelper.GetObjectFromJson <Item>("basicItem"); if (basicItem != null) { LocalItem localItem = await sessionHelper.GetObjectFromJson <LocalItem>("localItem"); FoodItem foodItem = await sessionHelper.GetObjectFromJson <FoodItem>("foodItem"); JsonBoxModel pictureFilePath = await sessionHelper.GetObjectFromJson <JsonBoxModel>("pictureFilePath"); basicItem.PictureFilePath = (string)pictureFilePath?.Value ?? ""; basicItem.LocalItem = localItem; basicItem.FoodItem = foodItem; if (await db.Items.ContainsAsync(basicItem)) { await logger.AddToLogAsync($"Updated product ID:{basicItem.Id}"); db.Items.Update(basicItem); } else { await logger.AddToLogAsync($"Added product ID:{basicItem.Id}"); db.Items.Add(basicItem); } await db.SaveChangesAsync(); } } finally { await sessionHelper.RemoveAsync("basicItem"); await sessionHelper.RemoveAsync("localItem"); await sessionHelper.RemoveAsync("foodItem"); await sessionHelper.RemoveAsync("pictureFilePath"); } return(RedirectToAction("Products")); }