/// <summary> /// Update device type /// </summary> /// <param name="deviceType"></param> /// <returns></returns> public int UpdateDeviceType(DeviceTypeDomain deviceType) { if (deviceType == null) { throw new NsiArgumentNullException(DeviceMessages.DeviceInvalidArgument); } var deviceTypeDb = _context.DeviceType.Where(x => x.DeviceTypeId == deviceType.DeviceTypeId).FirstOrDefault().FromDomainModel(deviceType); if (deviceTypeDb == null) { throw new NsiNotFoundException(DeviceMessages.DeviceNotFound); } var actionIds = deviceType.Actions.Select(x => x.ActionId).ToList(); var propertyIds = deviceType.Properties.Select(x => x.PropertyId).ToList(); foreach (EF.Action action in deviceTypeDb.Action.ToList()) { deviceTypeDb.Action.Remove(action); } foreach (Property property in deviceTypeDb.Property.ToList()) { deviceTypeDb.Property.Remove(property); } deviceTypeDb.Action = _context.Action.Where(x => actionIds.Contains(x.ActionId)).ToList(); deviceTypeDb.Property = _context.Property.Where(x => propertyIds.Contains(x.PropertyId)).ToList(); _context.SaveChanges(); return(deviceTypeDb.DeviceTypeId); }
/// <summary> /// Update device type /// </summary> /// <param name="deviceType"></param> /// <returns></returns> public int UpdateDeviceType(DeviceTypeDomain deviceType) { if (deviceType == null) { throw new NsiArgumentException(DeviceTypeMessages.DeviceTypeInvalidArgument); } return(_deviceTypeRepository.UpdateDeviceType(deviceType)); }
public AgencyController() { _agencyDomain = new AgencyDomain(); _serviceITSupportDomain = new ServiceITSupportDomain(); _serviceItemDomain = new ServiceItemDomain(); _deviceDomain = new DeviceDomain(); _accountDomain = new AccountDomain(); _requestDomain = new RequestDomain(); _deviceTypeDomain = new DeviceTypeDomain(); }
public static DeviceType FromDomainModel(this DeviceType obj, DeviceTypeDomain domain) { if (obj == null) { obj = new DeviceType(); } obj.DeviceTypeId = domain.DeviceTypeId; obj.Name = domain.Name; obj.Code = domain.Code; obj.IsActive = domain.IsActive; return(obj); }
/// <summary> /// Updates device type /// </summary> /// <returns><see cref="IHttpActionResult"/></returns> public IHttpActionResult UpdateDeviceType([FromBody] DeviceTypeDomain deviceType) { if (deviceType == null) { return(Content(System.Net.HttpStatusCode.BadRequest, DeviceTypeMessages.DeviceTypeInvalidArgument)); } var result = _deviceTypeManipulation.UpdateDeviceType(deviceType); if (result <= 0) { return(Content(System.Net.HttpStatusCode.BadRequest, DeviceTypeMessages.DeviceTypeUpdateFailed)); } return(Ok(result)); }
/// <summary> /// Create device type /// </summary> /// <param name="deviceType"></param> /// <returns></returns> public int CreateDeviceType(DeviceTypeDomain deviceType) { if (deviceType == null) { throw new NsiArgumentNullException(DeviceTypeMessages.DeviceTypeInvalidArgument); } var deviceTypedb = new DeviceType().FromDomainModel(deviceType); var actionIds = deviceType.Actions.Select(x => x.ActionId).ToList(); var propertyIds = deviceType.Properties.Select(x => x.PropertyId).ToList(); deviceTypedb.Action = _context.Action.Where(x => actionIds.Contains(x.ActionId)).ToList(); deviceTypedb.Property = _context.Property.Where(x => propertyIds.Contains(x.PropertyId)).ToList(); _context.DeviceType.Add(deviceTypedb); _context.SaveChanges(); return(deviceTypedb.DeviceTypeId); }
public void GetDeviceTypeById_Success() { DeviceTypeDomain deviceType = _deviceTypeManipulation.GetDeviceTypeById(1); Assert.AreEqual(1, deviceType.DeviceTypeId); }
public DeviceTypeController() { _devicetypeDomain = new DeviceTypeDomain(); }