Exemplo n.º 1
0
        public static List <BProduct> GetProducts(TrucksReserveEntities dc, int?categoryId = null)
        {
            dc.ExcIfNull();

            List <BProduct> products  = new List <BProduct>();
            List <Product>  bProducts = new List <Product>();

            if (categoryId.HasValue == true)
            {
                bProducts = dc.Products.Where(p => p.Products_Categories.Count() > 0 &&
                                              p.Products_Categories.FirstOrDefault(c => c.CategoryID == categoryId.Value) != null).ToList();
            }
            else
            {
                bProducts = dc.Products.ToList();
            }

            if (bProducts.AreThereItems() == true)
            {
                products = bProducts.ConvertAll <BProduct>(new Converter <Product, BProduct>(BProduct.ElementConverter));

                if (categoryId.HasValue == false)
                {
                    products = products.OrderBy(p => p.FirstCategoryID).ToList();
                }
            }


            return(products);
        }
Exemplo n.º 2
0
        public static List <BCategory> GetCategoriesWithProducts(TrucksReserveEntities trModel, bool loadCategories, int?onlyForCategoryID = null)
        {
            trModel.ExcIfNull();

            List <BCategory> bCategories = new List <BCategory>();

            if (onlyForCategoryID.HasValue == true)
            {
                BCategory wantedCategory = null;
                if (loadCategories == true)
                {
                    bCategories    = GetCategories(trModel);
                    wantedCategory = bCategories.First(c => c.ID == onlyForCategoryID.Value);
                }
                else
                {
                    wantedCategory = GetCategory(trModel, onlyForCategoryID.Value);
                    bCategories.Add(wantedCategory);
                }

                wantedCategory.ExcIfNull();

                wantedCategory.LoadProducts(trModel);
                wantedCategory.LoadImages(trModel);
            }
            else
            {
                bCategories = GetCategories(trModel, true);
            }

            return(bCategories);
        }
Exemplo n.º 3
0
        internal static void GetTexts(TrucksReserveEntities trModel, ref List <BBaseText> texts, ref BText selectedText, int?selectedTextId)
        {
            trModel.ExcIfNull();

            texts        = new List <BBaseText>();
            selectedText = null;

            List <Text> bTexts = trModel.Texts.Where(t => t.Deleted == false).ToList();

            if (bTexts.AreThereItems() == true)
            {
                foreach (Text text in bTexts)
                {
                    if (selectedTextId.HasValue == true && text.ID == selectedTextId.Value)
                    {
                        selectedText = new BText(text);
                        texts.Add(selectedText);
                    }
                    else
                    {
                        texts.Add(new BBaseText(text));
                    }
                }
            }
        }
Exemplo n.º 4
0
        public static List <BFirm> GetFirms(TrucksReserveEntities dc, bool loadImages)
        {
            dc.ExcIfNull();

            List <BFirm> firms = new List <BFirm>();

            List <Firm> dbFirms = dc.Firms.ToList();

            if (dbFirms.AreThereItems() == true)
            {
                firms = dbFirms.ConvertAll <BFirm>(new Converter <Firm, BFirm>(BFirm.ElementConverter));

                if (loadImages == true)
                {
                    List <Gallery> dbFirmsImages = dc.Gallery.Where(g => g.Type == (int)ImageType.Firm).ToList();
                    if (dbFirmsImages.AreThereItems() == true)
                    {
                        List <Gallery> firmImages = new List <Gallery>();
                        foreach (BFirm firm in firms)
                        {
                            firmImages = dbFirmsImages.Where(i => i.TypeID.HasValue == true && i.TypeID == firm.ID).ToList();
                            if (firmImages.AreThereItems() == true)
                            {
                                firm.Images = firmImages.ConvertAll <BImage>(new Converter <Gallery, BImage>(BImage.ElementConverter));
                            }
                        }
                    }
                }
            }

            return(firms);
        }
Exemplo n.º 5
0
        internal void LoadProducts(TrucksReserveEntities dc)
        {
            dc.ExcIfNull();
            if (this.ID < 1)
            {
                BTools.NewBException("this.ID < 1");
            }

            Category category = dc.Categories.FirstOrDefault(c => c.ID == this.ID);

            category.ExcIfNull();

            this.LoadProducts(category);
        }
