//
        // GET: /Users/
        public ActionResult Index()
        {
            DocsLinqDataContext doc_db = new DocsLinqDataContext();
            int userID = Convert.ToInt32(Session["userID"]);

            user u = new user();
            u = (from users in doc_db.users
                 where users.userID.Equals(userID)
                 select users).FirstOrDefault<user>();
            ViewBag.u = u;

            // Get the states
            List<State> states = new List<State>();
            states = (from s in doc_db.States
                     orderby s.abbr
                     select s).ToList<State>();
            ViewBag.states = states;

            // Get the user's available modules
            List<module> modules = new List<module>();
            modules = Users.GetUserModules(userID);
            ViewBag.Modules = modules;

            return View();
        }
Exemple #2
0
        /// <summary>
        /// This function will send an email to the given user letting them know that their account has been created and is active.
        /// </summary>
        /// <param name="userID">ID of the user.</param>
        public static void AlertNewUser(int userID)
        {
            DocsLinqDataContext doc_db = new DocsLinqDataContext();
            // Get the user's infromation
            user thisUser = (from u in doc_db.users
                             where u.userID.Equals(userID)
                             select u).FirstOrDefault<user>();

            MailMessage mail = new MailMessage();
            SmtpClient SmtpServer = new SmtpClient();

            mail.To.Add(thisUser.email);
            mail.Subject = "CURT Documentation Account Activation";

            mail.IsBodyHtml = true;
            string htmlBody;

            htmlBody = "<div style='margin-top: 15px;font-family: Arial;font-size: 10pt;'>";
            htmlBody += "<h4>Dear " + thisUser.fname + " " + thisUser.lname + ",</h4>";
            htmlBody += "<p>A new account has been created with the e-mail {" + thisUser.email +"}. The credentials are: </p>";
            htmlBody += "<p style='margin:2px 0px'>Username: <strong>" + thisUser.username + "</strong></p>";
            htmlBody += "<p style='margin:2px 0px'>Password: <strong>" + thisUser.password + "</strong></p>";
            htmlBody += "<p>You may log into your account at <a href='http://admin.curtmfg.com'>http://admin.curtmfg.com</a></p>";
            htmlBody += "______________________________________________________________________";
            htmlBody += "<p>If you feel this has been sent by mistake, please contact Web Support at <a href='mailto:[email protected]' target='_blank'>[email protected]</a>.</p>";
            htmlBody += "<br /><span style='color:#999'>Thank you,</span>";
            htmlBody += "<br /><br /><br />";
            htmlBody += "<span style='line-height:75px;color:#999'>CURT Administration</span>";
            htmlBody += "</div>";

            mail.Body = htmlBody;

            SmtpServer.Send(mail);
        }
        /// <summary>
        /// Generates a new password for a given user and e-mails them the new credentials.
        /// </summary>
        /// <param name="u">User object</param>
        /// <returns>True if e-mail was sent ::: False if we encountered an error.</returns>
        public static Boolean sendNewPass(user u)
        {
            // Get the user information
            DocsLinqDataContext doc_db = new DocsLinqDataContext();
            user thisUser = (from users in doc_db.users
                            where users.userID.Equals(u.userID)
                            select users).FirstOrDefault<user>();

            // Generate the new password
            PasswordGenerator pg = new PasswordGenerator();
            string newPass = pg.Generate();

            // Assign to user
            thisUser.password = newPass;

            try { // Attempt to committ the changes to the database

                // Save the changes
                doc_db.SubmitChanges();

                // Attempt to send e-mail
                try {
                    MailMessage mail = new MailMessage();
                    SmtpClient SmtpServer = new SmtpClient();

                    mail.To.Add(thisUser.email);
                    mail.Subject = "CURT Documentation Account Recovery";

                    mail.IsBodyHtml = true;
                    string htmlBody;

                    htmlBody    =   "<div style='margin-top: 15px;font-family: Arial;font-size: 10pt;'>";
                    htmlBody    +=  "<h4>Dear " + thisUser.fname + " " + thisUser.lname + ",</h4>";
                    htmlBody    +=  "<p>There has been a password change for {"+thisUser.username+"}. You're new credentials for CURT Manufacturing Documentation are: </p>";
                    htmlBody    +=  "<p style='margin:2px 0px'>Username: <strong>" + thisUser.username + "</strong></p>";
                    htmlBody    +=  "<p style='margin:2px 0px'>Password: <strong>" + newPass + "</strong></p>";
                    htmlBody    +=  "______________________________________________________________________";
                    htmlBody += "<p>If you feel this has been sent by mistake, please contact Web Support at <a href='mailto:[email protected]' target='_blank'>[email protected]</a>.</p>";
                    htmlBody    +=  "<br /><span style='color:#999'>Thank you,</span>";
                    htmlBody    +=  "<br /><br /><br />";
                    htmlBody    +=  "<span style='line-height:75px;color:#999'>CURT Documentation Administrator</span>";
                    htmlBody    +=  "</div>";

                    mail.Body = htmlBody;

                    SmtpServer.Send(mail);
                } catch (Exception e) {
                    Console.Write(e.Message);
                    return false;
                }

                return true;
            } catch (ChangeConflictException e) {
                return false;
            }
        }
        /// <summary>
        /// Gets all items.
        /// </summary>
        /// <returns>List of docItems</returns>
        /// <remarks></remarks>
        public static List<docItem> GetAllItems()
        {
            List<docItem> items = new List<docItem>();
            DocsLinqDataContext doc_db = new DocsLinqDataContext();

            items = (from di in doc_db.docItems
                     orderby di.itemID
                     select di).ToList<docItem>();
            return items;
        }
