public void SaveHouseplant(Houseplant houseplant) { if (houseplant.HouseplantId == 0) { context.Houseplants.Add(houseplant); } else { Houseplant dbEntry = context.Houseplants.FirstOrDefault(e => e.HouseplantId == houseplant.HouseplantId); if (dbEntry != null) { dbEntry.Name = houseplant.Name; dbEntry.NameLatin = houseplant.NameLatin; dbEntry.Thumbnail = houseplant.Thumbnail; //gallery dbEntry.BuyDate = houseplant.BuyDate; dbEntry.LastPlantDate = houseplant.LastPlantDate; dbEntry.IrrigationDescription = houseplant.IrrigationDescription; dbEntry.Fertigation = houseplant.Fertigation; } } context.SaveChanges(); }
public async Task <IActionResult> Edit(Houseplant houseplant) { using (var memoryStream = new MemoryStream()) { // Upload the file if less than 2 MB if (memoryStream.Length < 2097152) { await houseplant.ImageFile.CopyToAsync(memoryStream); houseplant.Thumbnail = memoryStream.ToArray(); } } if (ModelState.IsValid) { repoHouseplants.SaveHouseplant(houseplant); return(RedirectToAction("Index")); } else { return(View(houseplant)); } }