Esempio n. 1
0
        public IHttpActionResult Post(CreateProductCommand cmd)
        {
            if (string.IsNullOrWhiteSpace(cmd.Name))
            {
                var response = new HttpResponseMessage(HttpStatusCode.Forbidden)
                {
                    Content = new StringContent("code must be supplied in the body"),
                    ReasonPhrase = "Missing product code"
                };
                throw new HttpResponseException(response);
            }

            try
            {
                var command = new CreateProduct(Guid.NewGuid(), cmd.Name, cmd.Description, cmd.Price);
                handler.Handle(command);

                var link = new Uri(string.Format("http://localhost:8181/api/products/{0}", command.Id));
                return Created<CreateProduct>(link, command);
            }
            catch (AggregateNotFoundException)
            {
                return NotFound();
            }
            catch (AggregateDeletedException)
            {
                return Conflict();
            }
        }
        public void Handle(CreateProduct message)
        {
            // Validation
            ProductDto existingProduct = null;

            // Process
            var series = new Products.Domain.Product(message.Id, message.Name, message.Description, message.Price);
            repository.Save(series);
        }