public async Task <ActionResult> Index([Bind(Include = "UserName")] TwitterReportLikesByPeriod twitterReportLikesByPeriod)
        {
            if (await TweetsReportGenerator.UpdateReportAsync(twitterReportLikesByPeriod))
            {
                await repository.SaveReportAsync(twitterReportLikesByPeriod);
            }

            ModelState.Clear();
            return(View());
        }
        public async Task UpdateAsync_New_TwitterReportLikesPePeriod_With_Invalid_UserName()
        {
            //Arrange - create a report
            TwitterReportLikesByPeriod report = new TwitterReportLikesByPeriod();

            //Arrange - set incorrect name
            report.UserName = "******";

            //Act
            bool result = await TweetsReportGenerator.UpdateReportAsync(report);

            //Assert
            Assert.AreEqual(result, false);
        }
示例#3
0
        public async Task UpdateReportAsync(TwitterReportLikesByPeriod report)
        {
            if (report == null)
            {
                return;
            }
            TwitterReportLikesByPeriod dbEntry = context.ReportLikesByPeriod.Find(report.ID);

            if (dbEntry == null)
            {
                return;
            }
            IEnumerable <TwitterReportPartLikesByHour> oldCollection = dbEntry.reportParts;
            await TweetsReportGenerator.UpdateReportAsync(dbEntry);

            if (oldCollection != null)
            {
                context.ReportPartLikesByHour.RemoveRange(oldCollection);
            }
            context.ReportPartLikesByHour.AddRange(dbEntry.reportParts);
            //db.ReportLikesByPeriod.Add(twitterReportLikesByPeriod);
            await context.SaveChangesAsync();
        }