public async Task <IViewComponentResult> InvokeAsync(int productId) { var product = await _context.Product.SingleOrDefaultAsync(p => p.Id == productId); ViewData["productId"] = product.Id; ViewData["productName"] = product.Name; ViewData["productDescription"] = product.Description; ViewData["productPrice"] = product.Price; ViewData["productQuantity"] = 1; var deliveryData = new DeliveryDataViewModel(); var dbUser = await _context.Users.SingleOrDefaultAsync(u => u.UserName == User.Identity.Name); if (dbUser != null) { deliveryData = new DeliveryDataViewModel() { FirstName = dbUser.FirstName, LastName = dbUser.LastName, PhoneNumber = dbUser.PhoneNumber, Address = dbUser.Address, City = dbUser.City, CompanyName = dbUser.CompanyName, CompanyEIK = dbUser.CompanyEIK, Tax = dbUser.Tax }; } return(View(deliveryData)); }
public IActionResult EditDeliveryData(DeliveryDataViewModel userVM) { if (ModelState.IsValid) { var user = _context.Users.Single(u => u.UserName == User.Identity.Name); user.FirstName = userVM.FirstName; user.LastName = userVM.LastName; user.PhoneNumber = userVM.PhoneNumber; user.Address = userVM.Address; user.City = userVM.City; user.CompanyName = userVM.CompanyName; user.CompanyEIK = userVM.CompanyEIK; user.Tax = userVM.Tax; _context.Update(user); _context.SaveChanges(); return RedirectToAction("Index", "Home"); } return View(userVM); }