public async Task <ActionResult> DeleteConfirmed(Guid id) { RejectedWord rejectedWord = await db.RejectedWords.FindAsync(id); db.RejectedWords.Remove(rejectedWord); await db.SaveChangesAsync(); isRedirect = true; System.Web.HttpContext.Current.Session["hasAdded"] = 1; return(RedirectToAction("Index")); }
public async Task <ActionResult> Edit([Bind(Include = "Id,ListNameId,Word")] RejectedWord rejectedWord) { Guid?list_ID = HttpContext.Session["listGuidRejected"] as Guid?; if (ModelState.IsValid) { bool canSave = true; //don't save the word to anything if it already belongs to this list if (await db.RejectedWords.Where(m => m.ListNameId == list_ID).AnyAsync(p => p.Word == rejectedWord.Word)) { canSave = false; } #region //remove approved //List<ApprovedWord> foundWords = await db.ApprovedWords.Where(x => x.Word == rejectedWord.Word).ToListAsync(); //if (foundWords != null) //{ // db.ApprovedWords.RemoveRange(foundWords); // await db.SaveChangesAsync(); //} #endregion //save the word to both this rejected list... if (canSave) { System.Web.HttpContext.Current.Session["hasAdded_r"] = 1; rejectedWord.Word = rejectedWord.Word.ToUpperInvariant(); db.Entry(rejectedWord).State = EntityState.Modified; await db.SaveChangesAsync(); } //...and only to the master rejected list if it's not already in there if (canSave && await db.RejectedWords.Where(m => m.ListName.listName == masterRejectedListName).AllAsync(p => p.Word != rejectedWord.Word)) { var masterListID = await db.ListNames.Where(m => m.listName == masterRejectedListName).FirstAsync(); if (rejectedWord.ListNameId != masterListID.Id) { rejectedWord.ListNameId = masterListID.Id; db.RejectedWords.Add(rejectedWord); await db.SaveChangesAsync(); } } return(RedirectToAction("Index")); } ViewBag.ListNameId = new SelectList(db.ListNames.Where(p => p.Id == list_ID && p.Archive == false && p.IsRejected == true).OrderBy(m => m.listName), "Id", "listName"); return(View(rejectedWord)); }
// GET: RejectedWords/Delete/5 public async Task <ActionResult> Delete(Guid?id) { isRedirect = true; if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } RejectedWord rejectedWord = await db.RejectedWords.FindAsync(id); if (rejectedWord == null) { return(HttpNotFound()); } return(View(rejectedWord)); }
// GET: RejectedWords/Edit/5 public async Task <ActionResult> Edit(Guid?id) { isRedirect = true; if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } RejectedWord rejectedWord = await db.RejectedWords.FindAsync(id); if (rejectedWord == null) { return(HttpNotFound()); } Guid?list_ID = System.Web.HttpContext.Current.Session["listGuid"] as Guid?; ViewBag.ListNameId = new SelectList(db.ListNames.Where(p => p.Id == list_ID && p.Archive == false && p.IsRejected == true).OrderBy(m => m.listName), "Id", "listName"); return(View(rejectedWord)); }
public async Task <ActionResult> Create([Bind(Include = "Id,ListNameId,Word")] RejectedWord rejectedWord) { ViewBag.Warning = string.Empty; #region //Hide View Options If Master //Hide options if master list //if (System.Web.HttpContext.Current.Session["OnMaster"] as bool? == true) //{ // ViewBag.OnMaster = true; //} //else //{ // ViewBag.OnMaster = false; //} #endregion //create current rejected word object for parsing RejectedWord tempLNameID = new RejectedWord(); tempLNameID.ListNameId = rejectedWord.ListNameId; if (ModelState.IsValid) { var masterListID = await db.ListNames.Where(m => m.listName == masterRejectedListName).FirstAsync(); System.Web.HttpContext.Current.Session["hasAdded_r"] = 1; string text = rejectedWord.Word; MatchCollection matches = Regex.Matches(text, @"[\w\d_]+", RegexOptions.Singleline); foreach (Match match in matches) { if (match.Success) { bool canSave = true; //bool canMasterList = false; RejectedWord parsedWord = new RejectedWord(); parsedWord.Id = Guid.NewGuid(); parsedWord.Word = match.Value.ToUpperInvariant(); parsedWord.ListNameId = rejectedWord.ListNameId; rejectedWord = parsedWord; //don't save the word to anything if it already belongs to this list var listID = HttpContext.Session["listGuid"] as Guid?; if (await db.RejectedWords.Where(m => m.ListNameId == listID).AnyAsync(p => p.Word == rejectedWord.Word)) { canSave = false; } #region //remove from approved //option: remove word from all approved lists and enable gloabal master list save //List<ApprovedWord> foundWords = await db.ApprovedWords.Where(x => x.Word == rejectedWord.Word).ToListAsync(); //if (foundWords != null) //{ // if (ViewBag.RemoveAllApproved) // { // canMasterList = true; // db.ApprovedWords.RemoveRange(foundWords); // await db.SaveChangesAsync(); // } //} //option: remove words from client's approved lists //List<ApprovedWord> foundWordsSome = await db.ApprovedWords.Where(x => x.Word == rejectedWord.Word).Where(p => p.ListName.ClientId == rejectedWord.ListName.ClientId).ToListAsync(); //if (foundWordsSome != null) //{ // if (ViewBag.RemoveSomeApproved && !ViewBag.RemoveAllApproved) // { // db.ApprovedWords.RemoveRange(foundWordsSome); // await db.SaveChangesAsync(); // } //} #endregion //save the word to both this rejected list... if (canSave) { rejectedWord.ListNameId = tempLNameID.ListNameId; System.Web.HttpContext.Current.Session["hasAdded_r"] = 1; db.RejectedWords.Add(rejectedWord); await db.SaveChangesAsync(); } //...and only to the master rejected list if it's not already in there if (canSave && await db.RejectedWords.Where(m => m.ListName.listName == masterRejectedListName).AllAsync(p => p.Word != rejectedWord.Word)) { if (rejectedWord.ListNameId != masterListID.Id) { rejectedWord.ListNameId = masterListID.Id; db.RejectedWords.Add(rejectedWord); await db.SaveChangesAsync(); } } } } return(RedirectToAction("Index")); } ViewBag.ListNameId = new SelectList(db.ListNames.OrderBy(m => m.listName), "Id", "listName", rejectedWord.ListNameId); return(View(rejectedWord)); }
public async Task <ActionResult> Create([Bind(Include = "Id,ClientId,listName,IsRejected,Archive,DateCreated,DateModified")] ListName Name, string Word) { bool canCreate = true; bool canSave = true; if (ModelState.IsValid) { if (Name.listName == masterRejectedListName) { if (db.ListNames.Where(p => p.listName == masterRejectedListName).Count() > 0) { canCreate = false; ViewBag.Warning = masterRejectedListName.ToString() + " has already been created."; } } //if (db.ListNames.Where(p => p.listName == Name.listName).Count() > 0) //{ // canCreate = false; // ViewBag.Warning = Name.listName + " has already been created."; //} if (canCreate) { Name.DateCreated = DateTime.Now; Name.DateModified = DateTime.Now; ViewBag.Warning = null; Name.Id = Guid.NewGuid(); db.ListNames.Add(Name); await db.SaveChangesAsync(); } } ViewBag.ClientId = new SelectList(db.Clients, "Id", "Name", Name.ClientId); System.Web.HttpContext.Current.Session["hasAdded"] = 1; if (Name.IsRejected == false) { if (ModelState.IsValid) { ViewBag.Warning = "Working. Please wait..."; System.Web.HttpContext.Current.Session["hasAdded"] = 1; ViewBag.Processing = true; ApprovedWord approvedWord = new ApprovedWord(); approvedWord.Id = Guid.NewGuid(); approvedWord.ListNameId = Name.Id; approvedWord.Word = Word; string textAW = approvedWord.Word; MatchCollection matches = Regex.Matches(textAW, @"[\w\d_]+", RegexOptions.Singleline); foreach (Match match in matches) { if (match.Success) { canSave = true; ApprovedWord parsedWord = new ApprovedWord(); parsedWord.Id = Guid.NewGuid(); parsedWord.Word = match.Value.ToUpperInvariant(); parsedWord.ListNameId = approvedWord.ListNameId; approvedWord = parsedWord; if (await db.ApprovedWords.Where(m => m.ListNameId == Name.Id).AnyAsync(p => p.Word == approvedWord.Word)) { canSave = false; } //color if on master rejected if (await db.RejectedWords.Where(m => m.ListName.listName == masterRejectedListName).AnyAsync(p => p.Word == approvedWord.Word)) { approvedWord.onRejected = true; } if (canSave) { db.ApprovedWords.Add(approvedWord); await db.SaveChangesAsync(); } } } return(RedirectToAction("Index")); } ViewBag.ListNameId = new SelectList(db.ListNames.OrderBy(m => m.listName), "Id", "listName", Name.Id); return(View(Name)); } else { ViewBag.Warning = "Working. Please wait..."; #region //Hide View Options If Master //Hide options if master list //if (System.Web.HttpContext.Current.Session["OnMaster"] as bool? == true) //{ // ViewBag.OnMaster = true; //} //else //{ // ViewBag.OnMaster = false; //} #endregion //create current rejected word object for parsing RejectedWord tempLNameID = new RejectedWord(); tempLNameID.ListNameId = Name.Id; if (ModelState.IsValid) { var masterListID = await db.ListNames.Where(m => m.listName == masterRejectedListName).FirstAsync(); System.Web.HttpContext.Current.Session["hasAdded_r"] = 1; RejectedWord rejectedWord = new RejectedWord(); rejectedWord.Id = Guid.NewGuid(); rejectedWord.ListNameId = Name.Id; rejectedWord.Word = Word; string text = rejectedWord.Word; MatchCollection matches = Regex.Matches(text, @"[\w\d_]+", RegexOptions.Singleline); foreach (Match match in matches) { if (match.Success) { canSave = true; //bool canMasterList = false; RejectedWord parsedWord = new RejectedWord(); parsedWord.Id = Guid.NewGuid(); parsedWord.Word = match.Value.ToUpperInvariant(); parsedWord.ListNameId = Name.Id; rejectedWord = parsedWord; //don't save the word to anything if it already belongs to this list if (await db.RejectedWords.Where(m => m.ListNameId == Name.Id).AnyAsync(p => p.Word == rejectedWord.Word)) { canSave = false; } #region //remove from approved //option: remove word from all approved lists and enable gloabal master list save //List<ApprovedWord> foundWords = await db.ApprovedWords.Where(x => x.Word == rejectedWord.Word).ToListAsync(); //if (foundWords != null) //{ // if (ViewBag.RemoveAllApproved) // { // canMasterList = true; // db.ApprovedWords.RemoveRange(foundWords); // await db.SaveChangesAsync(); // } //} //option: remove words from client's approved lists //List<ApprovedWord> foundWordsSome = await db.ApprovedWords.Where(x => x.Word == rejectedWord.Word).Where(p => p.ListName.ClientId == rejectedWord.ListName.ClientId).ToListAsync(); //if (foundWordsSome != null) //{ // if (ViewBag.RemoveSomeApproved && !ViewBag.RemoveAllApproved) // { // db.ApprovedWords.RemoveRange(foundWordsSome); // await db.SaveChangesAsync(); // } //} #endregion //save the word to both this rejected list... if (canSave) { rejectedWord.ListNameId = tempLNameID.ListNameId; System.Web.HttpContext.Current.Session["hasAdded_r"] = 1; db.RejectedWords.Add(rejectedWord); await db.SaveChangesAsync(); } //...and only to the master rejected list if it's not already in there if (canSave && await db.RejectedWords.Where(m => m.ListName.listName == masterRejectedListName).AllAsync(p => p.Word != rejectedWord.Word)) { if (rejectedWord.ListNameId != masterListID.Id) { rejectedWord.ListNameId = masterListID.Id; db.RejectedWords.Add(rejectedWord); await db.SaveChangesAsync(); } } } } return(RedirectToAction("Index")); } ViewBag.ListNameId = new SelectList(db.ListNames.OrderBy(m => m.listName), "Id", "listName", Name.Id); } return(View(Name)); }