Exemplo n.º 1
0
        public HttpResponseMessage ImportCategory()
        {
            ImportCategoryCollection categories;
            var path = HttpContext.Current.Request.PhysicalApplicationPath + "Import\\category.xml";

            var serializer = new XmlSerializer(typeof(ImportCategoryCollection));

            using (var reader = new StreamReader(path))
            {
                categories = (ImportCategoryCollection)serializer.Deserialize(reader);
            }

            var importList = categories.ImportCategory.ToList();

            if (importList.Count == 0)
            {
                return(ErrorResult());
            }

            var list = importList.Select(category => new Category
            {
                Id        = Guid.NewGuid(),
                Name      = category.Name,
                PublicKey = category.PublicKey
            }).ToList();

            _category.CreateItems(list);

            return(SuccessResult());
        }