Ejemplo n.º 1
0
        public static void ToRow(Sequencer bean, SequencerRow row)
        {
            if (bean == null)
                return;

            row.Id = bean.Id;
            row.Name = bean.Name;
            row.Value = bean.Value;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create data in database
        /// </summary>
        /// <param name="sequencer">Data</param>
        /// <returns>insert data</returns>
        public Sequencer Create(Sequencer sequencer)
        {
            if (sequencer == null)
                return null;

            var sequencerRow = new SequencerRow();
            SequencerTransformer.ToRow(sequencer, sequencerRow);
            _dbContext.Sequencer.Add(sequencerRow);
            _dbContext.SaveChanges();
            return SequencerTransformer.ToBean(sequencerRow);
        }
Ejemplo n.º 3
0
        internal static Sequencer ToBean(SequencerRow row)
        {
            if (row == null)
                return null;

            var bean = new Sequencer();
            bean.Id = row.Id;
            bean.Name = row.Name;
            bean.Value = row.Value;
            return bean;
        }
Ejemplo n.º 4
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;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Update data in database
        /// </summary>
        /// <param name="sequencer">data</param>
        /// <returns>updated data</returns>
        public Sequencer Update(Sequencer sequencer)
        {
            if (sequencer == null || sequencer.Id == 0)
                return null;

            var sequencerRow = _dbContext.Sequencer.Where(m => m.Id == sequencer.Id && m.Name == sequencer.Name).FirstOrDefault();
            if (sequencerRow == null)
            { // No data in database
                return Create(sequencer);
            }
            else
            { //Modify Data in database
                SequencerTransformer.ToRow(sequencer, sequencerRow);
                _dbContext.SaveChanges();
                return SequencerTransformer.ToBean(sequencerRow);
            }
        }