// Bind(Include = "...") is used to avoid overposting attacks public async Task <ActionResult> Edit(MvcDepartamentoModel departamento) { try { var entity = _mapper.Map <Departamento>(departamento); await _departamentoEndpoint.Put(entity, _userSession.BearerToken); } catch (UnauthorizedRequestException) { return(RedirectToAction("AccessDeniedPartial", "Error")); } catch (BadRequestException ex) { ModelState.AddModelErrors(ex.Errors); return(PartialView("_Edit", departamento)); } catch (Exception ex) { return(RedirectToAction("SpecificErrorPartial", "Error", new { error = ex.Message })); } return(Content("OK")); }
public async void Edit() { ErrorMessages = null; var materia = new WpfDepartamentoModel { Id = SelectedDepartamento.Id, Name = NameInForm }; try { var entity = _mapper.Map <Departamento>(materia); await _departamentoEndpoint.Put(entity, _usuarioLogged.Token); await LoadDepartamentos(); } catch (UnauthorizedRequestException) { ErrorMessages = new BindingList <string> { "No tiene acceso" }; } catch (BadRequestException ex) { ErrorMessages = new BindingList <string>(ex.Errors.Select(kvp => string.Join(". ", kvp.Value)).ToList()); } catch (Exception ex) { ErrorMessages = new BindingList <string> { $"{ex.Message} Ha ocurrido un error. Por favor contacte a soporte" }; } }