예제 #1
0
        public IHttpActionResult PutCustomer(string id, CustomerViewModel customer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != customer.Id)
            {
                return(Content(HttpStatusCode.BadRequest, "Cliente no coinciden"));
            }

            var _customer = _customerService.GetCustomerById(id);

            if (_customer == null)
            {
                return(Content(HttpStatusCode.BadRequest, "Cliente no existe"));
            }
            else
            {
                _customerService.DetachCustomer(_customer);
                _customerService.EditCustomer(customer.ModelToEntity());
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #2
0
        public IHttpActionResult PostCustomer(CustomerViewModel customer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var _customer = _customerService.GetCustomerById(customer.Id);

            if (_customer == null)
            {
                _customerService.SaveCustomer(customer.ModelToEntity());
                return(Ok(customer));
            }
            else
            {
                return(Content(HttpStatusCode.BadRequest, "Cliente ya existe"));
            }
        }