public async Task <ActionResult> Create(MvcDepartamentoModel departamento) { try { var entity = _mapper.Map <Departamento>(departamento); await _departamentoEndpoint.Post(entity, _userSession.BearerToken); } catch (UnauthorizedRequestException) { return(RedirectToAction("AccessDeniedPartial", "Error")); } catch (BadRequestException ex) { ModelState.AddModelErrors(ex.Errors); return(PartialView("_Create", departamento)); } catch (Exception ex) { return(RedirectToAction("SpecificErrorPartial", "Error", new { error = ex.Message })); } return(Content("OK")); }
public async void Create() { ErrorMessages = null; var departamento = new WpfDepartamentoModel { Name = NameInForm }; try { var entity = _mapper.Map <Departamento>(departamento); await _departamentoEndpoint.Post(entity, _usuarioLogged.Token); await LoadDepartamentos(); SelectedDepartamento = null; } 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" }; } }