// GET: Classifier/Edit/5 public ActionResult Edit(int id) { using (var db = new ChatLogDataContext()) { // Get the item var item = db.ClassifiedMessages.SingleOrDefault(m => m.MessageId == id); if (item != null) { var log = db.LogMessages.Single(m => m.Id == item.MessageId); return(View("Classify", new ClassifyViewModel() { Categories = db.Categories.ToList(), Selectors = CategorySelector.GetCategorySelectors(db.Categories.ToList()), IsEditMode = true, CategoryId = item.CategoryId.GetValueOrDefault(), MessageId = item.MessageId, SecondCategoryId = item.SecondCategoryId.GetValueOrDefault(), RelatedMessages = db.LogMessages.Where(m => m.SessionFileName == log.SessionFileName).OrderBy(m => m.Id).ToList(), Message = log.Message, Mode = ClassificationMode.Edit, SelectedCategories = item.SelectedCategories == null ? item.CategoryId.Value.ToString("N0") : item.SelectedCategories })); } return(View("Classify")); } }
private ClassifyViewModel GetNextUnclassifiedItem(ClassificationMode mode, ChatLogDataContext db, int currentId) { var firstitem = db.LogMessages.OrderBy(m => m.Id).FirstOrDefault(m => m.Status == (short)mode); try { if (firstitem != null) { var newitem = db.LogMessages.OrderBy(m => m.Id).FirstOrDefault(m => m.Status == (short)mode && m.Id > currentId); if (newitem != null) { firstitem = newitem; } } if (firstitem == null) { firstitem = new LogMessage() { Id = 0, Message = string.Empty }; } // Get related messages var related = db.LogMessages.Where(m => m.SessionFileName == firstitem.SessionFileName).OrderBy(m => m.Id).ToList(); return(new ClassifyViewModel() { MessageId = firstitem.Id, Mode = mode, Message = firstitem.Message, Categories = db.Categories.ToList(), RelatedMessages = related, Selectors = CategorySelector.GetCategorySelectors(db.Categories.ToList()), SelectedCategories = string.Empty }); } finally { firstitem = null; } }