예제 #1
0
        /// <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));
            }
        }
예제 #2
0
        /// <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); }
            }
        }