public JsonResult SaveChild(CategoryUsableProductViewModel model)
        {
            Response response;

            try
            {
                using (var db = new KiaGalleryContext())
                {
                    var userId = GetAuthenticatedUserId();
                    if (model.id != null && model.id > 0)
                    {
                        var category = db.CategoryUsableProduct.Single(x => x.Id == model.id);
                        category.Title        = model.title;
                        category.Order        = model.order;
                        category.Active       = model.active;
                        category.ModifyUserId = userId;
                        category.ModifyDate   = DateTime.Now;
                        category.Ip           = Request.UserHostAddress;
                    }
                    else
                    {
                        var item = new CategoryUsableProduct()
                        {
                            Title        = model.title,
                            ParentId     = model.parentId,
                            Order        = model.order,
                            Active       = model.active,
                            CreateUserId = userId,
                            ModifyUserId = userId,
                            CreateDate   = DateTime.Now,
                            ModifyDate   = DateTime.Now,
                            Ip           = Request.UserHostAddress,
                        };
                        db.CategoryUsableProduct.Add(item);
                    }
                    db.SaveChanges();
                }

                response = new Response()
                {
                    status  = 200,
                    message = "محصول جدید ثبت شد",
                };
            }
            catch (Exception ex)
            {
                response = Core.GetExceptionResponse(ex);
            }
            return(Json(response, JsonRequestBehavior.AllowGet));
        }
        public JsonResult Search(CategoryUsableProductViewModel model)
        {
            Response response;

            try
            {
                using (var db = new KiaGalleryContext())
                {
                    List <CategoryUsableProductViewModel> list;
                    var query = db.CategoryUsableProduct.Where(x => x.ParentId == null).OrderBy(x => x.Order);
                    list = query.Select(item => new CategoryUsableProductViewModel()
                    {
                        id       = item.Id,
                        title    = item.Title,
                        parentId = item.ParentId,
                        order    = item.Order,
                        active   = item.Active,
                        children = item.ChildList.OrderByDescending(x => x.Order).Where(x => x.ParentId != null).Select(x => new SearchCategoryUsableProductSearchViewModel()
                        {
                            id         = x.Id,
                            order      = x.Order,
                            parentId   = x.ParentId,
                            childTitle = x.Title,
                        }).ToList(),
                    }).ToList();

                    response = new Response()
                    {
                        status = 200,
                        data   = new
                        {
                            list = list
                        },
                    };
                }
            }
            catch (Exception ex)
            {
                response = Core.GetExceptionResponse(ex);
            }
            return(Json(response, JsonRequestBehavior.AllowGet));
        }