Ejemplo n.º 1
0
        public void FailToCreateNewClientWithInvalidCpfTest()
        {
            try
            {
                var dto = new ClientDto
                {
                    MaritalStatusId      = 1,
                    StateId              = 1,
                    Cpf                  = "111.222.333-44",
                    Name                 = "José Teste Filho",
                    Email                = "*****@*****.**",
                    Street               = "Avenida Qualquer",
                    Neighborhood         = "Qualquer",
                    Number               = 200,
                    CEP                  = "4058500",
                    Complement           = "",
                    ReferenceInformation = ""
                };

                new ClientsBo().PostClient(dto);

                Assert.IsTrue(false);
            }
            catch (Exception)
            {
                Assert.IsTrue(true);
            }
        }
Ejemplo n.º 2
0
        public void CreateNewClientWithValideCpfTest()
        {
            try
            {
                var dto = new ClientDto
                {
                    MaritalStatusId      = 2,
                    StateId              = 2,
                    Cpf                  = "508.803.883-66",
                    Name                 = "José Teste Filho",
                    Email                = "*****@*****.**",
                    Street               = "Avenida Qualquer",
                    Neighborhood         = "Qualquer",
                    Number               = 200,
                    CEP                  = "4058500",
                    Complement           = "casa",
                    ReferenceInformation = "Proximo a escola estadual"
                };

                new ClientsBo().PostClient(dto);

                Assert.IsTrue(true);
            }
            catch (Exception)
            {
                Assert.IsTrue(false);
            }
        }
Ejemplo n.º 3
0
        public IHttpActionResult PostClient(ClientDto client)
        {
            if (!ModelState.IsValid)
                return BadRequest(ModelState);

            new ClientsBo().PostClient(client);

            return CreatedAtRoute("DefaultApi", new { id = client.Id }, client);
        }
Ejemplo n.º 4
0
        public IHttpActionResult PutClient(long id, ClientDto client)
        {
            if (!ModelState.IsValid)
                return BadRequest(ModelState);

            if (id != client.Id)
                return BadRequest();

            new ClientsBo().PutClient(id, client);

            return StatusCode(HttpStatusCode.NoContent);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Método responsável por atualizadar dados do cliente
        /// </summary>
        /// <param name="clientDto"></param>
        public void PostClient(ClientDto clientDto)
        {
            if (!Cpf.Validade(clientDto.Cpf))
                throw new Exception("Erro! CPF inválido.");

            var client = clientDto.To<Client>();

            _db.Clients.Add(client);
            _db.SaveChanges();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Método responsável por atualizar os dados do cliente
        /// </summary>
        /// <param name="id"></param>
        /// <param name="clientDto"></param>
        public void PutClient(long id, ClientDto clientDto)
        {
            if (id != clientDto.Id)
                throw new Exception("Erro!");

            if (!Cpf.Validade(clientDto.Cpf))
                throw new Exception("Erro! CPF inválido.");

            var client = clientDto.To<Client>();

            _db.Entry(client).State = EntityState.Modified;

            try
            {
                _db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ClientExists(id))
                    throw new Exception("Cliente não encontrado!");

                throw;
            }
        }