public void ChangeInformationTable(string informationTableId, InformationTable newInformationTable) { var informationTable = db.InformationTables .Any(i => i.Id == informationTableId) ? db.InformationTables .FirstOrDefault(i => i.Id == informationTableId) : null; if (informationTable == null || newInformationTable == null) { return; } informationTable.HeightWithModule = newInformationTable.HeightWithModule; informationTable.RowCount = newInformationTable.RowCount; informationTable.WidthWithModule = newInformationTable.WidthWithModule; informationTable.IpDevice = newInformationTable.IpDevice; informationTable.PasswordDevice = newInformationTable.PasswordDevice; informationTable.UserNameDevice = newInformationTable.UserNameDevice; try { db.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = $"{validationErrors.Entry.Entity}:{validationError.ErrorMessage}"; raise = new InvalidOperationException(message, raise); } } } }
public StationModel ActivateInformationTable(string stationId) { InformationTable defaultInformationTable; var defaultContent = new Content() { ContentType = ContentType.FORECAST, Id = Guid.NewGuid().ToString(), InnerContent = stationId, TimeOut = 15 }; var station = db.Stations .Any(s => s.Id == stationId) ? db.Stations .FirstOrDefault(s => s.Id == stationId) : null; var moduleType = db.ModuleTypes .Any() ? db.ModuleTypes .FirstOrDefault() : null; if (station == null || moduleType == null) { return(null); } if (station.InformationTable == null) { defaultInformationTable = new InformationTable() { Id = Guid.NewGuid() .ToString(), AccessCode = Guid.NewGuid() .ToString(), ServiceType = 0, PasswordDevice = "", IpDevice = "", UserNameDevice = "", HeightWithModule = 2, WidthWithModule = 4, RowCount = 4 }; defaultInformationTable.Contents .Add(defaultContent); db.InformationTables.Add(defaultInformationTable); try { db.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = $"{validationErrors.Entry.Entity}:{validationError.ErrorMessage}"; raise = new InvalidOperationException(message, raise); } } } var informationTable = db.InformationTables .Any(i => string.Equals(i.Id, defaultInformationTable.Id)) ? db.InformationTables .FirstOrDefault(i => string.Equals(i.Id, defaultInformationTable.Id)) : null; if (informationTable == null) { return(null); } informationTable.ModuleType = moduleType; station.InformationTable = informationTable; } station.Active = true; try { db.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = $"{validationErrors.Entry.Entity}:{validationError.ErrorMessage}"; raise = new InvalidOperationException(message, raise); } } } return(station); }