/// <summary> /// Saves the call. /// </summary> /// <param name="call">The call.</param> /// <exception cref="System.ArgumentNullException">rvItemId;Rv Item Id can't be null</exception> public static bool AddOrUpdateCall(ref RvPreviousVisitData call) { if (call.RvItemId < 0) { throw new ArgumentNullException("call", "Rv Item Id can't be null"); } int itemId = call.ItemId; using (var db = new RvPreviousVisitsContext(RvPreviousVisitsContext.DBConnectionString)) { if (itemId > 0 && db.RvPreviousVisitItems.Any(s => s.ItemId == itemId)) { RvPreviousVisitItem c = db.RvPreviousVisitItems.Single(s => s.ItemId == itemId); c.RvItemId = call.RvItemId; c.Magazines = call.Magazines; c.Books = call.Books; c.Brochures = call.Brochures; c.Date = call.Date; c.Notes = call.Notes; c.Tracts = call.Tracts; db.SubmitChanges(); return(c.ItemId > 0 && ReturnVisitsInterface.UpdateLastVisitDate(call.RvItemId, call.Date)); // existing call saved. } var cc = RvPreviousVisitData.Copy(call); db.RvPreviousVisitItems.InsertOnSubmit(cc); db.SubmitChanges(); call.ItemId = cc.ItemId; return(call.ItemId >= 0 && ReturnVisitsInterface.UpdateLastVisitDate(call.RvItemId, call.Date)); } }
/// <summary> /// Deletes the call. /// </summary> /// <param name="callId">The call id.</param> public static bool DeleteCall(int callId) { using (var db = new RvPreviousVisitsContext(RvPreviousVisitsContext.DBConnectionString)) { try { RvPreviousVisitItem call = db.RvPreviousVisitItems.Single(s => s.ItemId == callId); db.RvPreviousVisitItems.DeleteOnSubmit(call); db.SubmitChanges(); return(ReturnVisitsInterface.DeleteCallFromRv(call.RvItemId, call.Date)); } catch { return(false); } } }
/// <summary> /// Deletes all calls from rv. /// </summary> /// <param name="itemId">The item id.</param> public static bool DeleteAllCallsFromRv(int itemId) { using (var db = new RvPreviousVisitsContext(RvPreviousVisitsContext.DBConnectionString)) { try { var calls = from x in db.RvPreviousVisitItems where x.RvItemId == itemId select x; db.RvPreviousVisitItems.DeleteAllOnSubmit(calls); db.SubmitChanges(); return(true); } catch (Exception) { return(false); } } }