Esempio n. 1
0
        public RepositoryActionResult <Actuator> Update(Actuator actuator)
        {
            try
            {
                var existingAct = context.Actuator.Where(c => c.ActuatorId == actuator.ActuatorId).FirstOrDefault();

                if (existingAct != null)
                {
                    context.Entry(existingAct).State = EntityState.Detached;
                    context.Actuator.Attach(actuator);
                    context.Entry(actuator).State = EntityState.Modified;
                    context.SaveChanges();
                    return(new RepositoryActionResult <Actuator>(actuator, RepositoryActionStatus.Updated));
                }
                return(new RepositoryActionResult <Actuator>(null, RepositoryActionStatus.NothingModified));
            }
            catch (Exception ex)
            {
                return(new RepositoryActionResult <Actuator>(null, RepositoryActionStatus.Error, ex));
            }
        }
Esempio n. 2
0
 public RepositoryActionResult <Unit> Update(Unit entity)
 {
     try
     {
         var existingUnit = context.Unit.Where(c => c.UnitId == entity.UnitId).FirstOrDefault();
         if (existingUnit != null)
         {
             context.Entry(existingUnit).State = EntityState.Detached;
             context.Unit.Attach(entity);
             context.Entry(entity).State = EntityState.Modified;
             context.SaveChanges();
             return(new RepositoryActionResult <Unit>(entity, RepositoryActionStatus.Updated));
         }
         else
         {
             return(new RepositoryActionResult <Unit>(entity, RepositoryActionStatus.NotFound));
         }
     }
     catch (Exception ex)
     {
         return(new RepositoryActionResult <Unit>(null, RepositoryActionStatus.Error, ex));
     }
 }
Esempio n. 3
0
        public RepositoryActionResult <Alarm> Update(Alarm alarm)
        {
            var existingAlarm = context.Alarm.FirstOrDefault(ea => ea.AlarmId == alarm.AlarmId);

            if (existingAlarm == null)
            {
                return(new RepositoryActionResult <Alarm>(alarm, RepositoryActionStatus.NotFound));
            }

            context.Entry(existingAlarm).State = EntityState.Detached;
            context.Alarm.Attach(alarm);
            context.Entry(alarm).State = EntityState.Modified;

            var result = context.SaveChanges();

            if (result > 0)
            {
                return(new RepositoryActionResult <Alarm>(alarm, RepositoryActionStatus.Updated));
            }
            else
            {
                return(new RepositoryActionResult <Alarm>(alarm, RepositoryActionStatus.NothingModified));
            }
        }