public async Task <IActionResult> ChangeProduct(GiversChangeProductVM giversChangeProductVM) { if (!ModelState.IsValid) { return(View(giversChangeProductVM)); } if (giversChangeProductVM.Picture != null) { var uniqueFileName = Helper.GetUniqueFileName(giversChangeProductVM.Picture.FileName); var images = Path.Combine(hostingEnvironment.WebRootPath, "products"); var filePath = Path.Combine(images, uniqueFileName); giversChangeProductVM.Picture.CopyTo(new FileStream(filePath, FileMode.Create)); giversChangeProductVM.PictureFileName = uniqueFileName; } var giver = await membersService.GetUser(HttpContext.User); giversChangeProductVM.GiverId = giver.Id; giversChangeProductVM.Street = giver.Street; giversChangeProductVM.City = giver.City; giversChangeProductVM.ZipCode = giver.ZipCode; var location = await giversService.GetCoordinates(giver); giversChangeProductVM.Location = location; await giversService.ChangeProductAsync(giversChangeProductVM); return(RedirectToAction(nameof(Products))); }
public async Task ChangeProductAsync(GiversChangeProductVM giversChangeProductVM) { var product = await context.Product.SingleOrDefaultAsync(p => p.Id == giversChangeProductVM.ProductId); product.Description = giversChangeProductVM.Description; product.ExpiryDate = giversChangeProductVM.ExpiryDate; product.Freshness = giversChangeProductVM.Freshness; product.Location = giversChangeProductVM.Location; product.Street = giversChangeProductVM.Street; product.City = giversChangeProductVM.City; product.ZipCode = giversChangeProductVM.ZipCode; product.Name = giversChangeProductVM.ProductName; product.PickUpDate1 = giversChangeProductVM.PickUpDate1; product.PickUpDate2 = giversChangeProductVM.PickUpDate2; product.Picture = giversChangeProductVM.PictureFileName; product.PublishDate = DateTime.Now; await context.SaveChangesAsync(); }