示例#1
0
        internal Bidder ProcessDuplicates(IOrganizationService organizationService, EntityCollection ec_bidders)
        {
            List <Entity> list_Bidder  = ec_bidders.Entities.ToList();
            int           bidderNumber = 0;

            foreach (Entity e_bidder in list_Bidder)
            {
                var IsRecordInToBeDeactivated = bidder.TotalRecordsToBeDeactivated.Find(i => i.Id == e_bidder.Id);
                var IsRecordsInToBeActivated  = bidder.TotalRecordsToBeActivated.Find(i => i.Id == e_bidder.Id);
                if (IsRecordInToBeDeactivated == null && IsRecordsInToBeActivated == null)
                {
                    bidderNumber++;
                    List <Entity> duplicateRecords = GetDuplicateRecords(organizationService, list_Bidder, e_bidder);
                    log.Information("Bidder " + bidderNumber /*e_bidder.Attributes["sse_factorkey"]*/ + " : " + duplicateRecords.Count());
                    var oldestrecord = duplicateRecords.OrderBy(i => i.Attributes["createdon"]).FirstOrDefault();
                    duplicateRecords.Remove(oldestrecord);
                    bidder.TotalRecordsToBeActivated.Add(oldestrecord);
                    int activecount = oldestrecord != null ? 1 : 0;
                    BidderInformation bidderInformation = new BidderInformation()
                    {
                        ActiveBidderCount = activecount, ActiveBidder = oldestrecord, CurentBidder = e_bidder, ToBeDeactivated = duplicateRecords, TotalDuplicates = duplicateRecords.Count + activecount
                    };
                    bidder.bidderInformation.Add(bidderInformation);
                    bidder.TotalRecordsToBeDeactivated.AddRange(bidderInformation.ToBeDeactivated);

                    Deactivate(organizationService, bidder, bidderInformation, bidderInformation.ToBeDeactivated, bidderNumber);
                    log.Information("Bidder " + bidderNumber /*bidderInformation.CurentBidder.Attributes["sse_factorkey"]*/ + " Active  : " + bidderInformation.ActiveBidderCount);
                    log.Information("Bidder " + bidderNumber /*bidderInformation.CurentBidder.Attributes["sse_factorkey"]*/ + " Inactive : " + bidderInformation.DeactivatedBidderCount + "\n");
                }
            }
            var totalCount = bidder.bidderInformation.Sum(i => i.TotalDuplicates);

            log.Information("Total Count : " + totalCount);
            var totalActiveRecords  = bidder.bidderInformation.Sum(i => i.ActiveBidderCount);
            var totalInactiveRecord = bidder.bidderInformation.Sum(i => i.DeactivatedBidderCount);

            log.Information("Total Active Records : " + totalActiveRecords);
            log.Information("Total Inactive Record : " + totalInactiveRecord + "\n\n");
            if (totalCount != totalActiveRecords + totalInactiveRecord)
            {
                foreach (var item in bidder.FailedRecord)
                {
                    log.Information(item);
                }
            }
            return(bidder);
        }
示例#2
0
        private void Deactivate(IOrganizationService organizationService, Bidder bidder, BidderInformation bidderinfo, List <Entity> ToBeDeactivated, int bidderNumber)
        {
            foreach (var record in ToBeDeactivated)
            {
                try
                {
                    Entity entity = new Entity("sse_bidder");
                    entity.Id = record.Id;
                    entity.Attributes["statecode"] = new OptionSetValue(1);
                    organizationService.Update(entity);
                    log.Information("Deactivating Bidder : " + entity.Id);
                    bidderinfo.DeactivatedBidderCount++;
                    bidderinfo.Deactivated.Add(record);
                }
                catch (Exception ex)
                {
                    // For Record Level
                    bidderinfo.NoOfRecordsFailed++;
                    bidderinfo.FailedRecord.Add("For Bidder " + bidderNumber /*bidderinfo.CurentBidder.Attributes["sse_factorkey"]*/ + " Deactivating DuplicateBidder -: " + record.Id);

                    // Aggregate
                    bidder.NoOfRecordsFailed++;
                    bidder.FailedRecord.Add("For Bidder " + bidderNumber /*bidderinfo.CurentBidder.Attributes["sse_factorkey"]*/ + " Deactivating DuplicateBidder -: " + record.Id);
                }
            }
        }