public static void ApplyUpdate(this Database.Attribute dataItem, Contracts.Attribute.UpdateAttribute update) { dataItem.Name = update.Name; dataItem.Description = update.Description; dataItem.UpdatedOn = DateTime.Now; dataItem.Comment = update.Comment; dataItem.AttributeCategoryId = update.AttributeCategoryId; dataItem.MonthTimeframe = (int?)update.Timeframe.Months; dataItem.DayTimeframe = (int?)update.Timeframe.Days; dataItem.HourTimeframe = (int?)update.Timeframe.Hours; dataItem.Source = update.Source; }
public static void RemoveChildAttributes(RAAPEntities db, Database.Attribute attribute, Attribute[] childAttributes) { if (childAttributes == null) { childAttributes = new Attribute[0]; } var validAttributeIds = childAttributes.Select(al => al.AttributeId).ToArray(); var missingAttributeLinks = attribute.AttributeLinks1.Where(al => !validAttributeIds.Contains(al.AttributeId)).ToArray(); db.AttributeLinks.RemoveRange(missingAttributeLinks); }
public static Contracts.Attribute.Attribute ToContract(this Database.Attribute dataItem, bool isFirstLevel = true) { return(new Contracts.Attribute.Attribute { AttributeCategoryId = dataItem.AttributeCategoryId, AttributeCategoryName = dataItem.AttributeCategory != null ? dataItem.AttributeCategory.Name : "", Name = dataItem.Name, Description = dataItem.Description, CreatedOn = dataItem.CreatedOn, UpdatedOn = dataItem.UpdatedOn, AttributeTypeId = dataItem.AttributeTypeId, AttributeId = dataItem.AttributeId, Comment = dataItem.Comment, Source = dataItem.Source, ChildAttributes = isFirstLevel ? dataItem.AttributeLinks1.Select(al => al.Attribute.ToContract(false)).ToList() : new List <Attribute>(), Timeframe = new Timeframe { Months = dataItem.MonthTimeframe != null ? (MonthTimeframe)dataItem.MonthTimeframe : MonthTimeframe.None, Days = dataItem.DayTimeframe != null ? (DayTimeframe)dataItem.DayTimeframe : DayTimeframe.None, Hours = dataItem.HourTimeframe != null ? (HourTimeframe)dataItem.HourTimeframe : HourTimeframe.None } }); }
public static void AddNewChildAttributes(RAAPEntities db, Database.Attribute attribute, Attribute[] childAttributes) { if (childAttributes == null) { return; } var existingAttributeIds = attribute.AttributeLinks1.Select(al => al.AttributeId).ToArray(); var missingAttributes = childAttributes.Where(a => !existingAttributeIds.Contains(a.AttributeId)); foreach (var attributeToAdd in missingAttributes) { var existAsParentLink = db.AttributeLinks.Any(al => al.ParentAttributeId == attributeToAdd.AttributeId || (al.ParentAttributeId == attribute.AttributeId && al.AttributeId == attributeToAdd.AttributeId)); if (existAsParentLink) { return; // dont allow this to prevent recursive links } db.AttributeLinks.Add(new AttributeLink { ParentAttributeId = attribute.AttributeId, AttributeId = attributeToAdd.AttributeId }); } }