public bool DeleteContact(long id)
        {
            CCItems dbEntry = context.CCContacts.Find(id);
            if (dbEntry != null)
            {
                //  context.CCContacts.Remove(dbEntry);
                dbEntry.LastUpdated = DateTime.Now.ToUniversalTime();
                dbEntry.isDeleted = true;
                context.SaveChanges();

                CCHistoryLog HistoryLog = new CCHistoryLog();
                HistoryLog.AccountGUID = dbEntry.AccountGUID;
                HistoryLog.Date = DateTime.Now;
                HistoryLog.FieldID = 0;
                HistoryLog.ItemID = dbEntry.ItemID;
                HistoryLog.NewValue = "" ;
                HistoryLog.OldValue = "";
                HistoryLog.Source = "Web";
                HistoryLog.Action = "Delete";
                HistoryLog.ConnectionID = 0;
                context.CCHistoryLog.Add(HistoryLog);
                context.SaveChanges();

                return true;
            }
            return false;
        }
        public bool DeleteFieldValueByITemID(long id)
        {
            List<CCFieldValue> dbEntryList = context.CCFieldValues.Where(fv => fv.ItemID==id).ToList();

            foreach (var dbEntry in dbEntryList)
            {
                if (dbEntry != null)
                {
                    CCHistoryLog HistoryLog = new CCHistoryLog();
                    HistoryLog.AccountGUID = dbEntry.AccountGUID;
                    HistoryLog.Date = DateTime.Now;
                    HistoryLog.FieldID = dbEntry.FieldID;
                    HistoryLog.ItemID = dbEntry.ItemID;
                    HistoryLog.NewValue = dbEntry.Value;
                    HistoryLog.OldValue = "";
                    HistoryLog.Source = "Web";
                    HistoryLog.Action = "Delete";
                    context.CCHistoryLog.Add(HistoryLog);

                    context.CCFieldValues.Remove(dbEntry);
                    context.SaveChanges();

                }
            }
            return true;
        }
        public CCHistoryLog SaveHistoryLog(CCHistoryLog historyLogsObj)
        {
            if (historyLogsObj.ID == 0)
            {
                context.CCHistoryLog.Add(historyLogsObj);
                context.SaveChanges();
            }

            return historyLogsObj;
        }
        public bool DeleteFieldValue(long id)
        {
            CCFieldValue  dbEntry = context.CCFieldValues.Find(id);
            if (dbEntry != null)
            {
                CCHistoryLog HistoryLog = new CCHistoryLog();
                HistoryLog.AccountGUID = dbEntry.AccountGUID;
                HistoryLog.Date = DateTime.Now;
                HistoryLog.FieldID = dbEntry.FieldID;
                HistoryLog.ItemID = dbEntry.ItemID;
                HistoryLog.NewValue = dbEntry.Value;
                HistoryLog.OldValue = "";
                HistoryLog.Source = "Web";
                HistoryLog.Action = "Delete";
                context.CCHistoryLog.Add(HistoryLog);

                context.CCFieldValues.Remove(dbEntry);
                context.SaveChanges();
                return true;
            }
            return false;
        }
        public CCFieldValue RevertChangeToFieldValues(CCFieldValue FieldValueObj, CCHistoryLog HistLogObj)
        {
            CCFieldValue dbEntry = context.CCFieldValues.Find(FieldValueObj.ValueID);
            if (dbEntry != null)
            {
                CCHistoryLog HistoryLog = new CCHistoryLog();
                HistoryLog.AccountGUID = FieldValueObj.AccountGUID;
                HistoryLog.Date = DateTime.Now;
                HistoryLog.FieldID = dbEntry.FieldID;
                HistoryLog.ItemID = dbEntry.ItemID;
                HistoryLog.NewValue = FieldValueObj.Value;
                HistoryLog.OldValue = HistLogObj.NewValue;
                HistoryLog.Source = "Web";
                HistoryLog.Action = "Update";
                HistoryLog.ConnectionID = 0;
                context.CCHistoryLog.Add(HistoryLog);

                dbEntry.Value = FieldValueObj.Value;

                context.SaveChanges();
            }
            return FieldValueObj;
        }
        public CCFieldValue SaveFieldValues(CCFieldValue FieldValueObj)
        {
            if (FieldValueObj.ValueID == 0)
            {
                context.CCFieldValues.Add(FieldValueObj);
                //context.SaveChanges();

                CCHistoryLog HistoryLog = new CCHistoryLog();
                HistoryLog.AccountGUID = FieldValueObj.AccountGUID;
                HistoryLog.Date = DateTime.Now;
                HistoryLog.FieldID = FieldValueObj.FieldID;
                HistoryLog.ItemID = FieldValueObj.ItemID;
                HistoryLog.NewValue = FieldValueObj.Value;
                HistoryLog.OldValue = "";
                HistoryLog.Source = "Web";
                HistoryLog.Action = "Insert";
                HistoryLog.ConnectionID = 0;
                context.CCHistoryLog.Add(HistoryLog);
                context.SaveChanges();
            }
            else
            {
                CCFieldValue dbEntry = context.CCFieldValues.Find(FieldValueObj.ValueID);
                if (dbEntry != null)
                {
                    if (dbEntry.Value != FieldValueObj.Value)
                    {
                        CCHistoryLog HistoryLog = new CCHistoryLog();
                        HistoryLog.AccountGUID = FieldValueObj.AccountGUID;
                        HistoryLog.Date = DateTime.Now;
                        HistoryLog.FieldID = dbEntry.FieldID;
                        HistoryLog.ItemID = dbEntry.ItemID;
                        HistoryLog.NewValue = FieldValueObj.Value;
                        HistoryLog.OldValue = dbEntry.Value;
                        HistoryLog.Source = "Web";
                        HistoryLog.Action = "Update";
                        HistoryLog.ConnectionID = 0;
                        context.CCHistoryLog.Add(HistoryLog);
                        //context.SaveChanges();

                        dbEntry.LastUpdated = DateTime.UtcNow;
                    }
                    dbEntry.Value = FieldValueObj.Value;
                    context.SaveChanges();
                }

            }
            return FieldValueObj;
        }
        public List<CCFieldValue> SaveFieldsObjValues(List<CCFieldValue> FieldValues)
        {
            foreach (CCFieldValue fieldvalues in FieldValues)
            {
                context.CCFieldValues.Add(fieldvalues);

                CCHistoryLog HistoryLog = new CCHistoryLog();
                HistoryLog.AccountGUID = fieldvalues.AccountGUID;
                HistoryLog.Date = DateTime.Now;
                HistoryLog.FieldID = fieldvalues.FieldID;
                HistoryLog.ItemID = fieldvalues.ItemID;
                HistoryLog.NewValue = fieldvalues.Value;
                HistoryLog.OldValue = "";
                HistoryLog.Source = "Web";
                HistoryLog.Action = "Insert";
                HistoryLog.ConnectionID = 0;
                context.CCHistoryLog.Add(HistoryLog);
                //context.SaveChanges();
            }
            context.SaveChanges();
            return FieldValues;
        }
        public bool UpdateContact(CCItems contactObj)
        {
            CCItems dbEntry = context.CCContacts.Find(contactObj.ItemID);
            if (dbEntry != null)
            {
                dbEntry.LastUpdated = DateTime.Now.ToUniversalTime();
                dbEntry.DeDupeValue = contactObj.DeDupeValue;

                if (dbEntry.TextBody != contactObj.TextBody)
                    dbEntry.TextBody = contactObj.TextBody;

                if (dbEntry.Notes != contactObj.Notes)
                    dbEntry.Notes = contactObj.Notes;

                if (dbEntry.isDeleted != contactObj.isDeleted)
                {
                    CCHistoryLog HistoryLog = new CCHistoryLog();
                    HistoryLog.AccountGUID = dbEntry.AccountGUID;
                    HistoryLog.Date = DateTime.Now;
                    HistoryLog.FieldID = 0;
                    HistoryLog.ItemID = dbEntry.ItemID;
                    HistoryLog.NewValue = "";
                    HistoryLog.OldValue = "";
                    HistoryLog.Source = "Web";
                    HistoryLog.Action = "Delete-Revert";
                    HistoryLog.ConnectionID = 0;
                    context.CCHistoryLog.Add(HistoryLog);
                    context.SaveChanges();

                    dbEntry.isDeleted = contactObj.isDeleted;
                }
                context.SaveChanges();
                return true;
            }

            return false;
        }