Ejemplo n.º 1
0
        public DeviceMontageType GetDeviceMontageTypeByNameOrInsert(string _name)
        {
            try
            {
                using (var context = new VeraEntities())
                {
                    var DeviceMontageType = context.DeviceMontageType.FirstOrDefault(x => x.Name.Trim() == _name.Trim() && x.Status > 0);

                    if (DeviceMontageType == null)
                    {
                        DeviceMontageType = new DeviceMontageType()
                        {
                            Name   = _name.Trim(),
                            Status = 1
                        };

                        context.DeviceMontageType.Add(DeviceMontageType);
                        context.SaveChanges();
                        return(DeviceMontageType);
                    }

                    return(DeviceMontageType);
                }
            }
            catch (Exception exc)
            {
                throw exc;
            }
        }
Ejemplo n.º 2
0
 private void UpdateObject(DeviceMontageType _newDeviceMontageType, ref DeviceMontageType _oldDeviceMontageType)
 {
     try
     {
         foreach (PropertyInfo DeviceMontageTypePropInfo in _newDeviceMontageType.GetType().GetProperties().ToList())
         {
             _oldDeviceMontageType.GetType().GetProperty(DeviceMontageTypePropInfo.Name).SetValue(_oldDeviceMontageType, _newDeviceMontageType.GetType().GetProperty(DeviceMontageTypePropInfo.Name).GetValue(_newDeviceMontageType));
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
Ejemplo n.º 3
0
 public DeviceMontageType AddNewDeviceMontageType(DeviceMontageType _DeviceMontageType)
 {
     try
     {
         using (var context = new VeraEntities())
         {
             context.DeviceMontageType.Add(_DeviceMontageType);
             int numOfInserted = context.SaveChanges();
             return(numOfInserted > 0 ? _DeviceMontageType : null);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Ejemplo n.º 4
0
        public DeviceMontageType UpdateDeviceMontageType(DeviceMontageType _DeviceMontageType)
        {
            try
            {
                using (var context = new VeraEntities())
                {
                    var oldDeviceMontageType = context.DeviceMontageType.FirstOrDefault(u => u.Id == _DeviceMontageType.Id);
                    if (oldDeviceMontageType != null)
                    {
                        UpdateObject(_DeviceMontageType, ref oldDeviceMontageType);
                        var numberOfUpdatedDeviceMontageType = context.SaveChanges();
                        return(numberOfUpdatedDeviceMontageType > 0 ? _DeviceMontageType : null);
                    }

                    return(null);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }