public async Task <ActionResult> Edit(int id, [FromForm] CreateDeveloperDTO dto) { var validator = new DevelopUpdateFluentValidator(_context, id); var errors = await validator.ValidateAsync(dto); if (!errors.IsValid) { var mapped = errors.Errors.Select(x => new { Name = x.PropertyName, Error = x.ErrorMessage }).ToArray(); TempData["error"] = "Please fill all blank boxes."; //mapped.ToString(); return(RedirectToAction(nameof(Create))); } try { // TODO: Add update logic here await _developerService.Update(id, dto); return(RedirectToAction(nameof(Index))); } catch (EntityNotFoundException e) { TempData["error"] = e.Message; return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public async Task <IActionResult> Put(int id, [FromBody] CreateDeveloperDTO dto) { var validator = new DevelopUpdateFluentValidator(_context, id); var errors = await validator.ValidateAsync(dto); if (!errors.IsValid) { return(UnprocessableEntity(ValidationFormatter.Format(errors))); } try { await _developerService.Update(id, dto); return(NoContent()); } catch (EntityNotFoundException e) { return(NotFound(e.Message)); } catch (Exception) { return(StatusCode(500, new { ServerErrorResponse.Message })); } }