Exemple #1
0
        /// <summary>
        /// Método responsável por adicionar um telefone
        /// </summary>
        /// <param name="phoneDto"></param>
        public void PostPhone(PhoneDto phoneDto)
        {
            var phone = phoneDto.To<Phone>();

            _db.Phones.Add(phone);
            _db.SaveChanges();
        }
        /// <summary>
        /// Action responsavel por criar os dados do telefone do cliente.
        /// </summary>
        /// <param name="phone">Número do telefone</param>
        /// <returns></returns>
        public IHttpActionResult PostClient(PhoneDto phone)
        {
            if (!ModelState.IsValid)
                return BadRequest(ModelState);

            new PhoneBo().PostPhone(phone);

            return CreatedAtRoute("DefaultApi", new { id = phone.Id }, phone);
        }
        /// <summary>
        /// Action responsavel por atualizar os dados do telefone do cliente.
        /// </summary>
        /// <param name="id">Identificador do cliente</param>
        /// <param name="phone">Número do telefone</param>
        /// <returns></returns>
        public IHttpActionResult PutClient(long id, PhoneDto phone)
        {
            if (!ModelState.IsValid)
                return BadRequest(ModelState);

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

            new PhoneBo().PutPhone(id, phone);

            return StatusCode(HttpStatusCode.NoContent);
        }
        public void CreateNewPhone()
        {
            try
            {
                var dto = new PhoneDto
                {
                    ClientId = 2,
                    CodArea = 33,
                    Number = "3333-4444"
                };

                new PhoneBo().PostPhone(dto);

                Assert.IsTrue(true);
            }
            catch (Exception)
            {
                Assert.IsTrue(false);
            }
        }
Exemple #5
0
        /// <summary>
        /// Método responsável por atualizar um telefone
        /// </summary>
        /// <param name="id"></param>
        /// <param name="phoneDto"></param>
        public void PutPhone(long id, PhoneDto phoneDto)
        {
            if (id != phoneDto.Id)
                throw new Exception("Erro!");

            var phone = phoneDto.To<Phone>();

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

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

                throw;
            }
        }
        public void UpdatePhone()
        {
            try
            {
                var dto = new PhoneDto
                {
                    Id = 2,
                    ClientId = 3,
                    CodArea = 31,
                    Number = "1111-2222"
                };

                new PhoneBo().PutPhone(2,dto);

                Assert.IsTrue(true);
            }
            catch (Exception)
            {
                Assert.IsTrue(false);
            }
        }