예제 #1
0
        public void Update(CategoryJson categoryJson)
        {
            var categoryToUpdate = db.Categories.Where(c => c.Id == categoryJson.id).SingleOrDefault();

            AssignValue(categoryJson, categoryToUpdate);
            db.SaveChanges();
        }
예제 #2
0
        public HttpResponseMessage Update(CategoryJson categoryJson)
        {
            if (categoryJson.Id == null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Parameter 'Id' cannot be null"));
            }

            Category category = Repository.CategoryRepository.FindById(categoryJson.Id.Value);

            if (category == null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound,
                                                   "Category with id '" + category.Id.Value + "' not found!"));
            }

            category.Name = categoryJson.Name;
            if (!string.IsNullOrEmpty(categoryJson.ImageData))
            {
                byte[] imageData = Convert.FromBase64String(categoryJson.ImageData);
                string subPath   = "photos/category/" + categoryJson.Id + "." + categoryJson.ImageType;
                string imagePath = HttpContext.Current.Server.MapPath("~/" + subPath);
                File.WriteAllBytes(imagePath, imageData);
                category.ImageUrlRelative = subPath;
            }
            category = Repository.CategoryRepository.Update(category);
            return(Request.CreateResponse(HttpStatusCode.OK, category));
        }
예제 #3
0
        public void Post(CategoryJson categoryJson)
        {
            Repository <Category> categoryRepository = new Repository <Category>(db);
            var category = convertor.CategoryJsonToCategory(categoryJson);

            categoryRepository.Insert(category);
            db.SaveChanges();
        }
예제 #4
0
        private CategoryJson toCategoryJson()
        {
            CategoryJson categoryJson = new CategoryJson();

            categoryJson.Id     = this.Id.ToString();
            categoryJson.Text   = this.Name;
            categoryJson.Childs = arrayToCategoryJson(this.subCategories);
            return(categoryJson);
        }
예제 #5
0
 public Category CategoryJsonToCategory(CategoryJson categoryJson)
 {
     return(new Category()
     {
         Id = categoryJson.id,
         Name = categoryJson.name,
         ParentCategoryId = categoryJson.parentCategoryId
     });
 }
예제 #6
0
        public CategoryJson ConvertASingleCategoryToASingleCategoryJson(Category category)
        {
            var categoryJson = new CategoryJson()
            {
                id            = category.Id,
                name          = category.Name,
                subCategories = new List <Category>()
            };

            return(categoryJson);
        }
예제 #7
0
        public JsonResult GetSubCategories(CategoryJson categoryJson)
        {
            var model = EconomyBusiness.GetSubCategoriesByCategory(categoryJson.CategoryId).ToList();

            var list = JsonConvert.SerializeObject(model, Formatting.Indented, new JsonSerializerSettings()
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            });


            return(Json(list, JsonRequestBehavior.DenyGet));
        }
예제 #8
0
        public HttpResponseMessage Create(CategoryJson categoryJson)
        {
            var category = new Category
            {
                Name = categoryJson.Name
            };

            category = Repository.CategoryRepository.Add(category);

            byte[] imageData = Convert.FromBase64String(categoryJson.ImageData);
            string subPath   = "photos/category/" + category.Id + "." + categoryJson.ImageType;
            string imagePath = HttpContext.Current.Server.MapPath("~/" + subPath);

            File.WriteAllBytes(imagePath, imageData);
            category.ImageUrlRelative = subPath;
            category = Repository.CategoryRepository.Update(category);
            return(Request.CreateResponse(HttpStatusCode.OK, category));
        }
예제 #9
0
        public List <CategoryJson> ConvertCategoryToCategoryJson(List <Category> categories)
        {
            var categoryJsonList = new List <CategoryJson>();

            foreach (var cat in categories)
            {
                var categoryJson = new CategoryJson()
                {
                    id            = cat.Id,
                    name          = cat.Name,
                    subCategories = GetSubCategories(cat)
                };
                categoryJsonList.Add(categoryJson);
            }


            return(categoryJsonList);
        }
예제 #10
0
        /// <summary>
        /// Recursive method to set category ordering
        /// </summary>
        /// <param name="json"></param>
        public async Task SetCategoryOrdering(int parent, CategoryJson[] json)
        {
            int sortOrder = 0;
            foreach (var item in json)
            {
                var category = await _categoryService.FindAsync(item.id);
                category.Parent = parent;
                category.Ordering = sortOrder;
                category.ObjectState = Repository.Pattern.Infrastructure.ObjectState.Modified;

                _categoryService.Update(category);

                sortOrder++;

                if (item.children != null)
                {
                    await SetCategoryOrdering(item.id, item.children);
                }
            }
        }
예제 #11
0
 private void AssignValue(CategoryJson categoryJson, Category categoryToUpdate)
 {
     categoryToUpdate.Name             = categoryJson.name;
     categoryToUpdate.ParentCategoryId = categoryJson.parentCategoryId;
 }
예제 #12
0
 // PUT: api/Category/5
 public void Put(CategoryJson categoryJson)
 {
     categoryLogic.Update(categoryJson);
 }
예제 #13
0
 // POST: api/Category
 public void Post(CategoryJson categoryJson)
 {
     categoryLogic.Post(categoryJson);
 }