Beispiel #1
0
        //שליפת מודעות לפי קטגוריה ועיר
        public static List <AdvertisementsDTO> GetAdvertismentByCategoryAndCity(string city, string category)
        {
            List <AdvertisementsDTO> l1 = AdvertismentsBLL.GetAdvertismentByCategory(category);
            List <BillboardDTO>      l2 = BillboardBLL.GetBillBoardByCity(city);
            List <AdvertisementsDTO> l3 = new List <AdvertisementsDTO>();

            foreach (var item in db.PanelAds)
            {
                var add = l1.FirstOrDefault(x => x.AdId == item.AdId);
                if (add != null)
                {
                    var bill = l2.FirstOrDefault(x => x.BoardId == item.BoardId);
                    if (bill != null)
                    {
                        if (item.PanelDate < DateTime.Today)
                        {
                            var ll = l3.FirstOrDefault(x => x.AdId == add.AdId);
                            if (ll == null)
                            {
                                l3.Add(add);
                            }
                        }
                    }
                }
            }
            return(l3);
        }
Beispiel #2
0
        //שליפת  לוחות לפי כתובת ותאריך
        public static List <PanelDTO> GetPanelAdByAddressAndDate(string street, string city, System.DateTime date)
        {
            var newpanel = new List <PanelDTO>();

            string[]            streetArr     = street.Split(',');
            List <BillboardDTO> billboardlist = BillboardBLL.GetBillBoardByCityAndArrStreet(city, streetArr);
            List <PanelDTO>     panellist     = PanelDTO.ListToDTO(db.PanelAds.Where(x => x.PanelDate == date).ToList());

            if (panellist.Count == 0 || billboardlist.Count == 0)
            {
                return(null);
            }
            foreach (var item in billboardlist)
            {
                foreach (var item2 in panellist)
                {
                    if (item.BoardId == item2.BoardId)
                    {
                        newpanel.Add(item2);
                    }
                }
            }
            if (newpanel.Count == 0)
            {
                return(null);
            }
            var orderedList = newpanel.OrderBy(x => x.PanelLineStart).ThenBy(x => x.PanelColumnStart).ToList();
            var emptyAdsList = new List <PanelDTO>();
            int row = 0, col = 0;

            for (int i = 0; i < 8; i++)
            {
                bool rowIsFull = false;
                int  columns   = 0;
                var  thisRow   = orderedList.Where(a => a.PanelLineStart == i ||
                                                   (a.PanelLineStart <= i && a.PanelLineEnd >= i))
                                 .OrderBy(x => x.PanelColumnStart).ThenBy(x => x.PanelLineStart).ToList();
                if (thisRow.Count == 0)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        emptyAdsList.Add(new PanelDTO()
                        {
                            AdId             = -1,
                            BoardId          = orderedList.FirstOrDefault().BoardId,
                            PanelLineStart   = i,
                            PanelLineEnd     = i,
                            PanelColumnStart = j,
                            PanelColumnEnd   = j
                        });
                    }
                    continue;
                }
                // check if need to add empty ads in the beginning of the row
                var firstColumn = thisRow.Min(a => a.PanelColumnStart);
                for (int j = 0; j < firstColumn; j++)
                {
                    emptyAdsList.Add(new PanelDTO()
                    {
                        AdId             = -1,
                        BoardId          = orderedList.FirstOrDefault().BoardId,
                        PanelLineStart   = i,
                        PanelLineEnd     = i,
                        PanelColumnStart = j,
                        PanelColumnEnd   = j
                    });
                }

                //check if need to add empty ads in the middle of the row
                for (int j = 0; j < thisRow.Count; j++)
                {
                    columns = thisRow[j].PanelColumnEnd;
                    if (j < thisRow.Count - 1)
                    {
                        int nextColumnStart = thisRow[j + 1].PanelColumnStart;
                        if (columns + 1 < nextColumnStart)
                        {
                            for (int k = columns + 1; k < nextColumnStart; k++)
                            {
                                emptyAdsList.Add(new PanelDTO()
                                {
                                    AdId             = -1,
                                    BoardId          = orderedList.FirstOrDefault().BoardId,
                                    PanelLineStart   = i,
                                    PanelLineEnd     = i,
                                    PanelColumnStart = k,
                                    PanelColumnEnd   = k
                                });
                            }
                        }
                    }
                    if (columns == 3)
                    {
                        rowIsFull = true;
                        break;
                    }
                }

                //check if need to add empty ads in the end of the row
                if (!rowIsFull)
                {
                    for (int k = columns + 1; k < 4; k++)
                    {
                        emptyAdsList.Add(new PanelDTO()
                        {
                            AdId             = -1,
                            BoardId          = orderedList.FirstOrDefault().BoardId,
                            PanelLineStart   = i,
                            PanelLineEnd     = i,
                            PanelColumnStart = k,
                            PanelColumnEnd   = k
                        });
                    }
                }
            }
            orderedList.AddRange(emptyAdsList);
            return(orderedList.OrderBy(x => x.PanelLineStart).ThenBy(x => x.PanelColumnStart).ToList());
        }