// Delete public async Task <string> DeleteProduct(string json) { JArray arrItems = JArray.Parse(json); foreach (int id in arrItems) { Product product = await db.Products .Include(e => e.WordMaps) .Include(e => e.Children) .Include(e => e.VisioMaps) .ThenInclude(e => e.Shapes) .ThenInclude(e => e.RelationShapes) .Include(e => e.VisioMaps) .ThenInclude(e => e.Relations) .FirstOrDefaultAsync(e => e.Id == id); if (product.Completion == "GOODS") { foreach (VisioMap visiomap in product.VisioMaps.Reverse()) { foreach (Shape shape in visiomap.Shapes.Reverse()) { foreach (RelationShape reShape in shape.RelationShapes.Reverse()) { db.Remove(reShape); } db.Remove(shape); } foreach (RelationVisiomap reVisiomap in visiomap.Relations.Reverse()) { db.Remove(reVisiomap); } db.Remove(visiomap); } foreach (var wdmap in product.WordMaps.Reverse()) { db.Remove(wdmap); } foreach (Variant variant in product.Children.Reverse()) { db.Remove(variant); } } else { IEnumerable <Variant> variants = db.Variants.Where(e => e.ProductId == product.Id); foreach (Variant variant in variants.Reverse()) { var reVisios = db.RelationVisiomaps.Where(e => e.VariantIds.Contains(variant.Id.ToString())); foreach (RelationVisiomap reVisio in reVisios.Reverse()) { if (reVisio.VariantIds.Contains(',')) { string[] oIds = reVisio.VariantIds.Split(','); string nIds = null; for (int i = 0; i < oIds.Length; i++) { if (oIds[i] != variant.Id.ToString()) { if (i == 0) { nIds = oIds[i]; } else { nIds += "," + oIds[i]; } } } reVisio.VariantIds = nIds; db.Update(reVisio); } else { //VisioMap visiomap = reVisio.VisioMap; VisioMap visiomap = await db.VisioMaps .Include(e => e.Shapes) .Include(e => e.Relations) .FirstOrDefaultAsync(e => e.Id == reVisio.VisiomapId); foreach (Diagram diagram in db.Diagrams.Where(e => e.VisioMapId == visiomap.Id).Reverse()) { db.Remove(diagram); } foreach (Shape shape in visiomap.Shapes.Reverse()) { db.Remove(shape); } db.Remove(reVisio); if (visiomap.Relations.Count() == 0) { db.Remove(visiomap); } } } db.Remove(variant); } } db.SaveChanges(); Log log = new Log { RefId = id, DataType = "Product", Date = DateTime.Now, User = User.Identity.Name, ActionType = "DeleteProduct" }; db.Add(log); // Product 삭제 db.Remove(product); db.SaveChanges(); } return("Success"); }
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 async Task <JArray> LoadWordMaps(string filter, string category) { if (!string.IsNullOrEmpty(category)) { if (category.ToUpper() == "ALL" || category.ToUpper() == "CATEGORY") { category = ""; } else if (category.ToUpper() == "BOOKMARKS") { category = "DELETE"; } else if (category.ToUpper() == "CONTENTCONTROL") { category = "UPDATE"; } } IEnumerable <WordMap> wordmaps = db.WordMaps .Include(e => e.Product) .AsNoTracking() .Where(e => e.ElementType.Contains(category ?? "") && (e.Product.Model.Contains(filter ?? "") || e.ElementName.Contains(filter ?? ""))) .OrderBy(e => e.Id); if (string.IsNullOrEmpty(filter)) { int x = wordmaps.Count() - 100; if (x > 0) { wordmaps = wordmaps.Skip(x); } } JArray arrWordMaps = new JArray(); foreach (var wordMap in wordmaps) { JObject item = new JObject(); item.Add("WordMapId", wordMap.Id); item.Add("ProductId", wordMap.ProductId); item.Add("ProductNumber", wordMap.Product.Model); item.Add("ElementName", wordMap.ElementName); item.Add("ElementType", wordMap.ElementType); if (!string.IsNullOrEmpty(wordMap.VariantIds)) { List <string> arrVariantIds = wordMap.VariantIds.Split(',').ToList(); string strVariant = null; bool check = false; for (int i = arrVariantIds.Count - 1; i >= 0; i--) { int variantId = int.Parse(arrVariantIds[i]); Variant variant = await db.Variants .Include(e => e.Product) .FirstOrDefaultAsync(e => e.Id == variantId); if (variant == null) { arrVariantIds.RemoveAt(i); check = true; } else { strVariant += strVariant == null ? variant.Product.Model : "," + variant.Product.Model; } } if (check) { wordMap.VariantIds = string.Join(",", arrVariantIds); db.Update(wordmaps); } } arrWordMaps.Add(item); } db.SaveChanges(); return(arrWordMaps); }