public async Task <IActionResult> Edit(int id, [Bind("Id,Name,AvatarPath,SkillsTags,Reliability,Status,CurrentJobId")] Android android, IFormFile avatar) { if (id != android.Id) { return(NotFound()); } if (ModelState.IsValid) { try { if (avatar != null) { if (android.AvatarPath != null) { try { System.IO.File.Delete(_appEnvironment.WebRootPath + "/Avatars/" + Path.GetFileName(android.AvatarPath)); } catch (System.IO.IOException e) { _logger.LogWarning("Failed to delete android avatar file. File path: {}", android.AvatarPath); } } string path = GetAvatarPath(avatar); android.AvatarPath = "~/" + path; using (var fileStream = new FileStream(_appEnvironment.WebRootPath + "/" + path, FileMode.Create)) { await avatar.CopyToAsync(fileStream); } } if (android.Reliability == 0) { android.Status = false; } _context.Update(android); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AndroidExists(android.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } return(View(android)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Description,Complexity")] Job job) { if (id != job.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(job); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!JobExists(job.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } return(View(job)); }