示例#1
0
        //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."));
            }
        }
示例#2
0
 public ActionResult Create(CreateClientViewModel clientViewModel)
 {
     try
     {
         var client = _mapper.Map <CreateClientDTO>(clientViewModel);
         _clientServices.AddClient(client);
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View());
     }
 }
示例#3
0
        //public IActionResult Index()
        //{
        //    return View();
        //}

        public void Index()
        {
            _clientServices.AddClient(new Client());
        }
示例#4
0
 public void Index([FromServices] IClientServices clientServices)
 {
     clientServices.AddClient(new Client());
 }