Exemplo n.º 1
0
        public IHttpActionResult PostCustomerDetails(Customers customer)
        {
            string CampoInconsistente      = null;
            string DescricaoInconsistencia = null;

            if (!ModelState.IsValid && !_repository.ValidateCustomer(customer, out CampoInconsistente, out DescricaoInconsistencia))
            {
                ModelState.AddModelError(CampoInconsistente,
                                         DescricaoInconsistencia);

                return(BadRequest(ModelState));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (customer.Birthday != null)
                    {
                        customer.Age = CalculateAGe.CalculateAge(customer.Birthday);
                    }

                    _repository.InsertCustomer(customer);
                }
                catch (Exception)
                {
                    throw;
                }
            }

            return(Ok(customer));
        }
Exemplo n.º 2
0
        public IHttpActionResult PutCustomerDetails(Customers customer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                customer.Age = CalculateAGe.CalculateAge(customer.Birthday);
                _repository.UpdateCustomer(customer);
            }
            catch (Exception)
            {
                throw;
            }

            return(Ok(customer));
        }