Exemple #5
0
        /// <summary>
        /// Gets module by name.
        /// </summary>
        /// <param name="module1">The module1.</param>
        /// <returns>module</returns>
        /// <remarks></remarks>
        public static module GetModuleByName(string module1)
        {
            module mod = new module();
            DocsLinqDataContext doc_db = new DocsLinqDataContext();

            mod = (from m in doc_db.modules
                 where m.module1.Equals(module1)
                 select m).FirstOrDefault<module>();

            return mod;
        }
Exemple #6
0
        public ActionResult Add()
        {
            DocsLinqDataContext doc_db = new DocsLinqDataContext();
            List<user> authors = doc_db.users.Where(x => x.isActive == 1).OrderBy(x => x.lname).ToList<user>();
            ViewBag.authors = authors;

            List<BlogCategory> categories = BlogCategoryModel.GetAll();
            ViewBag.categories = categories;

            return View();
        }
        /// <summary>
        /// Loads the blank category page so that the user can add a brand new category. The user will be able to choose a category to mark as the parent category.
        /// </summary>
        /// <returns>View of new category.</returns>
        public ActionResult AddCategory()
        {
            DocsLinqDataContext doc_db = new DocsLinqDataContext();

            // Get all categories
            List<docCategory> categories = (from c in doc_db.docCategories
                                         orderby c.catName
                                            select c).ToList<docCategory>();
            ViewBag.categories = categories;

            return View();
        }
Exemple #8
0
        public ActionResult Edit(int id = 0)
        {
            // Get all the Authors
            DocsLinqDataContext doc_db = new DocsLinqDataContext();
            List<user> authors = doc_db.users.Where(x => x.isActive == 1).OrderBy(x => x.lname).ToList<user>();
            ViewBag.authors = authors;

            List<BlogCategory> categories = BlogCategoryModel.GetAll();
            ViewBag.categories = categories;

            PostWithCategories post = BlogPostModel.Get(id);
            ViewBag.post = post;

            return View();
        }
        /// <summary>
        /// Gets the categories.
        /// </summary>
        /// <param name="moduleID">The module ID.</param>
        /// <returns>List of category</returns>
        /// <remarks></remarks>
        public static List<docCategory> GetCategories(int moduleID = 0)
        {
            List<docCategory> cats = new List<docCategory>();
            DocsLinqDataContext doc_db = new DocsLinqDataContext();

            if (moduleID != 0) {
                cats = (from c in doc_db.docCategories
                        orderby c.catName
                        select c).ToList<docCategory>();
            } else {
                cats = doc_db.docCategories.OrderBy(c => c.catName).ToList<docCategory>();
            }

            return cats;
        }
