public void Delete(int intentId) { var intent = this.FirstOrDefault(q => q.Id == intentId); if (intent != null) { intent.Active = false; PatternService patternService = new PatternService(); var patterns = patternService.Get(q => q.Active == true && q.IntentId == intentId).ToList(); foreach (var pattern in patterns) { pattern.IntentId = null; pattern.Group = -1; } patternService.SaveChanges(); this.SaveChanges(); } }
public void Update(int id, string name, int[] patterns, int[] groups) { try { Intent intent = this.FirstOrDefault(q => q.Id == id); if (intent != null) { intent.Name = name; } this.DbSet.SaveChanges(); PatternService patternService = new PatternService(); List <Pattern> ps = patternService.Get(q => q.IntentId == id).ToList(); foreach (var p in ps) { p.Active = false; p.IntentId = null; } if (patterns != null) { for (var i = 0; i < patterns.Length; ++i) { Pattern pattern = patternService.FirstOrDefault(q => q.Id == patterns[i]); pattern.IntentId = id; pattern.Group = groups[i]; pattern.Active = true; } } patternService.SaveChanges(); } catch (Exception e) { throw e; } }
public Intent Create(string name, int[] patterns, int[] groups) { Intent intent = this.Add(new Intent() { Active = true, Name = name, }); PatternService patternService = new PatternService(); int i = 0; foreach (var patternId in patterns) { var pattern = patternService.FirstOrDefault(q => q.Id == patternId && q.Active == true); pattern.Group = groups[i]; pattern.IntentId = intent.Id; ++i; } patternService.SaveChanges(); this.SaveChanges(); return(intent); }