public void UpdateRecord(User user,Record record,JournalCollection jcollection)
 {
     using (RecordAccessClient _recordAccessClient = new RecordAccessClient(EndpointName.RecordAccess))
     {
         _recordAccessClient.Update(user, record, jcollection.ToArray());
     }
 }
 public int InsertRecord(Record record, JournalCollection jcollection)
 {
     using (RecordAccessClient _recordAccessClient = new RecordAccessClient(EndpointName.RecordAccess))
     {
         return _recordAccessClient.Insert(record, jcollection.ToArray());
     }
 }
        public int SaveRecord(Record record, JournalCollection jcollection)
        {
            //log record
            var _logRecord = LoadRecordByPeriodEntityID(record.EntityID, record.Period.ID);
            if (_logRecord.Any())
            {
                JournalCollection _delJournalCollection= new JournalCollection();
                JournalCollection _updJournalCollection = new JournalCollection();
                var _newJournal = jcollection;
                foreach (var _journal in _logRecord[0].JournalCollection)
                {
                    if (_newJournal.Any(x => _journal.EntityID == x.EntityID && _journal.BaseAmount == x.BaseAmount))
                        continue;
                    else if (_newJournal.Any(x => _journal.EntityID == x.EntityID))
                        _updJournalCollection.Add(_newJournal.First(x => x.EntityID == _journal.EntityID));
                    else
                        _delJournalCollection.Add(_journal);
                }

                #region "Update function"
                if (_updJournalCollection.Any())
                {
                    using (RecordAccessClient _recordAccessClient = new RecordAccessClient(EndpointName.RecordAccess))
                    {
                        try
                        {
                            _recordAccessClient.UpdateJournalCollection(_updJournalCollection.ToArray());
                        }
                        catch(Exception ex)
                        {
                            return -1;
                        }
                    }
                }
                #endregion

                #region "Delete function"
                if (_delJournalCollection.Any())
                {
                    using (RecordAccessClient _recordAccessClient = new RecordAccessClient(EndpointName.RecordAccess))
                    {
                        try
                        {
                            _recordAccessClient.InsertDeletionLog(_delJournalCollection.ToArray());
                        }
                        catch (Exception ex)
                        {
                            return -1;
                        }
                    }
                }
                #endregion

                return record.RecordID;
            }
            else
            {
                using (RecordAccessClient _recordAccessClient = new RecordAccessClient(EndpointName.RecordAccess))
                {
                    return _recordAccessClient.Insert(record, jcollection.ToArray());
                }
            }
        }