Beispiel #1
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,ListNameId,Word")] ApprovedWord approvedWord)
        {
            Guid?list_ID = System.Web.HttpContext.Current.Session["listGuid"] as Guid?;

            if (ModelState.IsValid)
            {
                bool canSave = true;

                if (await db.ApprovedWords.Where(m => m.ListNameId == list_ID).AnyAsync(p => p.Word == approvedWord.Word))
                {
                    canSave = false;
                }

                if (await db.RejectedWords.Where(m => m.ListName.listName == masterRejectedListName).AnyAsync(p => p.Word == approvedWord.Word))
                {
                    canSave = false;
                }

                if (canSave)
                {
                    approvedWord.Word = approvedWord.Word.ToUpperInvariant();
                    System.Web.HttpContext.Current.Session["hasAdded"] = 1;
                    db.Entry(approvedWord).State = EntityState.Modified;
                    await db.SaveChangesAsync();
                }
                return(RedirectToAction("Index"));
            }
            ViewBag.ListNameId = new SelectList(db.ListNames.Where(p => p.Id == list_ID && p.Archive == false && p.IsRejected == false).OrderBy(m => m.listName), "Id", "listName");
            return(View(approvedWord));
        }
Beispiel #2
0
        public async Task <ActionResult> DeleteConfirmed(Guid id)
        {
            ApprovedWord approvedWord = await db.ApprovedWords.FindAsync(id);

            db.ApprovedWords.Remove(approvedWord);
            await db.SaveChangesAsync();

            isRedirect = true;
            System.Web.HttpContext.Current.Session["hasAdded"] = 1;
            return(RedirectToAction("Index"));
        }
Beispiel #3
0
        // GET: ApprovedWords/Delete/5
        public async Task <ActionResult> Delete(Guid?id)
        {
            isRedirect = true;
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ApprovedWord approvedWord = await db.ApprovedWords.FindAsync(id);

            if (approvedWord == null)
            {
                return(HttpNotFound());
            }
            return(View(approvedWord));
        }
Beispiel #4
0
        public async Task <ActionResult> Create([Bind(Include = "Id,ListNameId,Word")] ApprovedWord approvedWord)
        {
            ViewBag.Warning = "Please wait...";
            if (ModelState.IsValid)
            {
                System.Web.HttpContext.Current.Session["hasAdded"] = 1;
                ViewBag.Processing = true;
                string          text    = approvedWord.Word;
                MatchCollection matches = Regex.Matches(text, @"[\w\d_]+", RegexOptions.Singleline);
                foreach (Match match in matches)
                {
                    if (match.Success)
                    {
                        bool         canSave    = true;
                        ApprovedWord parsedWord = new ApprovedWord();
                        parsedWord.Id         = Guid.NewGuid();
                        parsedWord.Word       = match.Value.ToUpperInvariant();
                        parsedWord.ListNameId = approvedWord.ListNameId;
                        approvedWord          = parsedWord;

                        var listID = System.Web.HttpContext.Current.Session["listGuid"] as Guid?;
                        if (await db.ApprovedWords.Where(m => m.ListNameId == listID).AnyAsync(p => p.Word == approvedWord.Word))
                        {
                            canSave = false;
                        }

                        //Color (true) if on master rejected word list
                        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", approvedWord.ListNameId);
            return(View(approvedWord));
        }
Beispiel #5
0
        // GET: ApprovedWords/Edit/5
        public async Task <ActionResult> Edit(Guid?id)
        {
            isRedirect = true;
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ApprovedWord approvedWord = await db.ApprovedWords.FindAsync(id);

            if (approvedWord == 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 == false).OrderBy(m => m.listName), "Id", "listName");
            return(View(approvedWord));
        }
        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));
        }