public ActionResult Create(FormCollection collection) { try { // TODO: Add insert logic here using (var db = new ChatLogDataContext()) { // Check if the same name exists var exists = db.Categories.Any(c => c.CategoryName == collection["categoryname"].Trim()); if (!exists) { db.Categories.InsertOnSubmit(new Category() { CategoryName = collection["categoryname"], ModifiedDate = DateTime.Now }); db.SubmitChanges(); } return(RedirectToAction("Index")); } } catch { return(View()); } }
private bool Classify(ChatLogDataContext db, int MessageID, int CategoryID, ClassificationMode Mode, bool isSecond = false) { try { // Save or update to the classified var mitem = db.LogMessages.SingleOrDefault(l => l.Id == MessageID); var citem = db.Categories.SingleOrDefault(c => c.Id == CategoryID); if (mitem != null && citem != null) { // Check if the item exists var cl = db.ClassifiedMessages.SingleOrDefault(c => c.MessageId == MessageID); if (cl != null) { // Already exists -- set to the new category if (isSecond) { cl.SecondCategoryId = CategoryID; } else { cl.CategoryId = CategoryID; } cl.DateModified = DateTime.Now; } else { // Add a new one db.ClassifiedMessages.InsertOnSubmit(new ClassifiedMessage { CategoryId = citem.Id, MessageId = mitem.Id, DateModified = DateTime.Now }); } //Update the message status mitem.Status = (short)MessageStatus.Done; mitem.DateModified = DateTime.Now; db.SubmitChanges(); } return(true); } catch { return(false); } }
// GET: Category/Delete/5 public ActionResult Delete(int id) { using (var db = new ChatLogDataContext()) { // Find the specific item by ID var item = db.Categories.SingleOrDefault(c => c.Id == id); if (item != null) { db.Categories.DeleteOnSubmit(item); db.SubmitChanges(); } return(RedirectToAction("Index")); } }
// GET: Category/Create public ActionResult Create(string categoryname) { using (var db = new ChatLogDataContext()) { // Check if the same name exists var exists = db.Categories.Any(c => c.CategoryName == categoryname.Trim()); if (!exists) { db.Categories.InsertOnSubmit(new Category { CategoryName = categoryname, ModifiedDate = DateTime.Now }); db.SubmitChanges(); } return(RedirectToAction("Index")); } }
private bool Classify(ChatLogDataContext db, int MessageID, string CategoryIds, ClassificationMode Mode, bool isSecond = false) { try { // Save or update to the classified var originalMessage = db.LogMessages.SingleOrDefault(l => l.Id == MessageID); if (originalMessage != null) { // Check if the item exists var classified01 = db.ClassifiedMessages.SingleOrDefault(c => c.MessageId == MessageID); if (classified01 != null) { // Already exists -- set to the new category classified01.SelectedCategories = CategoryIds.Replace(',', '|'); classified01.DateModified = DateTime.Now; } else { // Add a new one db.ClassifiedMessages.InsertOnSubmit(new ClassifiedMessage { MessageId = originalMessage.Id, SelectedCategories = CategoryIds.Replace(',', '|'), DateModified = DateTime.Now }); } //Update the message status originalMessage.Status = (short)MessageStatus.Done; originalMessage.DateModified = DateTime.Now; db.SubmitChanges(); } return(true); } catch { return(false); } }
public ActionResult Discard(string messageId, ClassificationMode mode) { int mid = Convert.ToInt32(messageId); using (var db = new ChatLogDataContext()) { var mitem = db.LogMessages.SingleOrDefault(l => l.Id == mid); if (mitem != null) { // Update status and move next mitem.Status = (short)MessageStatus.Discarded; mitem.DateModified = DateTime.Now; } db.SubmitChanges(); return(View("Classify", GetNextUnclassifiedItem(mode, db, mid))); } }