public async Task <IActionResult> Create(Restaraunt restaraunt) { if (ModelState.IsValid) { RestarauntService restarauntService = new RestarauntService(_configuration); restaraunt.ImageUrl = restarauntService.GetImage(restaraunt.Name); _context.Add(restaraunt); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(restaraunt)); }
public async Task <IActionResult> Edit(int id, Restaraunt restaraunt, IFormFile image) { if (id != restaraunt.Id) { return(NotFound()); } if (ModelState.IsValid) { try { RestarauntService restarauntService = new RestarauntService(_configuration); restaraunt.ImageUrl = restarauntService.GetImage(restaraunt.Name); if (image != null) { using (var stream = new MemoryStream()) { image.CopyTo(stream); restaraunt.Image = stream.ToArray(); } } _context.Update(restaraunt); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RestarauntExists(restaraunt.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Details), new { id = restaraunt.Id })); } return(View(restaraunt)); }