private static void AddConcept(XmlFile documentDB, XElement item, CompAgriConnection ctx) { Term currentTerm = null; foreach (XElement child in item.Descendants()) { if (child.Name == "DESCRIPTOR") { currentTerm = AddTerm(child, documentDB, ctx); } else if (child.Name == "BT") { AddParentRelationToTerm(currentTerm, child, documentDB, ctx); } else if (child.Name == "NT") { AddChildRelationToTerm(currentTerm, child, documentDB, ctx); } else { AddPropertyToTerm(ctx, currentTerm, child); } } ctx.SaveChanges(); }
internal static int AddNode(int xmlFileId, String name, int parentId) { try { using (CompAgriConnection ctx = new CompAgriConnection()) { var newTerm = new Term() { Term_XmlFile_Id = xmlFileId, Term_Title = name }; newTerm.Relation1.Add(new Relation { Relation_Parent_Term_Id = parentId, Relation_Child_Term_Id = newTerm.Term_Id }); ctx.Terms.Add(newTerm); ctx.SaveChanges(); return(newTerm.Term_Id); } } catch (Exception) { // Do Nothing ! } return(-1); }
internal static void MoveNode(int nodeId, int? oldParentId, int? newParentId) { using (CompAgriConnection ctx = new CompAgriConnection()) { var relation = ctx.Relations.Where(o => o.Relation_Parent_Term_Id == oldParentId && o.Relation_Child_Term_Id == nodeId) .FirstOrDefault(); if (relation != null) { relation.Relation_Parent_Term_Id = newParentId; } else { relation = new Relation { Relation_Child_Term_Id = nodeId, Relation_Parent_Term_Id = newParentId }; ctx.Relations.Add(relation); } ctx.SaveChanges(); } }
internal static void MoveNode(int nodeId, int?oldParentId, int?newParentId) { using (CompAgriConnection ctx = new CompAgriConnection()) { var relation = ctx.Relations.Where(o => o.Relation_Parent_Term_Id == oldParentId && o.Relation_Child_Term_Id == nodeId) .FirstOrDefault(); if (relation != null) { relation.Relation_Parent_Term_Id = newParentId; } else { relation = new Relation { Relation_Child_Term_Id = nodeId, Relation_Parent_Term_Id = newParentId }; ctx.Relations.Add(relation); } ctx.SaveChanges(); } }
public void Delete(int id) { using (var db = new CompAgriConnection()) { var user = db.User.FirstOrDefault(u => u.User_Id == id); db.User.Remove(user); db.SaveChanges(); } }
internal static void DeleteNode(int nodeId, int parentId) { using (CompAgriConnection ctx = new CompAgriConnection()) { var relationToDelete = ctx.Relations.Where(o => o.Relation_Parent_Term_Id == parentId && o.Relation_Child_Term_Id == nodeId) .FirstOrDefault(); if (relationToDelete != null) { ctx.Relations.Remove(relationToDelete); ctx.SaveChanges(); } } }
internal static void DeleteNode(int nodeId, int parentId) { using (CompAgriConnection ctx = new CompAgriConnection()) { var relationToDelete = ctx.Relations.Where(o => o.Relation_Parent_Term_Id == parentId && o.Relation_Child_Term_Id == nodeId) .FirstOrDefault(); if (relationToDelete != null) { ctx.Relations.Remove(relationToDelete); ctx.SaveChanges(); } } }
private static Term AddTerm(XElement description, XmlFile documentDB, CompAgriConnection ctx) { Term currentTerm = documentDB.Term.FirstOrDefault(d => d.Term_Title == description.Value); if (currentTerm == null) { currentTerm = new Term(); currentTerm.Term_Title = description.Value; currentTerm.Term_XmlFile_Id = documentDB.XmlFile_Id; ctx.Terms.Add(currentTerm); ctx.SaveChanges(); } return(currentTerm); }
internal static void UploadFile(string filePath) { using (CompAgriConnection ctx = new CompAgriConnection()) { ctx.Configuration.AutoDetectChangesEnabled = false; string path = filePath; string fileName = filePath.Substring(filePath.LastIndexOf('\\') + 1); XDocument docX = XDocument.Load(path); XmlFile documentDB = new XmlFile(); ctx.XmlFiles.Add(documentDB); documentDB.XmlFile_Name = fileName; ctx.SaveChanges(); IEnumerable <XElement> concept = docX.Descendants("CONCEPT"); foreach (XElement item in concept) { AddConcept(documentDB, item, ctx); } ctx.SaveChanges(); } }
internal static void MoveNode(int nodeId, int oldParentId, int newParentId) { try { using (CompAgriConnection ctx = new CompAgriConnection()) { var relation = ctx.Relations.Where(o => o.Relation_Parent_Term_Id == oldParentId && o.Relation_Child_Term_Id == nodeId) .FirstOrDefault(); if (relation != null) { relation.Relation_Parent_Term_Id = newParentId; ctx.SaveChanges(); } } } catch (Exception) { throw; } }
public void Delete() { string token = UserUtils.GetUserToken(Request); if (token == null) { return; } using (var db = new CompAgriConnection()) { var user = db.User.FirstOrDefault(u => u.Token == token); if (user == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } user.Token = null; db.SaveChanges(); } }
private static void AddParentRelationToTerm(Term currentTerm, XElement parentInfo, XmlFile documentDB, CompAgriConnection ctx) { Term parentTerm = null; parentTerm = documentDB.Term.FirstOrDefault(d => d.Term_Title == parentInfo.Value); if (parentTerm == null) { parentTerm = new Term(); parentTerm.Term_Title = parentInfo.Value; parentTerm.Term_XmlFile_Id = documentDB.XmlFile_Id; ctx.Terms.Add(parentTerm); ctx.SaveChanges(); } Relation relation = new Relation() { Term = parentTerm, Term1 = currentTerm }; ctx.Relations.Add(relation); }
private static void AddChildRelationToTerm(Term currentTerm, XElement child, XmlFile documentDB, CompAgriConnection ctx) { Term childTerm = null; childTerm = documentDB.Term.FirstOrDefault(d => d.Term_Title == child.Value); if (childTerm == null) { childTerm = new Term(); childTerm.Term_Title = child.Value; childTerm.Term_XmlFile_Id = documentDB.XmlFile_Id; ctx.Terms.Add(childTerm); ctx.SaveChanges(); } Relation relation = new Relation() { Term = currentTerm, Term1 = childTerm }; ctx.Relations.Add(relation); }
public UserDto Post([FromBody] UserDto userDto) { if (!userDto.IsValid()) { throw new HttpResponseException(HttpStatusCode.BadRequest); } using (var db = new CompAgriConnection()) { var previousUser = db.User.FirstOrDefault(u => (u.UserName != null && u.UserName == userDto.UserName) || (u.Email != null && u.Email == userDto.Email)); if (previousUser != null) { throw WebExceptionsFactory.GetUserDuplicatedException(); } var userBeforeSave = userDto.User(); userBeforeSave.PasswordSalt = PasswordUtils.GenerateSalt(); userBeforeSave.Password = PasswordUtils.HashPassword(userBeforeSave.Password, userBeforeSave.PasswordSalt); var user = db.User.Add(userBeforeSave); db.SaveChanges(); return new UserDto(user); } }
internal static void UploadFile(string filePath) { using (CompAgriConnection ctx = new CompAgriConnection()) { ctx.Configuration.AutoDetectChangesEnabled = false; string path = filePath; string fileName = filePath.Substring(filePath.LastIndexOf('\\') + 1); XDocument docX = XDocument.Load(path); XmlFile documentDB = new XmlFile(); ctx.XmlFiles.Add(documentDB); documentDB.XmlFile_Name = fileName; ctx.SaveChanges(); IEnumerable<XElement> concept = docX.Descendants("CONCEPT"); foreach (XElement item in concept) { AddConcept(documentDB, item, ctx); } ctx.SaveChanges(); } }
public UserDto Post(UserDto user) { User userFromDatabase; using (var db = new CompAgriConnection()) { if (user.Email != null) { userFromDatabase = db.User.FirstOrDefault(u => u.Email == user.Email); } else if (user.UserName != null) { userFromDatabase = db.User.FirstOrDefault(u => u.UserName == user.UserName); } else { throw new HttpResponseException(HttpStatusCode.BadRequest); } if (userFromDatabase == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } var hashedPassword = PasswordUtils.HashPassword(user.Password, userFromDatabase.PasswordSalt); if (hashedPassword != userFromDatabase.Password) { throw new HttpResponseException(HttpStatusCode.Forbidden); } else { userFromDatabase.Token = TokenUtils.GenerateToken(); db.SaveChanges(); var userToSend = new UserDto(userFromDatabase, true); return userToSend; } } }
private static void AddParentRelationToTerm(Term currentTerm, XElement parentInfo, XmlFile documentDB, CompAgriConnection ctx) { Term parentTerm = null; parentTerm = documentDB.Term.FirstOrDefault(d => d.Term_Title == parentInfo.Value); if (parentTerm == null) { parentTerm = new Term(); parentTerm.Term_Title = parentInfo.Value; parentTerm.Term_XmlFile_Id = documentDB.XmlFile_Id; ctx.Terms.Add(parentTerm); ctx.SaveChanges(); } Relation relation = new Relation() { Term = parentTerm, Term1 = currentTerm }; ctx.Relations.Add(relation); }
private static void AddConcept(XmlFile documentDB, XElement item, CompAgriConnection ctx) { Term currentTerm = null; foreach (XElement child in item.Descendants()) { if (child.Name == "DESCRIPTOR") { currentTerm = AddTerm(child, documentDB, ctx); } else if (child.Name == "BT") { AddParentRelationToTerm(currentTerm, child, documentDB, ctx); } else if (child.Name == "NT") { AddChildRelationToTerm(currentTerm, child, documentDB, ctx); } else { AddPropertyToTerm(ctx, currentTerm, child); } } ctx.SaveChanges(); }
private static void AddChildRelationToTerm(Term currentTerm, XElement child, XmlFile documentDB, CompAgriConnection ctx) { Term childTerm = null; childTerm = documentDB.Term.FirstOrDefault(d => d.Term_Title == child.Value); if (childTerm == null) { childTerm = new Term(); childTerm.Term_Title = child.Value; childTerm.Term_XmlFile_Id = documentDB.XmlFile_Id; ctx.Terms.Add(childTerm); ctx.SaveChanges(); } Relation relation = new Relation() { Term = currentTerm, Term1 = childTerm }; ctx.Relations.Add(relation); }
private static Term AddTerm(XElement description, XmlFile documentDB, CompAgriConnection ctx) { Term currentTerm = documentDB.Term.FirstOrDefault(d => d.Term_Title == description.Value); if (currentTerm == null) { currentTerm = new Term(); currentTerm.Term_Title = description.Value; currentTerm.Term_XmlFile_Id = documentDB.XmlFile_Id; ctx.Terms.Add(currentTerm); ctx.SaveChanges(); } return currentTerm; }
internal static void UploadFile(string filePath) { try { using (CompAgriConnection ctx = new CompAgriConnection()) { ctx.Configuration.AutoDetectChangesEnabled = false; var path = ""; path = filePath; string fileName = filePath.Substring(filePath.LastIndexOf('\\') + 1); XDocument docX = XDocument.Load(path); try { XmlFile documentDB = new XmlFile(); ctx.XmlFiles.Add(documentDB); documentDB.XmlFile_Name = fileName; ctx.SaveChanges(); IEnumerable <XElement> concept = docX.Descendants("CONCEPT"); int countConcept = 0; foreach (XElement item in concept) { Term currentTerm = null; foreach (XElement child in item.Descendants()) { if (child.Name == "DESCRIPTOR") { currentTerm = documentDB.Term.FirstOrDefault(d => d.Term_Title == child.Value); if (currentTerm == null) { currentTerm = new Term(); currentTerm.Term_Title = child.Value; currentTerm.Term_XmlFile_Id = documentDB.XmlFile_Id; ctx.Terms.Add(currentTerm); ctx.SaveChanges(); } } else if (child.Name == "BT") { Term parentTerm = null; parentTerm = documentDB.Term.FirstOrDefault(d => d.Term_Title == child.Value); if (parentTerm == null) { parentTerm = new Term(); parentTerm.Term_Title = child.Value; parentTerm.Term_XmlFile_Id = documentDB.XmlFile_Id; ctx.Terms.Add(parentTerm); ctx.SaveChanges(); } Relation relation = new Relation() { Term = parentTerm, Term1 = currentTerm }; ctx.Relations.Add(relation); } else if (child.Name == "NT") { Term childTerm = null; childTerm = documentDB.Term.FirstOrDefault(d => d.Term_Title == child.Value); if (childTerm == null) { childTerm = new Term(); childTerm.Term_Title = child.Value; childTerm.Term_XmlFile_Id = documentDB.XmlFile_Id; ctx.Terms.Add(childTerm); ctx.SaveChanges(); } Relation relation = new Relation() { Term = currentTerm, Term1 = childTerm }; ctx.Relations.Add(relation); } else { Property newProperty = new Property() { Property_Key = child.Name.LocalName, Property_Value = child.Value, Property_Term_Id = currentTerm.Term_Id }; currentTerm.Property.Add(newProperty); ctx.Properties.Add(newProperty); } } countConcept++; if (countConcept % 1 == 0) { ctx.SaveChanges(); } } // End of For Each !!! ctx.SaveChanges(); } catch (Exception e) { String str = e.ToString(); String str2 = e.Message; throw e; } } } catch (Exception e) { String str = e.ToString(); String str2 = e.Message; throw e; } }