public void Add(Target E) { _dbContext.Targets.Add(new Target(E.UserID, E.StartDate, E.AmountSmoked, E.ReductionGoal)); double days = ((double)E.AmountSmoked / E.ReductionGoal) * 7; int totalDays = (int)Math.Ceiling(days); int counter = 1; while (counter < totalDays) { if (counter % 7 == 0 && E.AmountSmoked > E.ReductionGoal) { int smokeReducer = E.AmountSmoked - E.ReductionGoal; E.AmountSmoked = smokeReducer; _dbContext.Targets.Add(new Target(E.UserID, E.StartDate.AddDays(counter), smokeReducer, E.ReductionGoal)); counter++; } else if (E.AmountSmoked < E.ReductionGoal && totalDays - counter <= 7) { E.ReductionGoal = E.AmountSmoked; _dbContext.Targets.Add(new Target(E.UserID, E.StartDate.AddDays(counter), E.AmountSmoked, E.ReductionGoal)); counter++; } else { _dbContext.Targets.Add(new Target(E.UserID, E.StartDate.AddDays(counter), E.AmountSmoked, E.ReductionGoal)); counter++; } _dbContext.SaveChanges(); } }
public void Delete(int id) { var consumed = _dbContext.Consumeds.Where(x => x.ConsumedID == id); _dbContext.Consumeds.RemoveRange(consumed); _dbContext.SaveChanges(); }