Exemple #10
0
        protected override void Initialize(System.Web.Routing.RequestContext requestContext)
        {
            base.Initialize(requestContext);

            HttpCookie userID = new HttpCookie("");
            userID = Request.Cookies.Get("userID");

            HttpCookie username = new HttpCookie("");
            username = Request.Cookies.Get("username");

            HttpCookie superUser = new HttpCookie("");
            superUser = Request.Cookies.Get("superUser");

            HttpCookie name = new HttpCookie("");
            name = Request.Cookies.Get("name");

            try {
                string uID = null;
                try {
                    // cookie login
                    uID = userID.Value;
                } catch {
                    try {
                        uID = Session["userID"].ToString();
                    } catch { }
                }

                DocsLinqDataContext doc_db = new DocsLinqDataContext();
                user u = (from users in doc_db.users
                          where users.userID.Equals(Convert.ToInt32(uID))
                          select users).First<user>();

                Session["userID"] = u.userID;
                Session["username"] = u.username;
                Session["superUser"] = u.superUser;
                Session["name"] = u.fname + " " + u.lname;

                // Get the modules for the logged in user
                List<module> modules = new List<module>();
                modules = Users.GetUserModules(u.userID);
                ViewBag.name = u.fname + " " + u.lname;
                ViewBag.Modules = modules;
            } catch {
                // user doesn't exist
                Response.Redirect("~/Authenticate/Logout");
            }
        }
        public ActionResult Forgot(string username, string email)
        {
            DocsLinqDataContext doc_db = new DocsLinqDataContext();
            if (username.Trim().Length != 0) {

                // Instantiate the user object and assign user
                user u = new user();
                u = (from users in doc_db.users
                          where users.username.Equals(username.Trim())
                          select users).FirstOrDefault();
                if (u != null) { // Make sure we found a user
                    if (AuthenticateUser.sendNewPass(u)) { // Attempt to send updated e-mail
                        HttpContext.Response.Redirect("~/Authenticate/userFound");
                    } else {
                        ViewBag.Message = "We were unable to locate " + username.Trim() + " in our system";
                    }

                } else {
                    ViewBag.Message = "We were unable to locate " + username.Trim() + " in our system.";
                }
            } else if (email.Trim().Length != 0) {

                // Instantiate our user object and populate from database
                user u = new user();
                u = (from users in doc_db.users
                     where users.email.Equals(email.Trim())
                     select users).FirstOrDefault();

                if (u != null) { // Make sure we found a user
                    if (AuthenticateUser.sendNewPass(u)) { // Attempt to send update e-mail
                        HttpContext.Response.Redirect("~/Authenticate/userFound");
                    } else {
                        ViewBag.Message = "We were unable to locate " + email.Trim() + " in our system.";
                    }
                } else {
                    ViewBag.Message = "We were unable to locate " + email.Trim() + " in our system.";
                }
            } else { // Both username and email were blank
                ViewBag.Message = "You did not enter a username or e-mail address";
            }

            return View("Forgot");
        }
        public ActionResult AddCategory(string catName)
        {
            DocsLinqDataContext doc_db = new DocsLinqDataContext();
            catName = Request.Form["catName"].Trim();
            int parentID = Convert.ToInt32(Request.Form["parentID"].Trim());
            string comments = Request.Form["comments"].Trim();

            // Initiate our error message collection
            List<string> error_messages = new List<string>();

            // Make sure the category name is not blank.
            if (catName.Length == 0) { error_messages.Add("Category name is required."); }

            if (error_messages.Count == 0) {
                // Create new category object
                docCategory newCat = new docCategory {
                    catName = catName,
                    parentID = parentID,
                    comments = comments
                };
                doc_db.docCategories.InsertOnSubmit(newCat);

                try { // Attempt to save the category
                    doc_db.SubmitChanges();
                    return RedirectToAction("Index");
                } catch (Exception e) {
                    error_messages.Add(e.Message);
                }
            }

            ViewBag.catName = catName;
            ViewBag.parentID = parentID;
            ViewBag.comments = comments;
            ViewBag.error_messages = error_messages;

            // Get all categories
            List<docCategory> categories = (from c in doc_db.docCategories
                                         orderby c.catName
                                            select c).ToList<docCategory>();
            ViewBag.categories = categories;

            return View();
        }
Exemple #13
0
        public ActionResult Index()
        {
            ViewBag.Message = "Welcome "+ Session["username"];

            DocsLinqDataContext doc_db = new DocsLinqDataContext();

            int userId = 0;
            if (Session["userID"] != null && Session["userID"].ToString().Length > 0) {
                userId = Convert.ToInt32(Session["userID"]);
            } else {
                HttpContext.Response.Redirect("~/Authenticate");
            }

            // Get the modules for this admin user
            List<module> modules = Users.GetUserModules(userId);

            ViewBag.Modules = modules;

            return View();
        }
 public string Add(string name = "", string url = "", string username = "", string password = "", string comments = "")
 {
     string response = "";
     try {
         DocsLinqDataContext db = new DocsLinqDataContext();
         resource_listing listing = new resource_listing {
             resource_name = name,
             resource_url = url,
             username = username,
             password = password,
             comments = comments
         };
         db.resource_listings.InsertOnSubmit(listing);
         db.SubmitChanges();
         JavaScriptSerializer js = new JavaScriptSerializer();
         response = js.Serialize(listing);
     }catch(Exception e){
         response = "{\"error\":\""+ e.Message + "\"]";
     }
     return response;
 }
        public string AddUserToResource(int resourceID = 0, int userID = 0)
        {
            string response = "";
            try {
                DocsLinqDataContext db = new DocsLinqDataContext();

                // Make sure this record doesn't already exist.
                int existing = (from ru in db.resource_users
                                where ru.resourceID.Equals(resourceID) && ru.userID.Equals(userID)
                                select ru).Count();
                if (existing > 0) {
                    return "{\"error\":\"This record exists.\"]";
                }

                // Create new record
                resource_user new_ru = new resource_user {
                    resourceID = resourceID,
                    userID = userID
                };
                db.resource_users.InsertOnSubmit(new_ru);
                db.SubmitChanges();

                resource_slim_user user = (from u in db.users
                                           join r in db.resource_users on u.userID equals r.userID
                                           where r.resource_user_key.Equals(new_ru.resource_user_key)
                                           select new resource_slim_user{
                                               user = u.fname + " " + u.lname,
                                               username = u.username,
                                               userID = u.userID
                                           }).FirstOrDefault<resource_slim_user>();

                JavaScriptSerializer js = new JavaScriptSerializer();
                response = js.Serialize(user);
            } catch (Exception e) {
                response = "{\"error\":\"" + e.Message + "\"]";
            }
            return response;
        }
        /// <summary>
        /// Delete a given document from the syste,
        /// </summary>
        /// <param name="docID">ID of the document.</param>
        public static void DeleteDocument(int docID = 0)
        {
            if (docID <= 0) { throw new Exception("Doc ID is invalid."); }
            DocsLinqDataContext db = new DocsLinqDataContext();

            document doc = new document();
            doc = (from d in db.documents
                   where d.docID.Equals(docID)
                   select d).FirstOrDefault<document>();

            List<itemDoc> item_docs = new List<itemDoc>();
            item_docs = (from id in db.itemDocs
                         where id.docID.Equals(doc.docID)
                         select id).ToList<itemDoc>();

            string dir = @AppDomain.CurrentDomain.BaseDirectory.Replace("\\\\","\\") + doc.documentPath.Replace("~", "").Replace("/","\\").Replace("\\\\","\\");
            //string file = System.IO.Directory.GetFiles(dir)[0];
            System.IO.File.Delete(dir);

            db.documents.DeleteOnSubmit(doc);
            db.itemDocs.DeleteAllOnSubmit<itemDoc>(item_docs);
            db.SubmitChanges();
        }