Exemplo n.º 6
0
        public static BCategory GetCategory(TrucksReserveEntities trModel, int id)
        {
            trModel.ExcIfNull();

            BCategory category = null;

            Category dbCategory = trModel.Categories.FirstOrDefault(c => c.ID == id);

            if (dbCategory != null)
            {
                category = new BCategory(dbCategory, false, false);
            }

            return(category);
        }
Exemplo n.º 7
0
        internal void LoadImages(TrucksReserveEntities dc)
        {
            dc.ExcIfNull();
            if (this.ID < 1)
            {
                BTools.NewBException("this.ID < 1");
            }

            this.Images = new List <BImage>();

            List <Gallery> images = dc.Gallery.Where(i => i.Type == (int)ImageType.Category && i.TypeID == this.ID).ToList();

            if (images.AreThereItems() == true)
            {
                this.Images = images.ConvertAll <BImage>(new Converter <Gallery, BImage>(BImage.ElementConverter));
                this.Images = this.Images.OrderByDescending(i => i.Main).ToList();
            }
        }
Exemplo n.º 8
0
        public static List <BCategory> GetCategories(TrucksReserveEntities trModel, bool loadProducts = false)
        {
            trModel.ExcIfNull();

            List <BCategory> bCategories = new List <BCategory>();

            List <Category> dbCategories = trModel.Categories.ToList();

            if (dbCategories.AreThereItems() == true)
            {
                foreach (Category cat in dbCategories)
                {
                    bCategories.Add(new BCategory(cat, false, loadProducts));
                }
            }

            return(bCategories);
        }
Exemplo n.º 9
0
        public static List <BImage> GetImages(TrucksReserveEntities trModel, ImageType type, int?typeID = null)
        {
            trModel.ExcIfNull();
            if (type == ImageType.Unknown)
            {
                BTools.NewBException(string.Format("Снимки тип '{0}' не се поддържат за зареждане от базата.", type));
            }

            List <Gallery> dbImages = trModel.Gallery.Where(i => i.Type == (int)type &&
                                                            (typeID.HasValue == false || (i.TypeID.HasValue == true && i.TypeID.Value == typeID.Value))).ToList();

            List <BImage> images = new List <BImage>();

            if (dbImages.AreThereItems() == true)
            {
                images = dbImages.ConvertAll <BImage>(new Converter <Gallery, BImage>(BImage.ElementConverter));
            }

            return(images);
        }
Exemplo n.º 10
0
        internal static List <BText> GetTextsForPage(TrucksReserveEntities trModel, LoadedPage page)
        {
            trModel.ExcIfNull();

            List <BText> texts = new List <BText>();

            switch (page)
            {
            case LoadedPage.Promotions:
                BText promText = GetText(trModel, TextType.Promotions, onlyWithFilledDescription: true, excIfNull: false);
                if (promText != null)
                {
                    texts.Add(promText);
                }
                break;

            default:
                BTools.NewBException(string.Format("За страница {0} не се поддържа вземането на текстове за показване.", page));
                break;
            }

            return(texts);
        }
Exemplo n.º 11
0
        internal static BText GetText(TrucksReserveEntities trModel, TextType type, bool onlyWithFilledDescription = false, bool excIfNull = true)
        {
            trModel.ExcIfNull();

            Text dbText = trModel.Texts.FirstOrDefault(t => t.Type == (int)type && t.Deleted == false &&
                                                       (onlyWithFilledDescription == false || string.IsNullOrEmpty(t.Description) == false));

            BText text = null;

            if (dbText == null)
            {
                if (excIfNull == true)
                {
                    dbText.ExcIfNull();
                }
            }
            else
            {
                text = new BText(dbText);
            }

            return(text);
        }
Exemplo n.º 12
0
        public BFirm(Firm firm, TrucksReserveEntities dbModel)
        {
            dbModel.ExcIfNull();

            SetProperties(firm, dbModel);
        }