/// <summary> /// Adds a total entry to the TotalEntry table. /// </summary> /// <param name="_program">The program name you are adding a total for</param> /// <param name="_hours">The hours to add to the total entry</param> /// <param name="_comments">Comments to add for the total entry</param> /// <param name="_date">The DateID to add to the total</param> public override void AddTotal(Programs _program, Dates _date, string _comments = default(string), decimal?_hours = default(decimal?)) { using (var context = new TimeKeeperDBEntities()) { Totals total = new Totals(); total.ProgramName = _program.Name; total.DateID = _date.DateID; total.Comments = _comments; if (_hours != null) { total.Hours = _hours; } context.Totals.Add(total); context.SaveChanges(); } }
/// <summary> /// Deletes the specified total entry from the TotalEntry table /// </summary> /// <param name="_total">The requested Total for deletion</param> public override void DeleteTotal(Totals _total) { // TODO: Research if it is possible to generalize the delete method using DeleteObject<T>(T _object) instead of having four separate methods for each type using (var context = new TimeKeeperDBEntities()) { var total = context.Totals.Where(t => t.TotalID.Equals(_total.TotalID)).FirstOrDefault(); try { context.Totals.Remove(total); context.SaveChanges(); } catch { throw; } } }
public abstract void DeleteTotal(Totals total);