/// <summary> /// Gets a StbDivision named @name or creates one if it doesn't exist. May return null if @name is empty or null. /// </summary> /// <param name="name">Name of the Stb division.</param> /// <returns>StbDivision</returns> private StbDivision GetStbDivisionByName(string name) { if (name == null || name.Equals ("")) { return null; } IQueryable<StbDivision> divisions = _ctx.Entities.OfType<StbDivision> (); IQueryable<StbDivision> selectedDivisions = divisions.Where (p => p.Name.Equals (name)); if (selectedDivisions.Count () == 0) { // Center not found, create one StbDivision division = new StbDivision (); division.Name = name; _ctx.Entities.Add (division); _ctx.SaveChanges(); return division; } return selectedDivisions.First (); }
/// <summary> /// Adds a new relation to the person. /// </summary> /// <param name="p">Person</param> /// <param name="division">Stb division.</param> /// <param name="comment">Comment</param> private void AddStbRelationToPerson(Person p, StbDivision division, string comment, RelationType type) { Relation r = new Relation (); r.SubjectiveEntity = division; r.RelationType = type; r.ObjectiveEntity = p; r.Note = comment; _ctx.Relations.Add (r); }