public MpProductToSave SetProductToSave() { var prToSave = new MpProductToSave { DocumentId = BaseDocument.Id, DbName = BaseDocument.DataBaseName, Length = Length, Diameter = Diameter, Width = Width, Height = Height, SteelDoc = SteelDoc, SteelType = SteelType, Position = Position, Mass = Mass, WMass = WMass, CMass = CMass, SMass = SMass }; if (BaseDocument.Items != null && BaseDocument.Items.Elements("Item").Any()) { prToSave.IndexOfItem = BaseDocument.Items.Elements("Item").ToList().IndexOf(Item); } else { prToSave.IndexOfItem = -1; } if (ItemTypes != null) { var values = ItemTypes.Aggregate( string.Empty, (current, itemType) => current + (itemType.SelectedItem + "$")); prToSave.ItemTypesValues = values.TrimEnd('$'); } else { prToSave.ItemTypesValues = string.Empty; } return(prToSave); }
public static MpProduct GetProductFromSaved(MpProductToSave savedProduct) { var product = new MpProduct { BaseDocument = GetBaseDocumentById(savedProduct.DbName, savedProduct.DocumentId), Length = savedProduct.Length, Diameter = savedProduct.Diameter, Width = savedProduct.Width, Height = savedProduct.Height, SteelType = savedProduct.SteelType, SteelDoc = savedProduct.SteelDoc, Position = savedProduct.Position, Mass = savedProduct.Mass, WMass = savedProduct.WMass, CMass = savedProduct.CMass, SMass = savedProduct.SMass }; // Может быть вариант, что продукт "сделан" из атрибутов, тогда ссылки на базу не будет! И дальнейшие действия не нужны if (product.BaseDocument != null) { product.ItemTypes = product.BaseDocument.ItemTypes; if (savedProduct.IndexOfItem != null) { product.Item = savedProduct.IndexOfItem != -1 ? product.BaseDocument.Items.Elements("Item").ElementAt(savedProduct.IndexOfItem.Value) : null; } if (!string.IsNullOrEmpty(savedProduct.ItemTypesValues)) { var itv = savedProduct.ItemTypesValues.Split('$').ToList(); for (var i = 0; i < itv.Count; i++) { product.ItemTypes[i].SelectedItem = itv[i]; } } } return(product); }