public void AddorUpdateReward(List <ChildReward> rewards) { using (var db = new ModelKids()) { foreach (var m in rewards) { var r = db.ChildReward.Where(a => a.GoalId == m.GoalId && a.ChildId == m.ChildId).Include(i => i.Goal).FirstOrDefault(); if (r != null) { r.PointsAllocated = m.PointsAllocated; r.RewardRequested = m.RewardRequested; r.RewardReceived = m.RewardReceived; r.RewardComplete = m.RewardComplete; r.RewardReceivedDate = m.RewardReceivedDate; db.SaveChanges(); // AddorUpdateRewardAwarded(r); } else // if no existing record on rewards { if (m.PointsAllocated > 0) // if points allocated create entry. { db.ChildReward.Add(m); db.SaveChanges(); //AddorUpdateRewardAwarded(m); } } } } AddorUpdateRewardAwarded(rewards); return; }
public void UpdateContributorImage(int id, string imageuri) { using (var db = new ModelKids()) { var val = db.Contributor.Where(a => a.ContributorId == id).First(); val.ContributorImage = imageuri; db.SaveChanges(); } }
public void UpdateChildImage(int id, string imageuri) { using (var db = new ModelKids()) { var val = db.Children.Where(a => a.ChildId == id).First(); val.UserImage = imageuri; db.SaveChanges(); } }
public Goal AddGoal(Goal goal) { using (var db = new ModelKids()) { db.Goals.Add(goal); db.SaveChanges(); //var newid = goal.BehaviourId; } return(goal); }
public Child UpdateChild(Child child) { using (var db = new ModelKids()) { var val = db.Children.Where(a => a.ChildId == child.ChildId).First(); val.BankedPoints = child.BankedPoints; db.SaveChanges(); } return(child); }
public Points2 AddPoint2(Points2 point) { using (var db = new ModelKids()) { db.Points2.Add(point); db.SaveChanges(); var newid = point.Point2Id; } return(point); }
public RewardAwarded AddRewardAwarded(RewardAwarded rewardawarded) { using (var db = new ModelKids()) { db.RewardAwarded.Add(rewardawarded); db.SaveChanges(); //var newid = goal.BehaviourId; } return(rewardawarded); }
public Behaviour AddBehaviour(Behaviour behaviour) { using (var db = new ModelKids()) { db.Behaviour.Add(behaviour); db.SaveChanges(); var newid = behaviour.BehaviourId; } return(behaviour); }
public Child DeleteChild(Child child) { using (var db = new ModelKids()) { db.Children.Attach(child); db.Children.Remove(child); db.SaveChanges(); } return(child); }
public Contributor AddContributor(Contributor contributor) { using (var db = new ModelKids()) { contributor.ContributorAuthCode = CreateUserAuthCode(); db.Contributor.Add(contributor); db.SaveChanges(); var newid = contributor.ContributorId; } return(contributor); }
public Contributor DeleteContributor(Contributor contributor) { using (var db = new ModelKids()) { db.Contributor.Attach(contributor); db.Contributor.Remove(contributor); db.SaveChanges(); } return(contributor); }
public Goal DeleteGoal(Goal goal) { using (var db = new ModelKids()) { db.Goals.Attach(goal); db.Goals.Remove(goal); db.SaveChanges(); } return(goal); }
public Behaviour DeleteBehaviour(Behaviour behaviour) { using (var db = new ModelKids()) { db.Behaviour.Attach(behaviour); db.Behaviour.Remove(behaviour); db.SaveChanges(); } return(behaviour); }
public void DeletePointReview(int id) { using (var db = new ModelKids()) { var point = db.PointAllocation.Where(a => a.PointId == id).First(); db.PointAllocation.Attach(point); db.PointAllocation.Remove(point); db.SaveChanges(); } return; }
public Child EditChild(Child child) { using (var db = new ModelKids()) { //var val = db.Children.Where(a => a.ChildId == child.ChildId).First(); //val.BankedPoints = child.BankedPoints; // db.Children.Attach(child); db.Children.AddOrUpdate(child); db.SaveChanges(); } return(child); }
public Child AddChild(Child child) { using (var db = new ModelKids()) { child.CanBank = true; child.UserAuthCode = CreateUserAuthCode(); db.Children.Add(child); db.SaveChanges(); var newid = child.ChildId; } return(child); }
public void ApprovePointForId(int pointId) { using (var db = new ModelKids()) { var point = db.PointAllocation.Where(a => a.PointId == pointId).First(); if (point != null) { point.Approved = true; db.SaveChanges(); } } return; }
//Bank Points public void UpdatePointsToSavedStatusForId(Child child) { using (var db = new ModelKids()) { var allPoints = db.PointAllocation.Where(a => a.ChildId == child.ChildId && a.Saved != true && a.Approved == true); // tbd only select approved too foreach (var p in allPoints) { p.Saved = true; } var curchild = db.Children.Where(a => a.ChildId == child.ChildId).First(); curchild.BankedPoints = child.BankedPoints; db.SaveChanges(); } }
//private void UpdateBankedPointsWithChildReward(ChildReward childreward) //{ // using (var db = new ModelKids()) // { // var child = db.Children.Where(a => a.ChildId == childreward.ChildId).First(); // child.BankedPoints = child.BankedPoints + childreward.PointsAllocated; // } //} public void ApprovePointsForChild(int childId) { using (var db = new ModelKids()) { var points = db.PointAllocation.Where(a => a.Approved == false && a.ChildId == childId); if (points != null) { foreach (var p in points) { p.Approved = true; } db.SaveChanges(); } } return; }
private void AddorUpdateRewardAwarded(List <ChildReward> rewards) { using (var db = new ModelKids()) { foreach (var m in rewards) { var childreward = db.ChildReward.Where(a => a.GoalId == m.GoalId && a.ChildId == m.ChildId).Include(i => i.Goal).FirstOrDefault(); if (childreward != null) { if (childreward.RewardComplete == true) { var ra = BuildRewardAwarded(childreward); db.RewardAwarded.Add(ra); db.ChildReward.Attach(childreward); db.ChildReward.Remove(childreward); db.SaveChanges(); } } } } }
public PointAllocation AddPoint(PointAllocation point) { var test = point.ContributorId; using (var db = new ModelKids()) { //var behaviour = db.Behaviour.Where(a => a.BehaviourId == point.BehaviourId).First(); var p1 = new PointAllocation(); p1.ChildId = point.ChildId; p1.BehaviourId = point.BehaviourId; p1.Points = point.Points; p1.AllocationDate = DateTime.Now; p1.Saved = false; p1.ContributorId = point.ContributorId; p1.Approved = point.Approved; //point.Behaviour = behaviour; db.PointAllocation.Add(p1); db.SaveChanges(); var newid = p1.PointId; point = p1; } return(point); }