public long CreateContact(long fid, string augid)
        {
            CCItems objcontact = new CCItems();
            objcontact.FolderID = fid;
            objcontact.LastUpdated = DateTime.Now.ToUniversalTime();
            objcontact.Created = DateTime.Now.ToUniversalTime();
            objcontact.isDistGroup = false;
            objcontact.isRecurring = false;
            objcontact.AccountGUID = augid;
            var cont = this.SaveContact(objcontact);

            return cont.ItemID;
        }
        public string getTitleForItem(CCItems item)
        {
            string[] seperatedValues = seperateDeDupeValue(item.DeDupeValue);

            if (seperatedValues.Count() == 4)
            {
                if (seperatedValues[0] != "" && seperatedValues[2] != "")
                {
                    return seperatedValues[0] + " " + seperatedValues[2] + " - " + seperatedValues[3];
                }
                else
                {
                    return item.ItemID.ToString();
                }
            }
            else if (seperatedValues.Count() == 3)
            {
                if (seperatedValues[0] != "")
                {
                    return seperatedValues[0];
                }
                else
                {
                    return item.ItemID.ToString();
                }
            }
            return "";
        }
        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;
        }
        public CCItems SaveContact(CCItems contactObj)
        {
            if (contactObj.ItemID == 0)
            {
                context.CCContacts.Add(contactObj);
                context.SaveChanges();
            }
            else
            {
                CCItems dbEntry = context.CCContacts.Find(contactObj.ItemID);
                if (dbEntry != null)
                {
                    dbEntry.LastUpdated = DateTime.Now.ToUniversalTime();
                    context.SaveChanges();
                }

            }

            return contactObj;
        }
 private bool UpdateContact(AddDedupeViewModel dedupe, long contectID, int type, string notes)
 {
     CCItems contact = new CCItems();
     contact.ItemID = contectID;
     contact.Notes = notes;
     contact.TextBody = notes;
     if (type == 1) { contact.DeDupeValue = dedupe.FirstName + "|" + dedupe.MiddleName + "|" + dedupe.LastName + "|" + dedupe.CompanyName + "|" + dedupe.Email; }
     else { contact.DeDupeValue = dedupe.Subject + "|" + dedupe.StartDateTime + "|" + dedupe.EndDateTime; }
     bool res = CCItemRepository.UpdateContact(contact);
     return res;
 }