Пример #1
0
        public IActionResult Put(string id, [FromBody] CustomerPostViewModel model)
        {
            logger.LogInformation("Updating Customer for id value: {0}", id);
            if (!ModelState.IsValid || String.IsNullOrEmpty(id) || model == null)
            {
                logger.LogInformation("Add Customer Request Returned Bad Request");
                return(BadRequest());
            }

            var customer = mapper.Map <Customer>(model);

            customer.Id = id;

            try
            {
                customerManager.Update(customer);
            }
            catch (ArgumentOutOfRangeException)
            {
                logger.LogError("Updated Customer value {0} is invalid");
                return(BadRequest());
            }
            logger.LogInformation("Updating Customer for id value: {0} complete", id);
            return(Accepted(id));
        }
Пример #2
0
        public IActionResult Post([FromBody] CustomerPostViewModel model)
        {
            logger.LogInformation("Add Customer Request");
            if (!ModelState.IsValid)
            {
                logger.LogInformation("Add Customer Request Returned Bad Request");
                return(BadRequest());
            }

            try
            {
                var customer = mapper.Map <Customer>(model);

                string newCustomerId = customerManager.Add(customer);
                logger.LogInformation("Add Customer Request Complete");
                return(CreatedAtRoute("GetCustomer", new { id = newCustomerId }, newCustomerId));
            }
            catch (Exception ex)
            {
                logger.LogError("Add Custtomer Unexpected Exception", ex);
                return(StatusCode(500));
            }
        }