示例#1
0
        public void RegisterVoteForBill(bool vote, int billId, ConstituencyDataModel constituency)
        {
            decimal verticalAvarage   = 50;
            decimal horizontalAvarage = 50;
            var     bill = _db.Single <BillDataModel>(b => b.Id == billId);
            var     allStanceRecordsForBill = _db.All <BillStanceDateModel>().Where(s => s.BillId == billId);

            if (allStanceRecordsForBill.Any())
            {
                verticalAvarage   = allStanceRecordsForBill.Sum(s => s.VerticalValue) / allStanceRecordsForBill.Count();
                horizontalAvarage = allStanceRecordsForBill.Sum(s => s.HorizontalValue) / allStanceRecordsForBill.Count();
            }

            var newVote = new VoteDateModel()
            {
                BillDataModelId         = bill.Id,
                House                   = bill.House,
                Stage                   = bill.Stage,
                Vote                    = vote,
                ConstituencyDataModelId = constituency.Id,
                VerticalValue           = verticalAvarage,
                HorizontalValue         = horizontalAvarage
            };

            _db.Add <VoteDateModel>(newVote);
            _db.CommitChanges();
        }
示例#2
0
        public void UpdateBillData(HttpContext context)
        {
            _context = context;
            PopulateConstituencies();
            PopulateMPs();

            var newBillList = _rssClient.GetBills("http://services.parliament.uk/bills/AllBills.rss");

            foreach (var newBillData in newBillList)
            {
                var bill = _db.Single <BillDataModel>(b => b.Url == newBillData.Url);
                if (bill != null)
                {
                    if (bill.UpdatedDate < newBillData.UpdatedDate)
                    {
                        bill.UpdatedDate = newBillData.UpdatedDate;
                        bill.BillType    = newBillData.BillType;
                        bill.Description = newBillData.Description;
                        bill.House       = newBillData.House;
                        bill.Stage       = newBillData.Stage;
                        bill.Title       = newBillData.Title;
                        bill.IsUpdated   = true;
                    }
                    _db.Update <BillDataModel>(bill);
                    _db.CommitChanges();
                }
                else
                {
                    newBillData.IsNew = true;
                    _db.Add <BillDataModel>(newBillData);
                    _db.CommitChanges();
                    bill = _db.Single <BillDataModel>(b => b.Url == newBillData.Url);
                }

                var parliamentaryDebates = PopulateParliamentaryDebatesForBill(bill.Id);
                if (parliamentaryDebates.Count > 0)
                {
                    var debates = new List <DebateDataModel>();
                    foreach (var debateResult in parliamentaryDebates)
                    {
                        if (debateResult.speaker != null)
                        {
                            var mpId       = Convert.ToInt32(debateResult.speaker.person_id);
                            var speakingMP = _db.Single <MPDataModel>(m => m.TWFYPersonId == mpId);
                            debates.Add(new DebateDataModel
                            {
                                Body    = debateResult.body,
                                Date    = DateTime.Parse(debateResult.hdate),
                                Speaker = speakingMP,
                                BillId  = bill.Id
                            });
                        }
                    }
                    _db.Add <DebateDataModel>(debates);
                }
            }
            var voteDataProvider = new VoteData(_db);

            voteDataProvider.PopulateVoteData();
        }
示例#3
0
        public void PopulateVoteData()
        {
            string remoteUri = "http://www.publicwhip.org.uk/data/";
            string fileName = "votematrix-2010.dat", myStringWebResource = null;
            Stream file;

            using (WebClient myWebClient = new WebClient())
            {
                myStringWebResource = remoteUri + fileName;
                file = myWebClient.OpenRead(myStringWebResource);
            }


            using (StreamReader sr = new StreamReader(file))
            {
                int      columncount = 0;
                string   headerRow   = sr.ReadLine();
                string[] headers     = headerRow.Split('\t');
                headers = RemoveUnusedHeaderInfo(headers);
                while (sr.Peek() != -1)
                {
                    columncount = 0;
                    string voteData = sr.ReadLine();

                    string[] cells = voteData.Split('\t');
                    if (cells.Count() > 1)
                    {
                        var bill = FindBill(cells[3]);
                        if (bill != null)
                        {
                            var voteDate = cells[1];
                            cells = cells.RemoveAt(0);
                            cells = cells.RemoveAt(0);
                            cells = cells.RemoveAt(0);
                            cells = cells.RemoveAt(0);


                            foreach (var cell in cells)
                            {
                                if (!string.IsNullOrWhiteSpace(cell))
                                {
                                    var mpVote = new MpVoteRecord()
                                    {
                                        Date = DateTime.Parse(voteDate),
                                        Mp   = GetMp(headers[columncount]),
                                        Bill = bill,
                                        Vote = GetVoteType(cell.Trim())
                                    };
                                    columncount++;
                                    _db.Add <MpVoteRecord>(mpVote);
                                    _db.CommitChanges();
                                }
                            }
                        }
                    }
                }
            }
        }
