Пример #1
0
 public static CategoryViewModel From(Category category)
 {
     CategoryViewModel viewModel = new CategoryViewModel();
     viewModel.Id = category.Id;
     viewModel.Name = category.Name;
     if (category.Parent != null)
         viewModel.ParentId = category.Parent.Id;
     viewModel.Description = category.Description;
     viewModel.Image = category.Image != null ? new Image(){Id = category.Image.Id} : null;
     viewModel.IsVisible = category.IsVisible;
     return viewModel;
 }
Пример #2
0
 public IncomeSearchCriteria WithCategory(Category category)
 {
     IncomeSearchCriteria another = this.Clone<IncomeSearchCriteria>();
     if (category != null)
     {
         another.CategoryId = category.Id;
     }
     else
     {
         another.CategoryId = null;
     }
     
     // need to reset page index
     another.PageIndex = 1;
     return another;
 }
Пример #3
0
        private void AddChildCategories(Category category, IList<SelectListItem> listItems, int level)
        {
            level++;
            foreach (Category subcategory in category.Subcategories)
            {
                string indent = "";
                for (int i = 0; i < level; i++)
                {
                    indent += "-";
                }
                listItems.Add(new SelectListItem() { Text = indent + subcategory.Name, Value = subcategory.Id.ToString() });
                AddChildCategories(subcategory, listItems, level);

            }
            level--;
        }
Пример #4
0
 public ActionResult Create(CategoryViewModel viewModel)
 {
     if (!ModelState.IsValid)
     {
         return View(viewModel);
     }
     Category category = new Category();
     if (viewModel.ParentId.HasValue)
     {
         Category parent = daoTemplate.FindByID<Category>(viewModel.ParentId);
         parent.AddSubCategory(category);
     }
     category.CopyFrom(viewModel);
     handleImage(category);
     daoTemplate.Save(category);
     return RedirectToAction("Index");
 }
Пример #5
0
        public void AddCategories()
        {
            Category c1 = new Category() { Name = "Компьютеры" };
            Category c12 = new Category() { Name = "Игровые приставки", Parent = c1};
            Category c13 = new Category() { Name = "Ноутбуки", Parent = c1 };
            Category c14 = new Category() { Name = "Принтеры и МФУ", Parent = c1 };
            c1.Subcategories.Add(c12);
            c1.Subcategories.Add(c13);
            //            c1.Subcategories.Add(c14);

            Category c2 = new Category() { Name = "Дом и дача" };
            Category c22 = new Category() { Name = "Автомобили, самокаты", Parent = c2 };
            Category c23 = new Category() { Name = "Детская обувь", Parent = c2 };
            Category c24 = new Category() { Name = "Одежда для малышей", Parent = c2 };
            //            c2.Subcategories.Add(c22);
            c2.Subcategories.Add(c23);
            //            c2.Subcategories.Add(c24);

            Category c3 = new Category() { Name = "Бытовая техника" };
            Category c32 = new Category() { Name = "Стиральные машины", Parent = c3 };
            Category c33 = new Category() { Name = "Электробритвы", Parent = c3 };
            Category c34 = new Category() { Name = "Холодильники", Parent = c3 };
            //            c3.Subcategories.Add(c32);
            //            c3.Subcategories.Add(c33);
            //            c3.Subcategories.Add(c34);

            IList<Category> categories = new List<Category>() { c1, c2, c3/*, c12, c13, c14, c22, c23, c24, c32, c33, c34 */};

            using(ISession session = GetConfiguration().BuildSessionFactory().OpenSession())
            {
                foreach (Category category in categories)
                {
                    session.Save(category);
                }
                session.Flush();
            }
        }
Пример #6
0
        public void ProdsWDate()
        {
            ISession session = GetConfiguration().BuildSessionFactory().OpenSession();

            Category category = new Category() {Id = 1};

            DetachedCriteria criteria = DetachedCriteria.For<Income>();
            criteria.CreateAlias("Product", "p");
            criteria.CreateAlias("p.Category", "c");
            criteria.SetProjection(
                Projections.ProjectionList()
                    .Add(Projections.GroupProperty("Product"))
                    .Add(Projections.GroupProperty("c.Name"))
                    .Add(Projections.Max("Date")));
            //criteria.Add(Restrictions.Eq("p.Category", category));
            criteria.AddOrder(NHibernate.Criterion.Order.Asc("c.Name"));
            var list = criteria.GetExecutableCriteria(session).List();
            foreach (var VARIABLE in list)
            {

            }
        }
Пример #7
0
        public virtual void CopyFrom(ProductViewModel viewModel)
        {
            Name = viewModel.Name;
            Price = viewModel.Price;
            Description = viewModel.Description;
            ShortDescription = viewModel.ShortDescription;
            Category = new Category() { Id = viewModel.CategoryId };
            Date = viewModel.Date;

            SKU = viewModel.SKU;
            Size = viewModel.Size;
            Color = viewModel.Color;
            Weight = viewModel.Weight;
            Country = viewModel.Country;
            IsVisible = viewModel.IsVisible;
            IsNew = viewModel.IsNew;
        }
Пример #8
0
 public virtual void AddSubCategory(Category category)
 {
     Subcategories.Add(category);
     category.Parent = this;
 }
Пример #9
0
 public virtual void MoveToNewParent(Category newParent)
 {
     if (Parent != null)
     {
         Parent.Subcategories.Remove(this);
     }
     Parent = newParent;
     if (newParent != null)
         newParent.Subcategories.Add(this);
 }
Пример #10
0
 internal IList<Product> FindByCategory(Category category)
 {
     return daoTemplate.FindAllByField<Product>("Category", category);
 }
Пример #11
0
        private void handleImage(Category category)
        {
            foreach (string inputTagName in Request.Files)
            {
                HttpPostedFileBase file = Request.Files[inputTagName];
                if (file.ContentLength > 0)
                {
                    Image image = new Image();
                    image.PathRootBased = "Category";
                    daoTemplate.Save(image);
                    string fileName = image.Small;
                    string filePath = Path.Combine(HttpContext.Server.MapPath("../Content/Uploads/"), fileName);
                    file.SaveAs(filePath);
                    ImageUtils.SaveImageToFile(ImageUtils.ResizeImageSquare(filePath), filePath);
                    category.Image = image;

                    daoTemplate.Save(image);
                }
                break;
            }
        }
Пример #12
0
        private static void listChildren(ref string html, Category category, Func<int, string> url, bool showAll)
        {
            var subs = showAll ? new List<Category>(category.Subcategories)
                : new List<Category>(category.Subcategories.Where(cat => cat.IsVisible));
            if (subs.Count > 0)
            {
                html += "<ul>";
            }
            else
                return;

            foreach (var subCategory in subs)
            {
                html += string.Format("<li><a href=\"{0}\">{1}</a>", url(subCategory.Id), subCategory.Name);

                listChildren(ref html, subCategory, url, showAll);
                html += "</li>";
            }

            html += "</ul>";
        }