public Account Update(Account account) { Repo.Update(account); Unit.SaveChanges(); return account; }
public IHttpActionResult Put(Account account) { if (!ModelState.IsValid) { return BadRequest(ModelState); } try { Logic.Update(account); } catch (DbUpdateConcurrencyException) { if (!AccountExists(account.Id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public void AccountRepository() { Mock<IWebsiteContext> context = new Mock<IWebsiteContext>(); Mock<IDbSetFactory> factory = new Mock<IDbSetFactory>(); Mock<DbSet<Account>> dbSet = new Mock<DbSet<Account>>(); factory.Setup(m => m.CreateDbSet<Account>()).Returns(dbSet.Object); AccountRepository repo = new AccountRepository(context.Object, factory.Object); var account = new Account { Id = "SDF", FullName = "Trevor Slawnyk", PreferredName = "Trevor", Zip = 68456, FacebookId = 4929447011515, Birthdate = new DateTime(1994, 6, 22), Weight = 250, Height = 73, Sex = false }; account.UserName = "******"; var sequence = new MockSequence(); dbSet.InSequence(sequence).Setup(e => e.Add(account)); dbSet.InSequence(sequence).Setup(e => e.Find(account.Id)); dbSet.InSequence(sequence).Setup(e => e.Find(account.Id)); dbSet.InSequence(sequence).Setup(e => e.Find(account.Id)); repo.Create(account); repo.Get(account.Id); repo.Update(account); repo.Delete(account.Id); }
public PersonalDashboardViewModel GenerateViewModel(Account a) { PersonalDashboardViewModel pdvm = new PersonalDashboardViewModel(); pdvm.Id = a.Id; pdvm.FullName = a.FullName; pdvm.PreferredName = a.PreferredName; pdvm.GoalCSV = GoalsCSV(a); string[] TwoDay = TwoDayActivityCSV(a); pdvm.TwoDayCSV = TwoDay[0]; pdvm.ReportCSV = ReportCSV(a); string[] pie = TotalActivityCSV(a); pdvm.TotalCSV = pie[0]; pdvm.BarchartInsight = TwoDay[1]; pdvm.Closest = GoalInsight(a); pdvm.LinechartInsight = ReportInsight(a); pdvm.PiechartInsight = pie[1]; pdvm.Prediction = MovingAverageDistance(a); pdvm.CanShare = a.Id == User.Identity.GetUserId(); return pdvm; }
public void AccountLogic() { Mock<IUnitOfWork> uow = new Mock<IUnitOfWork>(); Mock<IAccountRepository> repo = new Mock<IAccountRepository>(); Mock<ITeamRepository> teamRepo = new Mock<ITeamRepository>(); Mock<IAttainmentRepository> attainmentRepo = new Mock<IAttainmentRepository>(); Mock<IMembershipRepository> membershipRepo = new Mock<IMembershipRepository>(); AccountLogic logic = new AccountLogic(uow.Object, repo.Object, teamRepo.Object, attainmentRepo.Object, membershipRepo.Object); var account = new Account(); var sequence = new MockSequence(); repo.InSequence(sequence).Setup(r => r.Create(account)); repo.InSequence(sequence).Setup(r => r.Update(account)); repo.InSequence(sequence).Setup(r => r.Get(account.Id)); repo.InSequence(sequence).Setup(r => r.Delete(account.Id)); logic.Create(account); logic.Update(account); logic.Get(account.Id); logic.Delete(account.Id); }
public IHttpActionResult Post(Account account) { if (!ModelState.IsValid) { return BadRequest(ModelState); } Logic.Create(account); return Ok(account); }
public void Put(Account account) { accounts[account.Id] = account; }
private string GoalsCSV(Account a) { string goalCSV = "name,Remaining,Progress \r\n"; foreach (Goal g in a.Goals) { if (g.Status == GoalStatus.Current) { if (g.Target.Type == TargetType.Distance) { goalCSV += g.Description + "," + (g.Target.TargetNumber - g.Progress) + "," + g.Progress + "\r\n"; } if (g.Target.Type == TargetType.Duration) { goalCSV += g.Description + "," + (g.Target.TargetNumber - g.Progress) + "," + g.Progress + "\r\n"; } if (g.Target.Type == TargetType.Steps) { goalCSV += g.Description + "," + (g.Target.TargetNumber - g.Progress) + "," + g.Progress + "\r\n"; } } } return goalCSV; }
private List<BadgeDisplay> UnearnedBadges(Account account) { List<Badge> items = AttainmentLogic.UnearnedBadges(account.Id).ToList(); List<BadgeDisplay> UnearnedEarned = new List<BadgeDisplay>(); foreach (Badge b in items) { UnearnedEarned.Add(new BadgeDisplay(b.Title, "--/--/----")); } return UnearnedEarned; }
private List<BadgeDisplay> EarnedBadges(Account account) { List<Attainment> items = AttainmentLogic.GetByAccount(account.Id).ToList(); List<BadgeDisplay> earned = new List<BadgeDisplay>(); foreach (Attainment a in items) { earned.Add(new BadgeDisplay(BadgeLogic.Get(a.BadgeId).Title, a.DateEarned.ToShortDateString())); } return earned; }
private string[] TotalActivityCSV(Account a) { string[] text = new string[2]; string[] generated = GenerateDurationTotals(a.Activities.ToList()); text[0] = "Type,% of Total Activities \r\n" + generated[0]; text[1] = generated[1]; return text; }
private double MovingAverageDistance(Account a) { double TotalDistance = 0; foreach (Report r in a.Reports.OrderByDescending(e => e.Date).Take(5)) { TotalDistance += r.Distance; } return Math.Max(Math.Round((TotalDistance / 5), 2),5); }
private string ReportInsight(Account a) { double distance = 0; double duration = 0; foreach (Report r in a.Reports) { distance += r.Distance; duration += r.Duration; } if (distance + duration == 0) { return "You do not have any daily reports :("; } return "Your average all activity miles per hour is "+ Math.Round((distance/duration),2) + "mph"; }
private string ReportCSV(Account a) { string Csv = "Date,Distance,Duration\r\n"; DateTime last= new DateTime(); foreach (Report r in a.Reports.OrderBy(e=> e.Date)) { Csv += r.Date.ToShortDateString() + "," + r.Distance + "," + r.Duration + "\r\n"; last = r.Date; } return Csv; }
private string[] TwoDayActivityCSV(Account a) { DateTime TodayMidnight = DateTime.Today.ToUniversalTime(); DateTime TomorrowMidnight= DateTime.Today.AddDays(1).ToUniversalTime(); DateTime YesterdayMidnight = DateTime.Today.AddDays(-1).ToUniversalTime(); List<Activity> Today = ActivityLogic.GetByDate(a.Id,TodayMidnight,TomorrowMidnight); List<Activity> Yesterday = ActivityLogic.GetByDate(a.Id, YesterdayMidnight, TodayMidnight); int[] YesterdayTotals = GenerateStepTotals(Yesterday); int[] TodayTotals = GenerateStepTotals(Today); string[] data = new string[2]; data[0] = "Day,Walking,Jogging,Running,Biking \r\n"+ "Yesterday," + YesterdayTotals[0].ToString() + "," + YesterdayTotals[1].ToString() + "," + YesterdayTotals[2].ToString() + "," + YesterdayTotals[3].ToString() + "\r\n" + "Today," + TodayTotals[0].ToString() + "," + TodayTotals[1].ToString() + "," + TodayTotals[2].ToString() + "," + TodayTotals[3].ToString() + "\r\n"; data[1] = TwoDayInsights(TodayTotals, YesterdayTotals); return data; }
private Goal GoalInsight(Account a) { return a.Goals.Where(u => u.Status == GoalStatus.Current).OrderByDescending(g => (g.Progress / g.Target.TargetNumber)).FirstOrDefault(); }