public ActionResult RegisterCliente(Cliente cliente) { if (ModelState.IsValid) { cliente.FechaRegistro = DateTime.Now; clientesService.CreateCliente(cliente); return(RedirectToAction("Index")); } return(RedirectToAction("RegisterCliente")); }
public ActionResult Create(ClienteDTO clienteDTO) { try { var cliente = _mapper.Map <Cliente>(clienteDTO); var clienteEmail = _clientesService.GetClienteByEmail(cliente.Email); if (clienteEmail == null) { cliente.Id = string.Empty; _clientesService.CreateCliente(cliente); return(NoContent()); } else { return(Ok("Email já utilizado")); } } catch (Exception ex) { return(BadRequest(new { message = ex.Message })); } }
public ClientesModule(IClientesService clientesService) : base("/clientes") { Get("/", args => { return(clientesService.GetClientes()); }); Get("/{id}", args => { Cliente cliente = clientesService.GetCliente(args.id); if (cliente != null) { return(cliente); } else { return(new Response { StatusCode = HttpStatusCode.NotFound }); } }); Post("/", args => { var cliente = this.Bind <Cliente>(); if (cliente.Name == null || cliente.Surname == null || cliente.Address == null) { return(new Response { StatusCode = HttpStatusCode.Forbidden }); } else { return(clientesService.CreateCliente(cliente)); } }); Put("/{id}", args => { var cliente = this.Bind <Cliente>(); cliente.Id = args.id; if (cliente.Name == null || cliente.Surname == null || cliente.Address == null) { return(new Response { StatusCode = HttpStatusCode.Forbidden }); } else { Cliente edited = clientesService.EditCliente(cliente); if (edited == null) { return(new Response { StatusCode = HttpStatusCode.NotFound }); } else { return(edited); } } }); Delete("/{id}", args => { if (clientesService.DeleteCliente(args.id)) { return(204); } else { return(new Response { StatusCode = HttpStatusCode.NotFound }); } }); }