public static bool SetFreitext (Guid ID, String FreiText) { AltErlaaInfoEntities WebAccess = new AltErlaaInfoEntities (); InformationenAddOn ExistingEntry = (from ExistingINF in WebAccess.InformationenAddOn where ExistingINF.ID == ID select ExistingINF).FirstOrDefault (); if ((ExistingEntry == null) || (ExistingEntry.ID == null) || (ExistingEntry.ID == Guid.Empty)) return false; try { ExistingEntry.FreiText = FreiText; ExistingEntry.ModifyTimeStamp = DateTime.Now; ExistingEntry.LastModifiedBy = CurrentUserName; WebAccess.MergeOption = MergeOption.AppendOnly; WebAccess.UpdateObject (ExistingEntry); DataServiceResponse Response = WebAccess.SaveChanges (); return true; } catch (Exception Excp) { Basics.ReportErrorToEventViewer ("TemplateManagement.SetFreitext", "Fehler bei UpdateObject von ID \"" + ID.ToString () + "\":\r\n" + Excp.Message); } return false; }
public static Guid InsertOrModifyInformationenAddOn (Guid ID, Guid InformationenID, String TabellenName, Guid TabelleID, DataTemplatesDescription Desc, String FreiText, bool MultipleEntriesAllowed) { AltErlaaInfoEntities WebAccess = new AltErlaaInfoEntities (); InformationenAddOn InfoAO = null; IQueryable<InformationenAddOn> OldEntries = from ExistingINF in WebAccess.InformationenAddOn where ExistingINF.InformationenID == InformationenID && ExistingINF.DataDependencyID == Desc.ID select ExistingINF; int ExistingCounter = OldEntries.Count (); if (MultipleEntriesAllowed == false) { InfoAO = OldEntries.First (); ID = InfoAO.ID; } if (ID != Guid.Empty) { try { InfoAO.InformationenID = InformationenID; InfoAO.Tabelle = TabellenName; InfoAO.TabelleID = TabelleID; InfoAO.ActuallBezeichner = Desc.ActuallBezeichner; if (InfoAO.SortOrder == null) { if (MultipleEntriesAllowed) InfoAO.SortOrder = Desc.SortOrder + ExistingCounter; else InfoAO.SortOrder = Desc.SortOrder; } InfoAO.DataDependencyID = Desc.ID; InfoAO.FreiText = FreiText; InfoAO.ModifyTimeStamp = DateTime.Now; InfoAO.LastModifiedBy = CurrentUserName; WebAccess.MergeOption = MergeOption.AppendOnly; WebAccess.UpdateObject (InfoAO); DataServiceResponse Response = WebAccess.SaveChanges (); return ID; } catch (Exception Excp) { Basics.ReportErrorToEventViewer ("TemplateManagement.InsertOrModifyInformationenAddOn", "Fehler bei UpdateObject von ID \"" + ID.ToString () + "\":\r\n" + Excp.Message); } } else { try { InfoAO = new InformationenAddOn (); InfoAO.ID = Guid.NewGuid (); InfoAO.InformationenID = InformationenID; InfoAO.Tabelle = TabellenName; InfoAO.TabelleID = TabelleID; InfoAO.ActuallBezeichner = Desc.ActuallBezeichner; if (InfoAO.SortOrder == null) { if (MultipleEntriesAllowed) InfoAO.SortOrder = Desc.SortOrder + ExistingCounter; else InfoAO.SortOrder = Desc.SortOrder; } InfoAO.DataDependencyID = Desc.ID; InfoAO.FreiText = FreiText; InfoAO.ModifyTimeStamp = DateTime.Now; InfoAO.LastModifiedBy = CurrentUserName; WebAccess.MergeOption = MergeOption.AppendOnly; WebAccess.AddObject ("InformationenAddOn", InfoAO); DataServiceResponse Response = WebAccess.SaveChanges (); return InfoAO.ID; } catch (Exception Excp) { Basics.ReportErrorToEventViewer ("TemplateManagement.InsertOrModifyInformationenAddOn", "Fehler bei AddObject von ID \"" + ID.ToString () + "\":\r\n" + Excp.Message); } } return Guid.Empty; }
private static void DeleteInformationenFromDataBase (Informationen ActuallInformation) { AltErlaaInfoEntities AllInformationenContext = new AltErlaaInfoEntities (ServiceSource); IQueryable<Informationen> DeleteInformationen = from del in AllInformationenContext.Informationen where del.ID == ActuallInformation.ID select del; foreach (Informationen DeleteableEntry in DeleteInformationen) { Guid ID = ActuallInformation.ID; try { AllInformationenContext.DeleteObject (DeleteableEntry); AllInformationenContext.SaveChanges (); } catch (DataServiceRequestException Excp ) { Basics.ReportErrorToEventViewer ("AltErlaaInfoRootControl.DeleteInformationenFromDataBase", "Fehler bei Delete von ID = \"" + ID.ToString () + "\":\r\n" + Excp.Message); } } }
public static void DeleteOneInformationenAddOnFromDataBase (Guid? InformationenAddOnID) { AltErlaaInfoEntities DeleteInformationenAddOnContext = new AltErlaaInfoEntities (ServiceSource); InformationenAddOn DeleteInformationenAddOn = (from del in DeleteInformationenAddOnContext.InformationenAddOn where del.ID == InformationenAddOnID select del).FirstOrDefault (); if ((DeleteInformationenAddOn == null) || (DeleteInformationenAddOn.ID == Guid.Empty)) return; try { DeleteInformationenAddOnContext.DeleteObject (DeleteInformationenAddOn); DeleteInformationenAddOnContext.SaveChanges (); } catch (DataServiceRequestException Excp) { Basics.ReportErrorToEventViewer ("TemplateManagement.DeleteOneInformationenAddOnFromDataBase", "Fehler bei Delete von ID = \"" + InformationenAddOnID.ToString () + "\":\r\n" + Excp.Message); } }
public static bool DoInformationenAddOnUpdate (Informationen ActuallInformation, List<TemplateElementManagement> EntriesTProcess) { AltErlaaInfoEntities InformationmenAddOnContext = new AltErlaaInfoEntities (ServiceSource); IQueryable<InformationenAddOn> OldInformationenAddOn = from InAdd in InformationmenAddOnContext.InformationenAddOn where InAdd.InformationenID == ActuallInformation.ID select InAdd; List<Guid> ProcessingHasBeenDone = new List<Guid> (); List<InformationenAddOn> ExistingEntriesToDelete = new List<InformationenAddOn> (); foreach (InformationenAddOn IAddOn in OldInformationenAddOn) { bool FoundInNew = false; foreach (TemplateElementManagement ElementManagement in EntriesTProcess) { if (ElementManagement.InfoAddOn == null) continue; if (IAddOn.ID == ElementManagement.InfoAddOn.ID) { if (((ElementManagement.InfoAddOn.TabelleID == null) || (ElementManagement.InfoAddOn.TabelleID == Guid.Empty)) && (String.IsNullOrEmpty (ElementManagement.InfoAddOn.FreiText))) { ExistingEntriesToDelete.Add (IAddOn); break; // delete this Entry } if (ElementManagement.ParentTemplateRuntime.AnythingInTheWholeEntryHasBeenModified == true) { AltErlaaInfoEntities UpdateContext = new AltErlaaInfoEntities (ServiceSource); try { InformationenAddOn ExistingInformationAddOn = (from InAddToUpdate in UpdateContext.InformationenAddOn where InAddToUpdate.ID == ElementManagement.InfoAddOn.ID select InAddToUpdate).FirstOrDefault (); UpdateContext.MergeOption = MergeOption.AppendOnly; ElementManagement.InfoAddOn.LastModifiedBy = CurrentUserName; ElementManagement.InfoAddOn.ModifyTimeStamp = DateTime.Now; Type TargetType = IAddOn.GetType (); foreach (PropertyInfo Prop in TargetType.GetProperties ()) { Prop.SetValue (ExistingInformationAddOn, Prop.GetValue (ElementManagement.InfoAddOn, null), null); } CheckForMaxLengthExceeded (ExistingInformationAddOn); UpdateContext.UpdateObject (ExistingInformationAddOn); DataServiceResponse Response = UpdateContext.SaveChanges (); } catch (Exception Excp) { Basics.ReportErrorToEventViewer ("TemplateManagement.DoInformationenAddOnUpdate", "Beim UpdateObject für IAddOn \"" + ElementManagement.InfoAddOn.ID.ToString () + "\" kam es zu folgendem Problem:\r\n" + Excp.Message); return false; } } ProcessingHasBeenDone.Add (ElementManagement.InfoAddOn.ID); } } } foreach (InformationenAddOn IAddOn in ExistingEntriesToDelete) { try { InformationmenAddOnContext.MergeOption = MergeOption.AppendOnly; InformationmenAddOnContext.DeleteObject (IAddOn); DataServiceResponse Response = InformationmenAddOnContext.SaveChanges (); } catch (Exception Excp) { Basics.ReportErrorToEventViewer ("TemplateManagement.DoInformationenAddOnUpdate", "Beim DeleteObject für AddOns \"" + IAddOn.ID.ToString () + "\" kam es zu folgendem Problem:\r\n" + Excp.Message); return false; } } foreach (TemplateElementManagement ElementManagement in EntriesTProcess) { if (ElementManagement.InfoAddOn == null) continue; if (MandatoryAddOns.ContainsKey(ElementManagement.InfoAddOn.ActuallBezeichner)) continue; Guid ProcessedBeforeID = ElementManagement.InfoAddOn.ID; if (ProcessingHasBeenDone.Contains (ProcessedBeforeID)) continue; if (((ElementManagement.InfoAddOn.TabelleID == null) || (ElementManagement.InfoAddOn.TabelleID == Guid.Empty)) && (String.IsNullOrEmpty (ElementManagement.InfoAddOn.FreiText))) { continue; } try { InformationmenAddOnContext.MergeOption = MergeOption.AppendOnly; ElementManagement.InfoAddOn.LastModifiedBy = CurrentUserName; ElementManagement.InfoAddOn.ModifyTimeStamp = DateTime.Now; if ((ElementManagement.InfoAddOn.ID == null) || (ElementManagement.InfoAddOn.ID == Guid.NewGuid ())) ElementManagement.InfoAddOn.ID = Guid.NewGuid (); CheckForMaxLengthExceeded (ElementManagement.InfoAddOn); InformationmenAddOnContext.AddObject ("InformationenAddOn", ElementManagement.InfoAddOn); DataServiceResponse Response = InformationmenAddOnContext.SaveChanges (); } catch (Exception Excp) { Basics.ReportErrorToEventViewer ("TemplateManagement.DoCompleteUpdate", "Beim AddObject für AddOns \"" + ProcessedBeforeID.ToString () + "\" kam es zu folgendem Problem:\r\n" + Excp.Message); return false; } } return true; }
private static bool DoZielGruppenUpdate (Informationen ActuallInformation, List<Guid> TargetZielgruppenSetting) { AltErlaaInfoEntities ZielGruppenAssignmentContext = new AltErlaaInfoEntities (ServiceSource); List<InformationenZuZielGruppen> OldAssignedZielGruppen = (from ZielGrp in ZielGruppenAssignmentContext.InformationenZuZielGruppen where ZielGrp.InformationenID == ActuallInformation.ID select ZielGrp).ToList (); foreach (Guid ZielGruppenID in TargetZielgruppenSetting) { int RemoveIndex = 0; bool Exists = false; foreach (InformationenZuZielGruppen Entry in OldAssignedZielGruppen) { if (Entry.ZielgruppenID == ZielGruppenID) { Exists = true; break; } RemoveIndex++; } if (Exists == true) { OldAssignedZielGruppen.RemoveAt (RemoveIndex); } else { try { ZielGruppenAssignmentContext.MergeOption = MergeOption.AppendOnly; InformationenZuZielGruppen NewEntry = new InformationenZuZielGruppen (); NewEntry.ID = Guid.NewGuid (); NewEntry.InformationenID = ActuallInformation.ID; NewEntry.ZielgruppenID = ZielGruppenID; ZielGruppenAssignmentContext.AddObject ("InformationenZuZielGruppen", NewEntry); DataServiceResponse Response = ZielGruppenAssignmentContext.SaveChanges (); } catch (Exception Excp) { Basics.ReportErrorToEventViewer ("TemplateManagement.DoZielGruppenUpdate", "Beim AddObject für InformationenZuZielGruppen \"" + ZielGruppenID.ToString () + "\" kam es zu folgendem Problem:\r\n" + Excp.Message); return false; } } } foreach (InformationenZuZielGruppen DeleteableEntry in OldAssignedZielGruppen) { Guid ID = DeleteableEntry.ID; try { ZielGruppenAssignmentContext.DeleteObject (DeleteableEntry); ZielGruppenAssignmentContext.SaveChanges (); } catch (DataServiceRequestException Excp) { Basics.ReportErrorToEventViewer ("TemplateManagement.DoZielGruppenUpdate", "Fehler bei Delete von ID = \"" + ID.ToString () + "\":\r\n" + Excp.Message.ToString ()); } } return true; }
public static bool DoInformationenUpdate (Informationen ActuallInformation, TemplateElementManagement EntryToProcess) { //if (EntryToProcess.InfoAddOn.Informationen != ActuallInformation) // throw new Exception ("EntryToProcess.InfoAddOn.Informationen != ActuallInformation"); AltErlaaInfoEntities UpdateContext = new AltErlaaInfoEntities (ServiceSource); Informationen StoredInformationen = (from Inf in UpdateContext.Informationen where Inf.ID == ActuallInformation.ID select Inf).FirstOrDefault (); if ((StoredInformationen == null) || (StoredInformationen.ID == Guid.Empty)) { try { DoTabelleDefaultModifications (EntryToProcess, ActuallInformation, true); UpdateContext.MergeOption = MergeOption.AppendOnly; UpdateContext.AddObject ("Informationen", ActuallInformation); DataServiceResponse Response = UpdateContext.SaveChanges (); } catch (Exception Excp) { Basics.ReportErrorToEventViewer ("TemplateManagement.DoCompleteUpdate", "Beim AddObject für ActuallInformation \"" + ActuallInformation.ID.ToString () + "\" kam es zu folgendem Problem:\r\n" + Excp.Message); return false; } } else { try { DoTabelleDefaultModifications (EntryToProcess, ActuallInformation, false); UpdateContext.MergeOption = MergeOption.AppendOnly; Type TargetType = StoredInformationen.GetType (); foreach (PropertyInfo Prop in TargetType.GetProperties ()) { Prop.SetValue (StoredInformationen, Prop.GetValue (ActuallInformation, null), null); } UpdateContext.UpdateObject (StoredInformationen); DataServiceResponse Response = UpdateContext.SaveChanges (); } catch (Exception Excp) { Basics.ReportErrorToEventViewer ("TemplateManagement.DoCompleteUpdate", "Beim UpdateObject für ActuallInformation \"" + ActuallInformation.ID.ToString () + "\" kam es zu folgendem Problem:\r\n" + Excp.Message); return false; } } return true; }