public ActionResult GetApprovals()
        {
            try
            {
                if (!IsValidUser(tokens => tokens[0] == Request["username"].ToString()))
                {
                    return(null);
                }

                List <object> entries = new List <object>();

                ThesaurusEntryClient c = new ThesaurusEntryClient();
                foreach (ThesaurusEntry entry in c.GetAllByDictionary("approvals").Execute())
                {
                    entries.Add(new { rowkey = entry.RowKey, dictionary = entry.PartitionKey, title = entry.From });
                }

                Response.ContentType = "application/json";
                string retvalue = (new { result = "ok", entries = entries.ToArray() }).ToJSON();
                Response.Write(retvalue);
                Response.End();
            }
            catch (Exception ex)
            {
                Response.ContentType = "application/json";
                Response.Write("{\"result\":\"error\", \"message\":\"" + ex.Message + "\"}");
                Response.End();
            }

            return(null);
        }
        public ActionResult PurgeManualEntries()
        {
            if (!IsValidUser(tokens => tokens[0] == Request["username"].ToString()))
            {
                return(RedirectToAction("Logon"));
            }

            ViewBag.UserFirstName = AuthTokens[2];


            List <ThesaurusEntry> entries = new List <ThesaurusEntry>();

            ThesaurusEntryClient c = new ThesaurusEntryClient();

            entries.AddRange(c.GetAllByDictionary("similars").Execute());
            entries.AddRange(c.GetAllByDictionary("progressions").Execute());

            int cnt = 0;

            foreach (ThesaurusEntry entry in entries)
            {
                c.Delete(entry);
                cnt++;
            }

            return(View());
        }
        public ActionResult Progressions()
        {
            if (!IsValidUser(tokens => tokens[0] == Request["username"].ToString()))
            {
                return(RedirectToAction("Logon"));
            }

            ThesaurusEntryClient c = new ThesaurusEntryClient();

            return(View(c.GetAllByDictionary("progressions").Execute()));
        }
        protected void NotifyApprovedItem(string title, string whathappened)
        {
            ThesaurusEntryClient c     = new ThesaurusEntryClient();
            ThesaurusEntry       entry = c.GetAllByDictionary("approvals").Execute().SingleOrDefault(x => x.From == title);

            if (entry == null)
            {
                return;
            }

            EmailManager em = new EmailManager();

            em.SendMail("*****@*****.**", "Career|Thesaurus", "*****@*****.**", "Mapping Change Alert", whathappened);
        }
        public ActionResult CreateEntry(ThesaurusEntry newitem)
        {
            try
            {
                if (!IsValidUser(tokens => tokens[0] == Request["username"].ToString()))
                {
                    return(RedirectToAction("Logon"));
                }

                newitem.Timestamp = DateTime.Now;
                if (ModelState.IsValid)
                {
                    ThesaurusEntryClient c = new ThesaurusEntryClient();
                    c.AddNewItem(newitem);
                    NotifyApprovedItem(newitem.From, AuthTokens[2] + " added \"" + newitem.AddRemove + "\" relationship in " + newitem.PartitionKey + " between \"" + newitem.From + "\" and \"" + newitem.To + "\"");

                    if (newitem.PartitionKey == "similars")
                    {
                        var reverseitem = new ThesaurusEntry {
                            AddedAs = "similar", PartitionKey = newitem.PartitionKey, AddRemove = newitem.AddRemove, From = newitem.To, To = newitem.From, RowKey = ShortGuidGenerator.NewGuid()
                        };
                        c.AddNewItem(reverseitem);
                        NotifyApprovedItem(newitem.To, AuthTokens[2] + " added \"" + newitem.AddRemove + "\" relationship in " + newitem.PartitionKey + " between \"" + newitem.To + "\" and \"" + newitem.From + "\"");
                    }
                }


                if (newitem.AddedAs == "predecessor")
                {
                    return(RedirectToAction("Index", new { p = newitem.To }));
                }
                else
                {
                    return(RedirectToAction("Index", new { p = newitem.From }));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("error", ex.Message);
                return(View(newitem));
            }
        }
        public ActionResult DeleteEntry(string d, string rowkey)
        {
            try
            {
                if (!IsValidUser(tokens => tokens[0] == Request["username"].ToString()))
                {
                    return(null);
                }

                ThesaurusEntryClient c     = new ThesaurusEntryClient();
                ThesaurusEntry       entry = c.GetByPartitionAndRowKey(d, rowkey);
                if (entry != null)
                {
                    c.Delete(entry);
                    NotifyApprovedItem(entry.From, AuthTokens[2] + " deleted \"" + entry.AddRemove + "\" relationship in " + d + " between \"" + entry.From + "\" and \"" + entry.To + "\"");

                    //get reverse entry
                    ThesaurusEntry reverseentry = c.GetAllByDictionary("similars").Execute().SingleOrDefault(x => x.From == entry.To && x.To == entry.From);
                    if (reverseentry != null)
                    {
                        c.Delete(reverseentry);
                        NotifyApprovedItem(entry.To, AuthTokens[2] + " deleted \"" + entry.AddRemove + "\" relationship in " + d + " between \"" + entry.To + "\" and \"" + entry.From + "\"");
                    }
                }

                Response.ContentType = "application/json";
                string retvalue = (new { result = "ok" }).ToJSON();
                Response.Write(retvalue);
                Response.End();
            }
            catch (Exception ex)
            {
                Response.ContentType = "application/json";
                Response.Write("{\"result\":\"error\", \"message\":\"" + ex.Message + "\"}");
                Response.End();
            }

            return(null);
        }
        public ActionResult AddEntry(string d, string t, string from, string to)
        {
            try
            {
                if (!IsValidUser(tokens => tokens[0] == Request["username"].ToString()))
                {
                    return(null);
                }

                ThesaurusEntryClient c = new ThesaurusEntryClient();
                c.AddNewItem(new ThesaurusEntry {
                    PartitionKey = d, AddRemove = t, From = from, To = to, RowKey = ShortGuidGenerator.NewGuid()
                });
                NotifyApprovedItem(from, AuthTokens[2] + " added \"" + t + "\" relationship in " + d + " between \"" + from + "\" and \"" + to + "\"");

                if (d == "similars")
                {
                    var reverseitem = new ThesaurusEntry {
                        PartitionKey = d, AddRemove = t, From = to, To = from, RowKey = ShortGuidGenerator.NewGuid()
                    };
                    c.AddNewItem(reverseitem);
                    NotifyApprovedItem(to, AuthTokens[2] + " added \"" + t + "\" relationship in " + d + " between \"" + to + "\" and \"" + from + "\"");
                }

                Response.ContentType = "application/json";
                string retvalue = (new { result = "ok" }).ToJSON();
                Response.Write(retvalue);
                Response.End();
            }
            catch (Exception ex)
            {
                Response.ContentType = "application/json";
                Response.Write("{\"result\":\"error\", \"message\":\"" + ex.Message + "\"}");
                Response.End();
            }

            return(null);
        }