private void CreateNewSpecialFields() { var objs = _db.EST_Item_Specification.Where(x => x.EstItemID == _originalItem.EstItemID).ToList(); foreach (var obj in objs) { var newObj = new EST_Item_Specification(); MyReflection.Copy(obj, newObj); newObj.EstItemSpecificationID = 0; newObj.EstItemID = NewEstItem.EstItemID; _db.EST_Item_Specification.Add(newObj); } _db.SaveChanges(); }
private void CreateNewSpecialFields() { //Supposed to Have Fields var configuedFields = _db.EST_Item_Specification_Template.Where(x => x.ProductID == _product.ProductID) .OrderBy(x => x.OrderNumber) .ToList(); if (!configuedFields.Any()) { //Disble Template var newValue = _db.EST_Item.Find(_estItemID); newValue.IsTemplateApplicable = false; _db.Entry(newValue).State = EntityState.Modified; _db.SaveChanges(); return; } try { foreach (var field in configuedFields) { var item = new EST_Item_Specification() { EstItemID = _estItemID, OrderNumber = field.OrderNumber, Title = field.Title, OptionGroupID = field.OptionGroupID, Contents = GetDefaultSpecialContents(field.DefaultValue), IsMandatory = field.IsMandatory, }; _db.EST_Item_Specification.Add(item); } _db.SaveChanges(); } catch (DbEntityValidationException dbEx) { var s = dbEx.Message; throw; } }