//DONE public ActionResult PostClient(CreateClientVM model) { try { if (ModelState.IsValid) { if (_clientServices.Exists(model.Document)) { return(BadRequest($"Existe un cliente con el documento {model.Document} registrado.")); } var clientToCreate = _mapper.Map <Client>(model); clientToCreate.CreationDate = DateTime.Now; var result = _clientServices.AddClient(clientToCreate); if (!result) { return(StatusCode(StatusCodes.Status500InternalServerError, "Algo salio mal tratando de agregar el cliente, Intente de nuevo o contacta el Administrador.")); } return(Json("El cliente ha sido agregado.")); } return(BadRequest(FormatedModelStateErrors.GetErrorsFormated(ModelState))); } catch (Exception ex) { //TODO: Log the exception return(StatusCode(StatusCodes.Status500InternalServerError, "Algo salio mal tratando de agregar el cliente, Intente de nuevo o contacta el Administrador.")); } }
public ActionResult Create(CreateClientViewModel clientViewModel) { try { var client = _mapper.Map <CreateClientDTO>(clientViewModel); _clientServices.AddClient(client); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
//public IActionResult Index() //{ // return View(); //} public void Index() { _clientServices.AddClient(new Client()); }
public void Index([FromServices] IClientServices clientServices) { clientServices.AddClient(new Client()); }