Example #1
0
        public PromotionSnapshot(ProducerInterfaceCommon.ContextModels.Account author,
                                 Promotion promotion,
                                 producerinterface_Entities db,
                                 Context db2,
                                 string comment = null)
        {
            Author          = db2.Users.Find(author.Id);
            AuthorName      = Author.DisplayName;
            CreatedOn       = DateTime.Now;
            Promotion       = promotion;
            Name            = promotion.Name;
            SnapshotName    = "Изменена промоакция";
            SnapshotComment = comment;
            Annotation      = promotion.Annotation;
            Status          = promotion.GetStatus().DisplayName();
            Begin           = promotion.Begin;
            End             = promotion.End;
            File            = promotion.MediaFile;
            var ids      = promotion.PromotionToDrug.Select(x => x.DrugId).ToArray();
            var products = db.assortment.Where(x => ids.Contains(x.CatalogId)).Select(x => x.CatalogName).ToArray();

            ProductsJson = JsonConvert.SerializeObject(products);
            var regions = db.Regions((ulong)promotion.RegionMask).Select(x => x.Name).ToArray();

            RegionsJson = JsonConvert.SerializeObject(regions);
            ids         = promotion.PromotionsToSupplier.Select(x => x.SupplierId).ToArray();
            var suppliers = db.suppliernames.Where(x => ids.Contains(x.SupplierId)).Select(x => x.SupplierName).ToArray();

            SuppliersJson = JsonConvert.SerializeObject(suppliers);
        }
Example #2
0
        public void Load_regions()
        {
            var cntx    = new producerinterface_Entities();
            var regions = cntx.Regions();

            Assert.That(regions.Count, Is.GreaterThan(0));
            Assert.That(regions[0].Id, Is.GreaterThan(0));
        }
        public void Find(producerinterface_Entities db, Context db2, long producerId)
        {
            var promoList = db2.Promotions.Where(x => x.ProducerId == producerId).OrderByDescending(x => x.Begin)
                            .ThenByDescending(x => x.Id).ToList();
            var suppliers  = db.suppliernames.ToDictionary(x => x.SupplierId, x => x.SupplierName);
            var assortment = db.assortment.Where(x => x.ProducerId == producerId).ToDictionary(x => x.CatalogId, x => x.CatalogName);

            foreach (var item in promoList)
            {
                unchecked {
                    if (item.RegionMask == 0)
                    {
                        item.RegionMask = (long)ulong.MaxValue;
                    }
                }
                var supplierIds = item.PromotionsToSupplier.Select(x => x.SupplierId).ToList();
                var drugsIds    = item.PromotionToDrug.Select(x => x.DrugId).ToList();
                var status      = item.GetStatus();
                if (Status != null && Status != status)
                {
                    continue;
                }
                var itemUi = new PromotionUi()
                {
                    Id                = item.Id,
                    Name              = item.Name,
                    Annotation        = item.Annotation,
                    Begin             = item.Begin.ToString("dd.MM.yyyy"),
                    End               = item.End.ToString("dd.MM.yyyy"),
                    PromotionFileId   = item.MediaFile?.Id,
                    PromotionFileName = item.MediaFile?.ImageName,
                    AllSuppliers      = item.AllSuppliers,
                    ActualStatus      = status,
                    DrugList          = assortment.Where(x => drugsIds.Contains(x.Key)).Select(x => x.Value).ToList(),
                    RegionList        = db.Regions((ulong)item.RegionMask).Select(x => x.Name).ToList(),
                    SuppierRegions    = suppliers.Where(x => supplierIds.Contains(x.Key)).Select(x => x.Value).ToList(),
                    RowStyle          = item.RowStyle
                };
                Items.Add(itemUi);
            }
        }
Example #4
0
 // для UI
 public List <OptionElement> GetRegionList()
 {
     return(_cntx.Regions().ToOptions());
 }
Example #5
0
        public string GetRegionHeader(List <decimal> regionCodes)
        {
            var regions = _cntx.Regions().Where(x => regionCodes.Contains(x.Id)).Select(x => x.Name).OrderBy(x => x).ToList();

            return($"В отчет включены следующие регионы: {String.Join(", ", regions)}");
        }