示例#4
0
 public void PostMessage(MessageViewModel message, User sender, Dialog dialog)
 {
     messageRepository.Add(new Message
     {
         Date       = DateTime.Parse(message.PostDate),
         IsReaction = message.IsReaction,
         IsRead     = false,
         Sender     = sender,
         Dialog     = dialog,
         Text       = message.Text
     });
 }
示例#5
0
        public DialogViewModel GetDialog(string firstUserId, string secondUserId)
        {
            var dialog = GetDomainDialog(firstUserId, secondUserId);

            if (dialog == null)
            {
                dialog = CreateDomainDialog(firstUserId, secondUserId);
                dialogRepository.Add(dialog);
                return(GetDialogViewModel(secondUserId, dialog));
            }

            return(GetDialogViewModel(secondUserId, dialog));
        }
示例#6
0
        public void SaveResults(User currentUser, TestResult model)
        {
            var session = new TestSession
            {
                IsValid    = model.ResultEmotion == model.SelectedEmotion,
                ResultType = EmotionUtil.GetEmotionType(model.ResultEmotion),
                Type       = EmotionUtil.GetEmotionType(model.SelectedEmotion),
                StartDate  = DateTime.Now,
                User       = currentUser,
                TestLogs   = new List <TestLog>(),
                Source     = model.Source
            };

            testRepository.Add(session);
        }
示例#7
0
        public void AddPeoplesComment(string userId, string newComment, string billId)
        {
            var realBillId = Convert.ToInt32(billId);
            var user       = _db.Single <ApplicationUser>(u => u.Id == userId);
            var bill       = _db.Single <BillDataModel>(billDataModel => billDataModel.Id == realBillId);

            var billCommentDataModel = new PeoplesDebatPostDataModel()
            {
                Date            = DateTime.Now,
                Author          = user,
                BillDataModelId = bill.Id,
                Text            = newComment
            };

            _db.Add <PeoplesDebatPostDataModel>(billCommentDataModel);
            _db.CommitChanges();
        }
示例#8
0
        public void RegisterStanceVoteForBill(int billId, decimal vertical, decimal horizontal, string userId)
        {
            var bill = _db.Single <BillDataModel>(b => b.Id == billId);

            var voteStance = new BillStanceDateModel()
            {
                BillId          = bill.Id,
                VerticalValue   = vertical,
                HorizontalValue = horizontal,
                UserId          = userId
            };

            bill.VerticalValue   = vertical;
            bill.HorizontalValue = horizontal;
            _db.Update <BillDataModel>(bill);
            _db.Add <BillStanceDateModel>(voteStance);
            _db.CommitChanges();
        }
示例#9
0
        public static void UpdatePublishedDetails(FbProfileType profileType, string fbUserId, string message, string profileId, long userId, string imagePath, MediaType mediaType, string profileName, IDatabaseRepository dbr)
        {
            var scheduledMessage = new ScheduledMessage
            {
                createTime  = DateTime.UtcNow,
                picUrl      = "https://graph.facebook.com/" + fbUserId + "/picture?type=small",
                profileId   = profileId,
                profileType = profileType == Domain.Socioboard.Enum.FbProfileType.FacebookProfile
                    ? Domain.Socioboard.Enum.SocialProfileType.Facebook
                    : Domain.Socioboard.Enum.SocialProfileType.FacebookFanPage,
                scheduleTime      = DateTime.UtcNow,
                shareMessage      = message,
                userId            = userId,
                status            = Domain.Socioboard.Enum.ScheduleStatus.Compleated,
                url               = imagePath,
                mediaType         = mediaType,
                socialprofileName = profileName
            };


            dbr.Add(scheduledMessage);
        }
示例#10
0
        public void SaveResults(User currentUser, TrainingSetupModel model)
        {
            var session = new TrainingSession
            {
                StartDate    = model.StartDate,
                User         = currentUser,
                TrainingLogs = new List <TrainingLog>(),
                Status       = TrainingSessionStatus.InProgress,
                EmotionType  = EmotionUtil.GetEmotionType(model.SelectedEmotion)
            };
            var sources = model.Sources.Select(x => new TrainingSource
            {
                SourceUrl       = x,
                TrainingSession = session
            });

            session.TrainingSources = sources.ToList();
            trainingRepository.Add(session);


            // HERE WE SHOULD START LOGGING PROCESS
            hostedService.StartAsync(new CancellationToken(false));
        }
示例#11
0
 public long AddProduct(Product product)
 {
     return(_productRepository.Add(product));
 }
示例#12
0
 public Customer AddCustomer(Customer customer)
 {
     customer.CustomerId = _customerRepository.Add(customer);
     return(customer);
 }
 public long AddOrder(Order order)
 {
     return(_orderRepository.Add(order));
 }