Beispiel #1
0
        public void Add(UserMeter newUserMeter)
        {
            UserMeter oldUserMeter;

            lock (Lock)
            {
                if ((oldUserMeter = ctx.UserMeters.Find(newUserMeter.Id)) != null)
                {
                    throw new Exception($"Element with ID : {newUserMeter.Id} is already found in database.");
                }
                else
                {
                    ctx.UserMeters.Add(newUserMeter);
                    ctx.SaveChanges();
                }
            }
        }
Beispiel #2
0
        public void ModifyId(int oldId, int newId)
        {
            UserMeter oldUserMeter;

            lock (Lock)
            {
                if ((oldUserMeter = ctx.UserMeters.Find(oldId)) == null)
                {
                    throw new Exception($"Element with ID : {oldId} not found.");
                }
                else
                {
                    UserMeter newUserMeter = new UserMeter()
                    {
                        Id = newId, ElectricEnergy = oldUserMeter.ElectricEnergy, Name = oldUserMeter.Name
                    };
                    Delete(oldId);
                    Add(newUserMeter);
                    ctx.SaveChanges();
                }
            }
        }