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 void Edit(int id, int productId, string group, string title, string def, string enableLayer, int wordmapId, string strRelations) { VisioMap visiomap = db.VisioMaps.Find(id); bool change = false; JObject objJson = new JObject(); JArray arrVisio = new JArray(); objJson.Add("VisioMap", arrVisio); if (visiomap.ProductId != productId) { JObject obj = new JObject(); obj.Add("Type", "ProductId"); obj.Add("oValue", visiomap.ProductId); obj.Add("nValue", productId); arrVisio.Add(obj); visiomap.ProductId = productId; change = true; } if (visiomap.Group != (group = string.IsNullOrEmpty(group) ? null : group.Trim())) { JObject obj = new JObject(); obj.Add("Type", "Group"); obj.Add("oValue", visiomap.Group); obj.Add("nValue", group); arrVisio.Add(obj); visiomap.Group = group; change = true; } if (visiomap.Title != (title = string.IsNullOrEmpty(title) ? null : title.Trim())) { JObject obj = new JObject(); obj.Add("Type", "Title"); obj.Add("oValue", visiomap.Title); obj.Add("nValue", title); arrVisio.Add(obj); visiomap.Title = title; change = true; } if (visiomap.Default != (def = string.IsNullOrEmpty(def) ? null : def.Trim())) { JObject obj = new JObject(); obj.Add("Type", "Default"); obj.Add("oValue", visiomap.Default); obj.Add("nValue", def); arrVisio.Add(obj); visiomap.Default = def; change = true; } if (visiomap.EnableLayer != (enableLayer = string.IsNullOrEmpty(enableLayer) ? null : enableLayer.Trim())) { JObject obj = new JObject(); obj.Add("Type", "EnableLayer"); obj.Add("oValue", visiomap.EnableLayer); obj.Add("nValue", enableLayer); arrVisio.Add(obj); visiomap.EnableLayer = enableLayer; change = true; } if (visiomap.WordMapId != wordmapId) { JObject obj = new JObject(); obj.Add("Type", "WordMapId"); obj.Add("oValue", visiomap.WordMapId); obj.Add("nValue", wordmapId); arrVisio.Add(obj); visiomap.WordMapId = wordmapId; change = true; } db.Update(visiomap); db.SaveChanges(); if (!string.IsNullOrEmpty(strRelations)) { JObject ob = JObject.Parse(strRelations); JToken arrShape = ob["Shapes"]; JToken arrRelation = ob["Relations"]; #region Relation Layer foreach (JToken strRelation in arrRelation) { string changeVal = (string)strRelation["ChangeVal"]; string method = (string)strRelation["Method"]; string value = (string)strRelation["Value"]; string gaVariant = (string)(strRelation["GAVariant"]); string variantIds = (string)strRelation["VariantIds"]; int? intEquipmentId = (int?)strRelation["IntEquipmentId"]; int? intProductId = string.IsNullOrEmpty((string)strRelation["IntProductId"]) ? null : (int?)strRelation["IntProductId"]; int? reLayerId = string.IsNullOrEmpty((string)strRelation["ReLayerId"]) ? null : (int?)strRelation["ReLayerId"]; string reLayerValue = string.IsNullOrEmpty((string)strRelation["ReLayerValue"]) ? null : (string)strRelation["ReLayerValue"]; if (changeVal == "A") { RelationVisiomap relation = new RelationVisiomap { VisiomapId = visiomap.Id, Method = method, Value = value + (gaVariant == null ? "" : "," + gaVariant), VariantIds = variantIds, IntEquipmentId = intEquipmentId, IntProductId = intProductId, ReLayerId = reLayerId, ReLayerValue = reLayerValue }; db.Add(relation); } else if (changeVal == "D") { int?relationId = (int?)strRelation["RelationId"]; RelationVisiomap relation = db.RelationVisiomaps.Find(relationId); db.Remove(relation); } else { int?relationId = (int?)strRelation["RelationId"]; RelationVisiomap relation = db.RelationVisiomaps.Find(relationId); if (relation.Method != (method = string.IsNullOrEmpty(method) ? null : method.Trim())) { relation.Method = method; } if (relation.Value != (value = string.IsNullOrEmpty(value) ? null : value.Trim())) { relation.Value = value; } if (relation.VariantIds != (variantIds = string.IsNullOrEmpty(variantIds) ? null : variantIds.Trim())) { relation.VariantIds = variantIds; } if (relation.IntEquipmentId != intEquipmentId) { relation.IntEquipmentId = intEquipmentId; } if (relation.IntProductId != intProductId) { relation.IntProductId = intProductId; } if (relation.ReLayerId != reLayerId) { relation.ReLayerId = reLayerId; } if (relation.ReLayerValue != (reLayerValue = string.IsNullOrEmpty(reLayerValue) ? null : reLayerValue.Trim())) { relation.ReLayerValue = reLayerValue; } db.Update(relation); } } #endregion #region Shape, Relation Shape JArray arrSha = new JArray(); objJson.Add("Shape", arrSha); foreach (JToken strShape in arrShape) { int? shapeId = string.IsNullOrEmpty((string)strShape["Id"]) ? null : (int?)strShape["Id"]; string changeVal = (string)strShape["ChangeVal"]; string type = (string)strShape["Type"]; string name = (string)strShape["Name"]; string text = (string)strShape["Text"]; JToken arrReShape = strShape["ReShapes"]; Shape shape = changeVal == "A" ? new Shape() : db.Shapes.Find(shapeId); if (changeVal == "D") { // 지워야 하는 shape가 포함된 diagram 삭제 IEnumerable <Diagram> diagrams = db.Diagrams.Where(e => e.ShapeId == shape.Id); foreach (Diagram diagram in diagrams.Reverse()) { db.Remove(diagram); } JObject obj = new JObject(); obj.Add("Action", "Delete"); obj.Add("Id", shape.Id); obj.Add("Name", shape.Name); arrSha.Add(obj); db.Remove(shape); } else if (changeVal == "A") { shape.VisioMapId = visiomap.Id; shape.Type = string.IsNullOrEmpty(type) ? null : type.Trim(); shape.Name = string.IsNullOrEmpty(name) ? null : name.Trim(); shape.Text = string.IsNullOrEmpty(text) ? null : text.Trim(); shape.Date = DateTime.Now; shape.User = User.Identity.Name; db.Add(shape); } else { if (shape.Type != (type = string.IsNullOrEmpty(type) ? null : type.Trim())) { JObject obj = new JObject(); obj.Add("Type", "Type"); obj.Add("oValue", shape.Type); obj.Add("nValue", type); arrVisio.Add(obj); shape.Type = type; change = true; } if (shape.Name != (name = string.IsNullOrEmpty(name) ? null : name.Trim())) { JObject obj = new JObject(); obj.Add("Type", "Name"); obj.Add("oValue", shape.Name); obj.Add("nValue", name); arrVisio.Add(obj); shape.Name = name; change = true; } if (shape.Text != (text = string.IsNullOrEmpty(text) ? null : text.Trim())) { JObject obj = new JObject(); obj.Add("Type", "Text"); obj.Add("oValue", shape.Text); obj.Add("nValue", text); arrVisio.Add(obj); shape.Text = text; change = true; } db.Update(shape); } foreach (JToken strReShape in arrReShape) { string reChangeVal = (string)strReShape["ChangeVal"]; int reId = (int)strReShape["Id"]; int? reProductId = (int?)strReShape["ProductId"]; int? reLayerId = (int?)strReShape["LayerId"]; int? reShapeId = (int?)strReShape["ShapeId"]; string reMethod = (string)strReShape["Method"]; string reVal = (string)strReShape["Value"]; RelationShape reShape = reChangeVal == "A" ? new RelationShape() : db.RelationShapes.Find(reId); if (reChangeVal == "D") { db.Remove(reShape); } else if (reChangeVal == "A") { reShape.ShapeId = shape.Id; reShape.ReShapeId = reShapeId; reShape.Method = string.IsNullOrEmpty(reMethod) ? null : reMethod.Trim(); reShape.Value = string.IsNullOrEmpty(reVal) ? null : reVal.Trim(); db.Add(reShape); } else { if (reShape.ShapeId != shapeId) { reShape.ShapeId = shapeId; } if (reShape.ReShapeId != reShapeId) { reShape.ReShapeId = reShapeId; } if (reShape.Method != (reMethod = string.IsNullOrEmpty(reMethod) ? null : reMethod.Trim())) { reShape.Method = reMethod; } if (reShape.Value != (reVal = string.IsNullOrEmpty(reVal) ? null : reVal.Trim())) { reShape.Value = reVal; } db.Update(reShape); } } } #endregion } if (change) { Log log = new Log { ActionType = "Edit", DataType = "VisioMap", RefId = visiomap.Id, Date = DateTime.Now, User = User.Identity.Name, ChangeData = objJson.ToString() }; db.Add(log); } db.SaveChanges(); }
public void Create(VisioMap visiomap, string strRelations, string strShapes) { visiomap.Group = string.IsNullOrEmpty(visiomap.Group) ? null : visiomap.Group.Trim(); visiomap.Title = string.IsNullOrEmpty(visiomap.Title) ? null : visiomap.Title.Trim(); visiomap.Default = string.IsNullOrEmpty(visiomap.Default) || visiomap.Group != "INTERFACE" ? null : visiomap.Default.Trim(); visiomap.EnableLayer = string.IsNullOrEmpty(visiomap.EnableLayer) ? null : visiomap.EnableLayer.Trim(); visiomap.Date = DateTime.Now; visiomap.User = User.Identity.Name; db.Add(visiomap); #region Shapes if (!string.IsNullOrEmpty(strShapes)) { foreach (string strShape in JArray.Parse(strShapes)) { string[] arrVal = strShape.Split(','); string type = arrVal[0]; string name = arrVal[1]; string text = arrVal[2]; string reShape = arrVal[3]; Shape shape = new Shape { VisioMapId = visiomap.Id, Type = string.IsNullOrEmpty(type) ? null : type, Name = string.IsNullOrEmpty(name) ? null : name, Text = string.IsNullOrEmpty(text) ? null : text, Date = DateTime.Now, User = User.Identity.Name }; visiomap.Shapes.Add(shape); db.SaveChanges(); if (!string.IsNullOrEmpty(reShape)) { RelationShape newReShape = new RelationShape { ShapeId = shape.Id, ReShapeId = int.Parse(reShape) }; shape.RelationShapes.Add(newReShape); } } db.SaveChanges(); } #endregion #region Relation if (!string.IsNullOrEmpty(strRelations)) { foreach (var strRelation in JArray.Parse(strRelations)) { string method = (string)strRelation["Method"]; string value = (string)strRelation["Value"]; string variantIds = (string)strRelation["VariantIds"]; int? intEquipmentId = (int?)strRelation["IntEquipmentId"]; int? intProductId = (int?)strRelation["IntProductId"]; int? reLayerId = (int?)strRelation["ReLayerId"]; string reLayerValue = (string)strRelation["ReLayerValue"]; RelationVisiomap relation = new RelationVisiomap { VisiomapId = visiomap.Id, Method = string.IsNullOrEmpty(method) ? null : method.Trim(), Value = string.IsNullOrEmpty(value) ? null : value.Trim(), VariantIds = string.IsNullOrEmpty(variantIds) ? null : value.Trim(), IntEquipmentId = intEquipmentId, IntProductId = intProductId, ReLayerId = reLayerId, ReLayerValue = string.IsNullOrEmpty(reLayerValue) ? null : reLayerValue.Trim() }; db.RelationVisiomaps.Add(relation); } db.SaveChanges(); } #endregion }