public string EditEntity(Entity entity) { db.Entry(entity).State = EntityState.Modified; db.SaveChanges(); return("Success"); }
// Create public string Create(Equipment equipment) { if (string.IsNullOrEmpty(equipment.Group) || string.IsNullOrEmpty(equipment.Name) || string.IsNullOrEmpty(equipment.FormalName)) { return("빈 항목이 있습니다."); } equipment.Name = equipment.Name.Trim(); equipment.FormalName = equipment.FormalName.Trim(); equipment.Group = equipment.Group.Trim(); equipment.Date = DateTime.Now; equipment.User = User.Identity.Name; db.Equipments.Add(equipment); db.SaveChanges(); return("Success"); }
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 }
public void CreateProduct(Product product) { db.Add(product); JObject obProduct = new JObject(); obProduct.Add("Model", product.Model); obProduct.Add("Title", product.Title); obProduct.Add("Completion", product.Completion); obProduct.Add("EquipmentId", product.EquipmentId); obProduct.Add("Mass", product.Mass); obProduct.Add("componentIdx", product.ComponentIdx); obProduct.Add("State", product.State); obProduct.Add("Group", product.Group); obProduct.Add("TableCol", product.TableCol); Log log = new Log { RefId = product.Id, DataType = "Product", Date = DateTime.Now, User = User.Identity.Name, ChangeData = obProduct.ToString(), ActionType = "CreateProduct" }; 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); }