예제 #1
0
        // POST api/ListItem/PostItem/
        public HttpResponseMessage PostItem(API_ListItem item)
        {
            if (ModelState.IsValid)
            {
                var createdItem = new Item();

                try
                {
                    using (_dataMethods = new DataMethods())
                    {
                        // Convert from the API to the Item
                        var listItem = converter.ConvertFromAPI_ListItem(item);

                        // Create the item
                        createdItem = _dataMethods.ListItem_Create(item.ListPublicKey,
                            listItem.Title,
                            listItem.Description,
                            listItem.Cost,
                            listItem.CostRangeStart,
                            listItem.CostRangeEnd,
                            listItem.Size,
                            listItem.Color,
                            listItem.Qty,
                            listItem.Ordinal,
                            listItem.ImageURL,
                            listItem.ItemURL);

                        // Next, create an ItemShare for the item for all the associated ListShares
                        foreach (var ls in _dataMethods.ListShare_GetAllByListPublicKey(item.ListPublicKey))
                        {
                            _dataMethods.ItemShare_Create(ls.ListShareID, item.ItemID);
                        }
                    }
                }
                catch (Exception)
                {

                    throw;
                }

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, item);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = createdItem.PublicKey }));
                return response;
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }