Пример #1
0
        public int CreateNode(ApiModels.Mushroom content)
        {
            var nodeExists = _mushroomsRoot.Children.FirstOrDefault(n => n.Name.Equals(content.Name, System.StringComparison.OrdinalIgnoreCase)) != null;

            IContent node;

            if (!nodeExists)
            {
                //new node
                node = Services.ContentService.CreateContentWithIdentity(content.Name, _mushroomsRoot.Id, Mushroom.ModelTypeAlias);

                node.SetValue("class", content.Class);
                node.SetValue("confusion", content.Confusion);
                node.SetValue("cookingInstructions", content.CookingInstructions);
                node.SetValue("cookingInterest", content.CookingInterest.ToString());
                node.SetValue("description", content.Description);
                node.SetValue("family", content.Family);
                node.SetValue("habitat", content.Habitat);
                node.SetValue("order", content.Order);
                node.SetValue("popularNames", content.PopularNames);
                node.SetValue("season", content.Season);
                node.SetValue("subclass", content.Subclass);
                node.SetValue("synonyms", content.Synonyms);

                Services.ContentService.Save(node);
                return(node.Id);
            }
            //else
            //{
            //    //node exists, we update info.
            //    node = Services.ContentService.GetById(existingNode.First().Id);
            //}

            return(default(int));
        }
Пример #2
0
        public HttpResponseMessage GetMushroom(int id)
        {
            var catalogue = Umbraco.TypedContentAtRoot().First(n => n.DocumentTypeAlias == Catalogue.ModelTypeAlias);
            var item      = catalogue.FirstChild <CoreModels.Mushroom>(n => n.Id == id);

            if (item == null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Item not found."));
            }

            ApiModels.Mushroom itemMapped = null;
            try
            {
                itemMapped = Mapper.Map <ApiModels.Mushroom>(item);
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Error mapping model"));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, itemMapped));
        }