Пример #1
0
        /// <summary>
        /// Delete data in database
        /// </summary>
        /// <param name="key">Primary Key</param>
        public void Delete(SequencerKey key)
        {
            if (key == null || key.Id == 0)
                return;

            var sequencerRow = _dbContext.Sequencer.Where(m => m.Id == key.Id && m.Name == key.Name).FirstOrDefault();
            if (sequencerRow != null)
            {
                _dbContext.Sequencer.Remove(sequencerRow);
                _dbContext.SaveChanges();
            }
        }
Пример #2
0
        /// <summary>
        /// Get data in database
        /// </summary>
        /// <param name="key">Primary Key</param>
        /// <returns>read data</returns>
        public Sequencer Get(SequencerKey key)
        {
            if (key == null || key.Id == 0)
                return null;

            var sequencerRow = _dbContext.Sequencer.Where(m => m.Id == key.Id && m.Name == key.Name).FirstOrDefault();
            if (sequencerRow != null)
            {
                return SequencerTransformer.ToBean(sequencerRow);
            }
            return null;
        }
Пример #3
0
 public int GetNextValue(ApplicationDbContext dbContext, int sequencerId, string sequencerName)
 {
     int result = 0;
     lock (_locker)
     {
         var sequencerModule = new SequencerModule(new ApplicationDbContext());
         var key = new SequencerKey() { Id = sequencerId, Name = sequencerName };
         var sequencer = sequencerModule.Get(key);
         if (sequencer == null)
         {
             sequencer = new Sequencer() { Id = sequencerId, Name = sequencerName, Value = 1 };
             sequencer = sequencerModule.Create(sequencer);
         }
         else
         {
             sequencer.Value++;
             sequencer = sequencerModule.Update(sequencer);
         }
         result = sequencer.Value;
     }
     return result;
 }