Exemple #17
0
        /// <summary>
        /// Alert the sales rep that a new user has signed up. This will let them know that they need to log in and chose to make the user active or not.
        /// </summary>
        /// <param name="u">User that has signed up.</param>
        public static void AlertRep(user u)
        {
            DocsLinqDataContext doc_db = new DocsLinqDataContext();

            // Get the users state
            State state = (from s in doc_db.States
                          where s.stateID.Equals(u.stateID)
                          select s).FirstOrDefault<State>();

            MailMessage mail = new MailMessage();
            SmtpClient SmtpServer = new SmtpClient();

            mail.To.Add("*****@*****.**");
            mail.Subject = "CURT Administration Account Sign Up";

            mail.IsBodyHtml = true;
            string htmlBody;

            htmlBody = "<div style='margin-top: 15px;font-family: Arial;font-size: 10pt;'>";
                htmlBody += "<div style='border-bottom: 2px solid #999'>";
                    htmlBody += "<p>A new account has been created with the e-mail {" + u.email + "}. </p>";
                    htmlBody += "<p style='margin:2px 0px'>Name: <strong>" + u.fname + " " + u.lname + "</strong></p>";
                    htmlBody += "<p style='margin:2px 0px'>Phone: <strong>" + u.phone + "</strong></p>";
                    htmlBody += "<p style='margin:2px 0px'>Address: <strong>" + u.address + " " + u.city +", "+ state.abbr + "</strong></p>";
                    htmlBody += "<p style='margin:2px 0px'>Comments: <strong>" + u.comments + "</strong></p><br />";
                    htmlBody += "<p style='margin:2px 0px'>Please login to the admin section of the CURT Administration and activate the account.</p>";
                htmlBody += "</div>";
                htmlBody += "<p>If you feel this has been sent by mistake, please contact Web Support at <a href='mailto:[email protected]' target='_blank'>[email protected]</a>.</p>";
                htmlBody += "<br /><span style='color:#999'>Thank you,</span>";
                htmlBody += "<br /><br /><br />";
                htmlBody += "<span style='line-height:75px;color:#999'>CURT Administration</span>";
            htmlBody += "</div>";

            mail.Body = htmlBody;

            SmtpServer.Send(mail);
        }
        public ActionResult ViewCatItems(int catID)
        {
            // Get the categories items
            List<docItem> items = Documentation.GetCategoryItems(catID);
            ViewBag.items = items;

            // Get the category to be updated
            DocsLinqDataContext doc_db = new DocsLinqDataContext();
            docCategory cat = (from c in doc_db.docCategories
                   where c.catID.Equals(catID)
                   select c).FirstOrDefault<docCategory>();
            ViewBag.cat = cat;

            return View("Items");
        }
        public string RemoveCategory(string cat_id)
        {
            string error = "";

            try {
                // Convert cat_id into integer and instantiate LINQ object
                int catID = Convert.ToInt32(cat_id);
                DocsLinqDataContext doc_db = new DocsLinqDataContext();

                // Get the category
                docCategory cat = (from c in doc_db.docCategories
                                where c.catID.Equals(catID)
                                   select c).FirstOrDefault<docCategory>();
                doc_db.docCategories.DeleteOnSubmit(cat);

                // Get the items under this category
                List<cat_item> items = (from ci in doc_db.cat_items
                                        where ci.catID.Equals(catID)
                                        select ci).ToList<cat_item>();

                foreach (cat_item item in items) { // Loop through the items and reset their category
                    item.catID = 1;
                }

                doc_db.SubmitChanges(); // Save changes
            } catch (Exception e) {
                error = e.Message;
            }

            return error;
        }
        public ActionResult EditItem(string item_id, string itemName)
        {
            DocsLinqDataContext doc_db = new DocsLinqDataContext();
            int itemID = Convert.ToInt32(item_id);

            // Get the item
            docItem item = (from di in doc_db.docItems
                            where di.itemID.Equals(itemID)
                            select di).Single<docItem>();

            // Reassign form fields
            itemName = Request.Form["itemName"].Trim();
            string itemDescription = Request.Form["itemDescription"].Trim().Replace("\r\n","<br />").Replace("\n","<br />").Replace("\r","<br />");
            string executionExample = Request.Form["executionExample"].Trim().Replace("\r\n", "<br />").Replace("\n", "<br />").Replace("\r", "<br />");
            string resultExample = Request.Form["resultExample"].Trim().Replace("\r\n", "<br />").Replace("\n", "<br />").Replace("\r", "<br />");
            string codeLink = Request.Form["codeLink"].Trim();
            string html = Request.Form["html"].Trim();
            int author = Convert.ToInt32(Request.Form["author"].Trim());
            string[] saved_cats = (Request.Form["cat"] != null)?Request.Form["cat"].Trim().Split(','):new string[' '];

            // Validate the submitted info
            List<string> error_messages = new List<string>();
            if (itemName.Length == 0) { error_messages.Add("You must enter a name for this item."); }
            if (itemDescription.Length == 0) { error_messages.Add("You must enter a brief overview of this item."); }
            if (saved_cats.Length == 0) { error_messages.Add("You did not specify a category for this item."); }
            // End Validation

            if (error_messages.Count == 0) { // Save the item

                try {
                    item.itemName = itemName;
                    item.itemDescription = itemDescription;
                    item.executionExample = executionExample;
                    item.resultExample = resultExample;
                    item.codeLink = codeLink;
                    item.author = author;
                    item.itemHTML = html;
                    item.dateModified = DateTime.Now;

                    doc_db.SubmitChanges();

                    // Handle File Upload
                    HttpPostedFileBase hpf = Request.Files[0] as HttpPostedFileBase;
                    if(hpf.ContentLength > 0){
                        string dir = AppDomain.CurrentDomain.BaseDirectory + "/Content/APIDocs/" + itemName;
                        if (!Directory.Exists(dir)) {
                            Directory.CreateDirectory(dir);
                        }
                        string savedFileName = Path.Combine(dir,Path.GetFileName(hpf.FileName));
                        hpf.SaveAs(savedFileName);

                        List<document> existing_docs = new List<document>();
                        existing_docs = (from d in doc_db.documents
                                         where d.documentPath.Equals("/Content/APIDocs/" + itemName + "/" + Path.GetFileName(hpf.FileName))
                                         select d).ToList<document>();
                        foreach (document existing_doc in existing_docs) {
                            itemDoc item_doc = (from item_docs in doc_db.itemDocs
                                                where item_docs.docID.Equals(existing_doc.docID)
                                                select item_docs).FirstOrDefault<itemDoc>();
                            doc_db.itemDocs.DeleteOnSubmit(item_doc);
                        }
                        doc_db.documents.DeleteAllOnSubmit<document>(existing_docs);
                        doc_db.SubmitChanges();

                        document doc = new document {
                            documentPath = "~/Content/APIDocs/"+itemName+"/"+hpf.FileName,
                            documentTitle = Request.Form["documentName"].Trim(),
                            dateAdded = DateTime.Now
                        };
                        doc_db.documents.InsertOnSubmit(doc);
                        doc_db.SubmitChanges();

                        itemDoc id = new itemDoc {
                            itemID = item.itemID,
                            docID = doc.docID
                        };
                        doc_db.itemDocs.InsertOnSubmit(id);
                        doc_db.SubmitChanges();
                    }

                    return RedirectToAction("Items");
                } catch (Exception e) {
                    error_messages.Add(e.Message);
                }
            }
            ViewBag.error_messages = error_messages;

            ViewBag.item = item;

            // Get the cateogries that this item is associated with
            List<docCategory> item_cats = new List<docCategory>();
            item_cats = (from ci in doc_db.cat_items
                         join cats in doc_db.docCategories on ci.catID equals cats.catID
                         where ci.itemID.Equals(item.itemID)
                         select cats).ToList<docCategory>();
            ViewBag.item_cats = item_cats;

            // get the comments on this item
            List<UserComment> comments = Documentation.GetItemComments(item.itemID);
            ViewBag.comments = comments;

            // Get all of the categories
            List<docCategory> categories = Documentation.GetCategories();
            ViewBag.categories = categories;

            // get all of the users ::: this will allow us to designate the author of the new item
            List<user> users = Users.GetAllUsers();
            ViewBag.users = users;

            return View();
        }
        public ActionResult EditItem(string item_id)
        {
            DocsLinqDataContext doc_db = new DocsLinqDataContext();
            int itemID = Convert.ToInt32(item_id);

            // Get the item
            docItem item = (from di in doc_db.docItems
                           where di.itemID.Equals(itemID)
                           select di).Single<docItem>();
            ViewBag.item = item;

            // Get the cateogries that this item is associated with
            List<docCategory> item_cats = new List<docCategory>();
            item_cats = (from ci in doc_db.cat_items
                         join cats in doc_db.docCategories on ci.catID equals cats.catID
                         where ci.itemID.Equals(item.itemID)
                         select cats).ToList<docCategory>();
            ViewBag.item_cats = item_cats;

            // get the comments on this item
            List<UserComment> comments = Documentation.GetItemComments(itemID);
            ViewBag.comments = comments;

            // Get all of the categories
            List<docCategory> categories = Documentation.GetCategories();
            ViewBag.categories = categories;

            // get all of the users ::: this will allow us to designate the author of the new item
            List<user> users = Users.GetAllUsers();
            ViewBag.users = users;

            // Get all the documents
            List<document> documents = new List<document>();
            documents = (from d in doc_db.documents
                         join id in doc_db.itemDocs on d.docID equals id.docID
                         where id.itemID.Equals(item_id)
                         select d).ToList<document>();
            ViewBag.documents = documents;

            return View();
        }
        /// <summary>
        /// Edit page for all super users.
        /// </summary>
        /// <returns>View</returns>
        public ActionResult FullList()
        {
            int userID = Convert.ToInt32(Session["userID"]);
            if (!super_users.Contains(userID)) {
                Response.Redirect("~/Account");
            }
            DocsLinqDataContext db = new DocsLinqDataContext();

            List<resource_listing> listings = new List<resource_listing>();
            listings = (from r in db.resource_listings
                        select r).Distinct().OrderBy(x => x.resource_name).ToList<resource_listing>();

            List<user> users = new List<user>();
            users = (from u in db.users
                        select u).OrderBy(x => x.lname).ToList<user>();

            ViewBag.listings = listings;
            ViewBag.users = users;
            return View();
        }
        public ActionResult Signup(string fname)
        {
            // Assign form fields
            fname = Request.Form["fname"].Trim();
            string lname = Request.Form["lname"].Trim();
            string new_username = Request.Form["new_username"].Trim();
            string email = Request.Form["email"].Trim();
            string address = Request.Form["address"].Trim();
            string phone = Request.Form["phone"].Trim().Replace("-", "");
            string city = Request.Form["city"].Trim();
            int stateID = Convert.ToInt32(Request.Form["stateID"].Trim());
            int isDealer = (Request.Form["dealer"] != null)?1:0;
            string comments = Request.Form["comments"];

            // Initiate error list
            List<string> error_messages = new List<string>();

            /******* Validate form fields ******/
            if (fname.Length == 0) { error_messages.Add("First name is required."); }
            if (lname.Length == 0) { error_messages.Add("Last name is required."); }
            if (new_username.Length < 6) { error_messages.Add("Username must be at least 6 characters."); }
            if (email.Length == 0) { error_messages.Add("E-Mail is required."); }
            if (!email.Contains("curtmfg.com")) { error_messages.Add("CURT Manufacturing E-Mail address is required."); }
            if (phone.Length == 0) { error_messages.Add("Phone number is required."); }
            if (address.Length == 0) { error_messages.Add("Address is required."); }
            if (city.Length == 0) { error_messages.Add("City is required."); }
            if (stateID == 0) { error_messages.Add("State is required."); }
            if (comments.Length == 0) { error_messages.Add("Comments are required."); }

            DocsLinqDataContext doc_db = new DocsLinqDataContext();

            // Make sure we don't have a user for this e-mail address
            List<user> u = (from users in doc_db.users
                              where users.email.Equals(email)
                              select users).ToList<user>();
            if (u.Count != 0) { error_messages.Add("A user with this e-mail already exists in the database."); }

            // Make sure we don't have a user with this username
            int username_count = (from uc in doc_db.users
                                  where uc.username.Equals(new_username)
                                  select uc).Count();
            if (username_count > 0) { error_messages.Add("Username is taken."); }

            if(error_messages.Count == 0){ // Store user information and send e-mail to rep
                PasswordGenerator pg = new PasswordGenerator();
                string password = pg.Generate();

                user newUser = new user {
                    username = new_username,
                    password = password,
                    email = email,
                    fname = fname,
                    lname = lname,
                    phone = phone,
                    comments = comments,
                    stateID = stateID,
                    city = city,
                    address = address,
                    dateAdded = DateTime.Now,
                    isDealer = isDealer
                };

                doc_db.users.InsertOnSubmit(newUser);
                try{
                    doc_db.SubmitChanges();
                    Users.AlertRep(newUser);
                    ViewBag.submitted = 1;
                }catch(Exception e){
                    error_messages.Add(e.Message);
                    ViewBag.error_messages = error_messages;

                    // Get the states
                    List<State> states = (from s in doc_db.States
                                          orderby s.abbr
                                          select s).ToList<State>();
                    ViewBag.states = states;
                }

            }else{ // Present error messages to user
                ViewBag.error_messages = error_messages;
                ViewBag.fname = fname;
                ViewBag.lname = lname;
                ViewBag.new_username = new_username;
                ViewBag.email = email;
                ViewBag.address = address;
                ViewBag.phone = phone;
                ViewBag.city = city;
                ViewBag.stateID = stateID;
                ViewBag.comments = comments;
                ViewBag.isDealer = isDealer;

                // Get the states
                List<State> states = (from s in doc_db.States
                                      orderby s.abbr
                                      select s).ToList<State>();
                ViewBag.states = states;

            }

            return View();
        }
        public string DeleteItemCategory(int cat_id, int item_id)
        {
            string error = "";
            DocsLinqDataContext doc_db = new DocsLinqDataContext();
            if (cat_id > 0 && item_id > 0) {
                try{
                    cat_item cat = new cat_item();
                    cat = (from ci in doc_db.cat_items
                           where ci.catID.Equals(cat_id) && ci.itemID.Equals(item_id)
                           select ci).Single<cat_item>();
                    doc_db.cat_items.DeleteOnSubmit(cat);
                    doc_db.SubmitChanges();

                }catch(Exception e){
                    error = e.Message;
                }
            } else {
                error = "Error: Unsatisfied data.";
            }

            return error;
        }
        public string AddItemCategory(int cat_id, int item_id)
        {
            string error = "";
            if (cat_id > 0 && item_id > 0) {
                try {
                    DocsLinqDataContext doc_db = new DocsLinqDataContext();
                    cat_item newCatItem = new cat_item {
                        catID = cat_id,
                        itemID = item_id
                    };
                    doc_db.cat_items.InsertOnSubmit(newCatItem);
                    doc_db.SubmitChanges();
                } catch (Exception e) {
                    error = e.Message;
                }

            } else {
                error = "Error: Unsatisfied data.";
            }
            return error;
        }
        public ActionResult Index(string username, string password, string rememberMe = "", string redirectUrl = "")
        {
            // Make sure the user entered a password.
            if (password.Trim().Length == 0) {
                ViewBag.Message = "You must enter a password.";
                return View();
            }

            DocsLinqDataContext doc_db = new DocsLinqDataContext();
            user login_user = new user();
            login_user = (from u in doc_db.users
                               where u.username.Equals(username)
                               select u).FirstOrDefault();
            if (login_user == null) {
                ViewBag.Message = "Username was not found in our database";
                return View();
            }

            if (password.Trim() != login_user.password) {
                ViewBag.Message = "Username/password was incorrect.";
                return View();
            } else {
                // User login successful: assign Session data and redirect.
                Session["userID"]       = login_user.userID;
                Session["username"]     = login_user.username;
                Session["superUser"]    = login_user.superUser;
                Session["name"]         = login_user.fname + " " + login_user.lname;

                if (rememberMe == "1") {
                    HttpCookie userID = new HttpCookie("userID");
                    userID.Value = login_user.userID + "";
                    userID.Expires = DateTime.Now.AddDays(30);
                    Response.Cookies.Add(userID);

                    HttpCookie cookie_username = new HttpCookie("username");
                    cookie_username.Value = login_user.username;
                    cookie_username.Expires = DateTime.Now.AddDays(30);
                    Response.Cookies.Add(cookie_username);

                    HttpCookie superUser = new HttpCookie("superUser");
                    superUser.Value = login_user.superUser + "";
                    superUser.Expires = DateTime.Now.AddDays(30);
                    Response.Cookies.Add(superUser);

                    HttpCookie name = new HttpCookie("name");
                    name.Value = login_user.fname + " " + login_user.lname;
                    name.Expires = DateTime.Now.AddDays(30);
                    Response.Cookies.Add(name);
                }

                if (redirectUrl == "") { // Redirect to admin section
                    return RedirectToAction("Index","home");
                } else {
                    Response.Redirect(redirectUrl);
                }
            }
            ViewBag.Message = "There was error while logging you in, my bad!";
            return View();
        }
        /// <summary>
        /// Sign up for a new account.
        /// </summary>
        /// <returns>Sign up page.</returns>
        public ActionResult Signup()
        {
            DocsLinqDataContext doc_db = new DocsLinqDataContext();
            List<State> states = (from s in doc_db.States
                                  orderby s.abbr
                                  select s).ToList<State>();
            ViewBag.states = states;
            ViewBag.stateID = 0;
            ViewBag.submitted = 0;

            return View();
        }
        public ActionResult EditCategory(string cat_id)
        {
            DocsLinqDataContext doc_db = new DocsLinqDataContext();
            int catID = Convert.ToInt32(cat_id);

            // Get all categories
            List<docCategory> categories = (from cats in doc_db.docCategories
                                         orderby cats.catName
                                            select cats).ToList<docCategory>();
            ViewBag.categories = categories;

            // Get the category to be updated
            docCategory cat = new docCategory();
            cat = (from c in doc_db.docCategories
                   where c.catID.Equals(catID)
                   select c).FirstOrDefault<docCategory>();
            ViewBag.cat = cat;

            return View();
        }
        public ActionResult AddItem(string itemName)
        {
            itemName = Request.Form["itemName"].Trim();
            string itemDescription = Request.Form["itemDescription"].Trim();
            string executionExample = Request.Form["executionExample"].Trim();
            string resultExample = Request.Form["resultExample"].Trim();
            string codeLink = Request.Form["codeLink"].Trim();
            int author = Convert.ToInt32(Request.Form["author"].Trim());
            string itemHTML = Request.Form["html"].Trim();
            List<string> catArray = new List<string>();
            catArray = (Request.Form["cat"] != null)?Request.Form["cat"].Trim().Split(',').ToList<string>():new List<string>();
            int item_id = 0;

            // Validate the fields
            List<string> error_messages = new List<string>();
            DocsLinqDataContext doc_db = new DocsLinqDataContext();
            if (itemName.Length == 0) { error_messages.Add("You must enter a name for this item."); }
            if (itemDescription.Length == 0) { error_messages.Add("You must enter a brief overview of this item."); }
            //if (catArray.Count == 0) { error_messages.Add("You did not specify a category for this item."); }

            if (error_messages.Count == 0) { // Add new item to database

                // Create new itemDoc object
                docItem item = new docItem {
                    itemName = itemName,
                    itemDescription = itemDescription,
                    executionExample = executionExample,
                    resultExample = resultExample,
                    codeLink = codeLink,
                    dateModified = DateTime.Now,
                    author = author,
                    itemHTML = itemHTML
                };
                doc_db.docItems.InsertOnSubmit(item);
                item_id = item.itemID;
                try { // Commit new item

                    doc_db.SubmitChanges();

                    // Get the itemID of the newly created entry
                    int itemID = item.itemID;

                    // Now we need to associate this item with the selected categories
                    if (catArray.Count > 0) {
                        foreach (string cat in catArray) {
                            if (cat.Trim().Length > 0) {
                                cat_item ci = new cat_item {
                                    itemID = itemID,
                                    catID = Convert.ToInt32(cat)
                                };
                                doc_db.cat_items.InsertOnSubmit(ci);
                            }
                        }
                    }

                    try { // Commit cat_items and redirect
                        doc_db.SubmitChanges();
                        return RedirectToAction("Items");
                    } catch (Exception e) {
                        error_messages.Add(e.Message);
                    }

                } catch (Exception e) {
                    error_messages.Add(e.Message);
                }
            }

            // Store the fields in the ViewBag
            ViewBag.itemName = itemName;
            ViewBag.itemDescription = itemDescription;
            ViewBag.executionExample = executionExample;
            ViewBag.resultExample = resultExample;
            ViewBag.codeLink = codeLink;
            ViewBag.author = author;
            ViewBag.itemHTML = itemHTML;
            ViewBag.error_messages = error_messages;

            // Get all of the categories
            List<docCategory> categories = Documentation.GetCategories();
            ViewBag.categories = categories;

            // get all of the users ::: this will allow us to designate the author of the new item
            List<user> users = Users.GetAllUsers();
            ViewBag.users = users;

            return View();
        }
        public ActionResult EditCategory(string cat_id, string catName)
        {
            DocsLinqDataContext doc_db = new DocsLinqDataContext();
            int catID = Convert.ToInt32(cat_id);
            catName = Request.Form["catName"].Trim();
            int parentID = Convert.ToInt32(Request.Form["parentID"].Trim());
            string comments = Request.Form["comments"];

            // Initiate error messages list
            List<string> error_messages = new List<string>();

            // validate category info
            if (catName.Length == 0) { error_messages.Add("Category name is required."); }

            // Get the category to be updated
            docCategory cat = new docCategory();
            cat = (from c in doc_db.docCategories
                   where c.catID.Equals(catID)
                   select c).FirstOrDefault<docCategory>();

            if (error_messages.Count == 0) { // Attempt to save category
                cat.catName = catName;
                cat.parentID = parentID;
                cat.comments = comments;

                try {
                    doc_db.SubmitChanges();
                    return RedirectToAction("Index");
                } catch (Exception e) {
                    error_messages.Add(e.Message);
                }
            }

            // Get all categories
            List<docCategory> categories = (from cats in doc_db.docCategories
                                         orderby cats.catName
                                            select cats).ToList<docCategory>();
            ViewBag.categories = categories;

            ViewBag.cat = cat;
            ViewBag.error_messages = error_messages;

            return View();
        }