public int Create(int companyId, Format_Create parseData) { using (CDStudioEntities dbEntity = new CDStudioEntities()) { DeviceCommandCatalog newData = new DeviceCommandCatalog(); newData.CompanyId = companyId; newData.Name = parseData.Name; newData.Method = parseData.Method; newData.Content = parseData.Content ?? ""; dbEntity.DeviceCommandCatalog.Add(newData); try { dbEntity.SaveChanges(); } catch (DbUpdateException ex) { if (ex.InnerException.InnerException.Message.Contains("Cannot insert duplicate key")) { throw new CDSException(10404); } else { throw ex; } } return(newData.Id); } }
public void DeleteById(int id) { using (CDStudioEntities dbEntity = new CDStudioEntities()) { DeviceCommandCatalog existingData = dbEntity.DeviceCommandCatalog.Find(id); if (existingData == null) { throw new CDSException(10403); } dbEntity.DeviceCommandCatalog.Remove(existingData); dbEntity.SaveChanges(); } }
public Format_Detail GetById(int id) { using (CDStudioEntities dbEntity = new CDStudioEntities()) { DeviceCommandCatalog existingData = (from c in dbEntity.DeviceCommandCatalog.AsNoTracking() where c.Id == id select c).SingleOrDefault <DeviceCommandCatalog>(); if (existingData == null) { throw new CDSException(10403); } return(new Format_Detail() { Id = existingData.Id, Name = existingData.Name, Content = existingData.Content, Method = existingData.Method }); } }