public async void CopyVisiomaps(string json) { foreach (int visioId in JArray.Parse(json)) { VisioMap oVisiomap = await db.VisioMaps .Include(e => e.Shapes) .ThenInclude(e => e.RelationShapes) .Include(e => e.Relations) .FirstOrDefaultAsync(e => e.Id == visioId); VisioMap nVisiomap = new VisioMap(); nVisiomap = (VisioMap)db.Entry(oVisiomap).GetDatabaseValues().ToObject(); nVisiomap.Date = DateTime.Now; nVisiomap.User = User.Identity.Name; db.Add(nVisiomap); db.SaveChanges(); foreach (Shape oShape in oVisiomap.Shapes) { Shape newShape = new Shape(); newShape = (Shape)db.Entry(oShape).GetDatabaseValues().ToObject(); newShape.Date = DateTime.Now; newShape.User = User.Identity.Name; nVisiomap.Shapes.Add(newShape); foreach (RelationShape oReShape in oShape.RelationShapes) { RelationShape newReShape = new RelationShape(); newReShape = (RelationShape)db.Entry(oReShape).GetDatabaseValues().ToObject(); newShape.RelationShapes.Add(newReShape); } } db.SaveChanges(); // Relation foreach (RelationVisiomap oReVisio in oVisiomap.Relations) { RelationVisiomap newReVisio = new RelationVisiomap(); newReVisio = (RelationVisiomap)db.Entry(oReVisio).GetDatabaseValues().ToObject(); nVisiomap.Relations.Add(newReVisio); } db.SaveChanges(); } }
public string EditEntity(Entity entity) { db.Entry(entity).State = EntityState.Modified; db.SaveChanges(); return("Success"); }
public void Clone(int?id) { WordMap oWordmap = db.WordMaps.Find(id); WordMap nWordmap = new WordMap(); nWordmap = (WordMap)db.Entry(oWordmap).GetDatabaseValues().ToObject(); nWordmap.Date = DateTime.Now; nWordmap.User = User.Identity.Name; db.Add(nWordmap); db.SaveChanges(); }
// Copy public async void CopyProducts(string json) { foreach (int productId in JArray.Parse(json)) { // Product Product oProduct = await db.Products .Include(e => e.Children) .FirstOrDefaultAsync(e => e.Id == productId); Product nProduct = new Product(); nProduct = (Product)db.Entry(oProduct).GetDatabaseValues().ToObject(); db.Add(nProduct); db.SaveChanges(); JObject obProduct = new JObject(); obProduct.Add("Model", nProduct.Model); obProduct.Add("Title", nProduct.Title); obProduct.Add("Completion", nProduct.Completion); obProduct.Add("EquipmentId", nProduct.EquipmentId); obProduct.Add("Mass", nProduct.Mass); obProduct.Add("componentIdx", nProduct.ComponentIdx); obProduct.Add("State", nProduct.State); obProduct.Add("Group", nProduct.Group); obProduct.Add("TableCol", nProduct.TableCol); Log log = new Log { RefId = nProduct.Id, DataType = "Product", Date = DateTime.Now, User = User.Identity.Name, ChangeData = obProduct.ToString(), ActionType = "CopyProduct" }; db.Add(log); db.SaveChanges(); // Variants foreach (Variant oVariant in oProduct.Children) { Variant nVariant = new Variant(); nVariant = (Variant)db.Entry(oVariant).GetDatabaseValues().ToObject(); nProduct.Children.Add(nVariant); db.SaveChanges(); JObject obVariant = new JObject(); obVariant.Add("ComponentName", nVariant.ComponentName); obVariant.Add("ProductId", nVariant.ProductId); obVariant.Add("Default", nVariant.Default); obVariant.Add("Priority", nVariant.Priority); obVariant.Add("Remark", nVariant.Remark); obVariant.Add("Quantity", nVariant.Quantity); obVariant.Add("Unit", nVariant.Unit); obVariant.Add("Mass", nVariant.Mass); obVariant.Add("ParentId", nVariant.ParentId); obVariant.Add("VariantGroup", nVariant.VariantGroup); Log logVariant = new Log { RefId = nVariant.Id, DataType = "Variant", Date = DateTime.Now, User = User.Identity.Name, ChangeData = obVariant.ToString(), ActionType = "CopyProduct" }; db.Add(logVariant); db.SaveChanges(); } } }
// Edit public void Edit(int id, string group, string name, string formalName, string desc) { JArray arrEquip = new JArray(); Equipment equipment = db.Equipments.Find(id); bool change = false; if (equipment.Group != (string.IsNullOrEmpty(group) ? null : group.Trim())) { JObject obj = new JObject(); obj.Add("Type", "Group"); obj.Add("oValue", equipment.Group); obj.Add("nValue", group); arrEquip.Add(obj); equipment.Group = group; change = true; } if (equipment.Name != (string.IsNullOrEmpty(name) ? null : name.Trim())) { JObject obj = new JObject(); obj.Add("Type", "Name"); obj.Add("oValue", equipment.Name); obj.Add("nValue", name); arrEquip.Add(obj); equipment.Name = name; change = true; } if (equipment.FormalName != (string.IsNullOrEmpty(formalName) ? null : formalName.Trim())) { JObject obj = new JObject(); obj.Add("Type", "FormalName"); obj.Add("oValue", equipment.FormalName); obj.Add("nValue", formalName); arrEquip.Add(obj); equipment.FormalName = formalName; change = true; } if (equipment.Desc != (string.IsNullOrEmpty(desc) ? null : desc.Trim())) { JObject obj = new JObject(); obj.Add("Type", "Desc"); obj.Add("oValue", equipment.Desc); obj.Add("nValue", desc); arrEquip.Add(obj); equipment.Desc = desc; change = true; } if (change) { Log log = new Log { ActionType = "P.Equipment", RefId = equipment.Id, Date = DateTime.Now, User = User.Identity.Name, ChangeData = arrEquip.ToString() }; db.Add(log); db.Entry(equipment).State = EntityState.Modified; db.SaveChanges(); } }