Example #1
0
        /// <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;
            }
        }
        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();
        }
 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();
        }
        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 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();
        }
Example #8
0
        public ActionResult Add(string username)
        {
            DocsLinqDataContext doc_db = new DocsLinqDataContext();

            username = Request.Form["username"].Trim();
            string password1 = Request.Form["password1"].Trim();
            string password2 = Request.Form["password2"].Trim();
            string email = Request.Form["email"].Trim();
            string fname = Request.Form["fname"].Trim();
            string lname = Request.Form["lname"].Trim();
            string website = Request.Form["website"].Trim();
            string phone = Request.Form["phone"].Trim();
            string fax = Request.Form["fax"].Trim();
            string comments = Request.Form["comments"].Trim();
            string biography = Request.Form["biography"].Trim();
            string photo = Request.Form["photo"].Trim();

            // Determine if the user is marked as active
            int isActive = 0;
            if (Request.Form["isActive"] != null) {
                isActive = Convert.ToInt32(Request.Form["isActive"].Trim());
            }

            // Are we going to assign super user privilages?
            int superUser = 0;
            if (Request.Form["superUser"] != null) {
                superUser = Convert.ToInt32(Request.Form["superUser"].Trim());
            }

            // Compile the selected modules
            List<string> selected_modules = new List<string>();
            if (Request.Form["module"] != null) {
                selected_modules = Request.Form["module"].Split(',').ToList<string>();
            }

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

            // Make sure passwords match
            if (password1 != password2) { error_messages.Add("Passwords do not match."); }

            // Make sure password is longer than 8 characters
            if (password1.Length < 8) { error_messages.Add("Password must be at least 8 characters."); }

            // Make sure username is longer than 8 characters
            if (username.Length < 8) { error_messages.Add(" Username must be at least 8 characters."); }

            // Make sure they entered an e-mail
            if (email.Trim().Length < 5) { error_messages.Add("You must enter a valid e-mail address"); }

            // We need to check the database to make sure we don't have a user with this username or e-mail
            int username_count = (from u in doc_db.users
                             where u.username.Equals(username)
                             select u).Count();
            int email_count = (from u in doc_db.users
                               where u.email.Equals(email)
                               select u).Count();
            if (username_count > 0) { error_messages.Add("The username already exists."); }
            if (email_count > 0) { error_messages.Add("The e-mail is already in use by another user."); }

            #region
            if (error_messages.Count == 0) { // No errors found

                // Create new user
                user newUser = new user {
                    username = username,
                    password = password1,
                    email = email,
                    fname = fname,
                    lname = lname,
                    website = website,
                    phone = phone.Replace("-", ""),
                    fax = fax.Replace("-", ""),
                    isActive = isActive,
                    comments = comments,
                    dateAdded = DateTime.Now,
                    superUser = superUser,
                    biography = biography,
                    photo = photo
                };
                doc_db.users.InsertOnSubmit(newUser);

                // Submit new user to database
                try {

                    doc_db.SubmitChanges(); // Commit new user

                    // Now we have to insert the modules for this user

                    int userId = newUser.userID; // Get ther userID for the new user

                    // Step through the select modules and insert to database
                    foreach (string moduleId in selected_modules) {
                        user_module newUser_module = new user_module {
                            userID = userId,
                            moduleID = Convert.ToInt32(moduleId)
                        };
                        doc_db.user_modules.InsertOnSubmit(newUser_module);
                    }

                    // Attempt to commit user modules
                    try {
                        doc_db.SubmitChanges();

                        if (isActive == 1) { // Send user e-mail message letting them know their account is active
                            Users.AlertNewUser(userId);
                        }
                        return RedirectToAction("Index");
                    } catch (Exception e) {
                        error_messages.Add(e.Message);

                    }
                    ViewBag.selected_modules = selected_modules;
                    ViewBag.error_messages = error_messages;
                } catch (Exception e) { // Something went wrong while saving

                    error_messages.Add(e.Message);
                    ViewBag.selected_modules = selected_modules;
                    ViewBag.error_messages = error_messages;

                }

            } else { // There were errors so we will store all entered data into the ViewBag so the user doesn't have to retype.

                ViewBag.username = username;
                ViewBag.email = email;
                ViewBag.fname = fname;
                ViewBag.lname = lname;
                ViewBag.website = website;
                ViewBag.phone = phone.Replace("-", "");
                ViewBag.fax = fax.Replace("-", "");
                ViewBag.isActive = isActive;
                ViewBag.superUser = superUser;
                ViewBag.comments = comments;
                ViewBag.biography = biography;
                ViewBag.photo = photo;
                ViewBag.selected_modules = selected_modules;
                ViewBag.error_messages = error_messages;
            }
            #endregion

            // Get the modules for the logged in user
            List<module> modules = Users.GetUserModules(Convert.ToInt32(Session["userID"]));
            ViewBag.modules = modules;

            // Get all the admin modules
            List<module> allmodules = Users.GetAllModules();
            ViewBag.allmodules = allmodules;

            List<user> users = Users.GetAllUsers();
            ViewBag.users = users;

            return View();
        }
        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();
        }
Example #11
0
        /// <summary>
        /// This will update the active/isactive status of the user.
        /// </summary>
        /// <param name="userID">ID of the user.</param>
        /// <returns>True/False</returns>
        public static Boolean Set_isActive(int userID)
        {
            try {
                DocsLinqDataContext doc_db = new DocsLinqDataContext();
                user u = (from users in doc_db.users
                          where users.userID.Equals(userID)
                          select users).FirstOrDefault<user>();

                int old_status = u.isActive;
                u.isActive = (u.isActive == 0)?1:0;
                int new_status = u.isActive;

                if (new_status == 1 && old_status == 0) {
                    AlertNewUser(userID);
                }

                doc_db.SubmitChanges();
                return true;
            } catch (Exception e) {
                error_message = e.Message;
                return false;
            }
        }
Example #12
0
        /*** AJAX Functions ***/
        /// <summary>
        /// Delete a given user from the system.
        /// </summary>
        /// <param name="userID">ID of the user.</param>
        /// <returns>True/False</returns>
        public static Boolean DeleteUser(int userID)
        {
            try {
                DocsLinqDataContext doc_db = new DocsLinqDataContext();
                user u = (from users in doc_db.users
                          where users.userID.Equals(userID)
                          select users).FirstOrDefault<user>();
                doc_db.users.DeleteOnSubmit(u);
                doc_db.SubmitChanges();
                return true;
            } catch (Exception e) {
                error_message = e.Message;
                return false;

            }
        }
Example #13
0
        /// <summary>
        /// Removes the item.
        /// </summary>
        /// <param name="itemID">The item ID.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static string RemoveItem(int itemID)
        {
            string error = "";
            try {
                DocsLinqDataContext doc_db = new DocsLinqDataContext();

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

                // Get the category entrees for this item and remove them
                List<cat_item> item_cats = (from ci in doc_db.cat_items
                                            where ci.itemID.Equals(item.itemID)
                                            select ci).ToList<cat_item>();
                foreach (cat_item cat in item_cats) {
                    doc_db.cat_items.DeleteOnSubmit(cat);
                }

                // Get the document entrees for this item and remove them [itemDoc]
                List<itemDoc> item_docs = (from id in doc_db.itemDocs
                                           where id.itemID.Equals(item.itemID)
                                           select id).ToList<itemDoc>();
                foreach (itemDoc doc in item_docs) {
                    doc_db.itemDocs.DeleteOnSubmit(doc);
                }

                // Get the comments on this item and remove them [itemComments]
                List<itemComment> comments = (from ic in doc_db.itemComments
                                                  where ic.itemID.Equals(item.itemID)
                                                  select ic).ToList<itemComment>();
                foreach (itemComment comment in comments) {
                    doc_db.itemComments.DeleteOnSubmit(comment);
                }

                doc_db.SubmitChanges(); // Commit all changes
            } catch (Exception e) {
                error = e.Message;
            }
            return error;
        }
Example #14
0
        public ActionResult Index(string username)
        {
            DocsLinqDataContext doc_db  = new DocsLinqDataContext();
            int userID                  = Convert.ToInt32(Session["userID"]);
            string password1            = Request.Form["password1"].Trim();
            string password2            = Request.Form["password2"].Trim();
            string email                = Request.Form["email"].Trim();
            string fname                = Request.Form["fname"].Trim();
            string lname                = Request.Form["lname"].Trim();
            string website              = Request.Form["website"].Trim();
            string phone                = Request.Form["phone"].Trim().Replace("-","");
            string fax                  = Request.Form["fax"].Trim().Replace("-", "");
            string address              = Request.Form["address"].Trim();
            string city                 = Request.Form["city"].Trim();
            string biography            = Request.Form["biography"].Trim();
            string photo                = Request.Form["photo"].Trim();
            int stateID                 = Convert.ToInt32(Request.Form["stateID"].Trim());

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

            if (password1.Length == 0) { error_messages.Add("Password must be at least 8 characters."); }
            if (password1 != password2) { error_messages.Add("Passwords must match."); }
            if (email.Length < 5) { error_messages.Add("E-mail is required."); }

            // Get the users information
            user u = new user();
            u = (from users in doc_db.users
                 where users.userID.Equals(userID)
                 select users).FirstOrDefault<user>();

            if (error_messages.Count == 0) { // Save the user's information

                u.password  = password1;
                u.email     = email;
                u.fname     = fname;
                u.lname     = lname;
                u.website   = website;
                u.phone     = phone;
                u.fax       = fax;
                u.address   = address;
                u.city      = city;
                u.stateID   = stateID;
                u.biography = biography;
                u.photo     = photo;

                try { // Attempt to update the users information
                    doc_db.SubmitChanges();
                } catch (Exception e) {
                    error_messages.Add(e.Message);
                }
            }

            // 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;

            ViewBag.u = u;
            ViewBag.error_messages = error_messages;

            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 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();
        }
Example #17
0
 public string Remove(int resourceID = 0)
 {
     string response = "";
     try {
         DocsLinqDataContext db = new DocsLinqDataContext();
         resource_listing listing = (from r in db.resource_listings
                                     where r.resourceID.Equals(resourceID)
                                     select r).FirstOrDefault<resource_listing>();
         db.resource_listings.DeleteOnSubmit(listing);
         db.SubmitChanges();
     } catch (Exception e) {
         response = e.Message;
     }
     return response;
 }
Example #18
0
 public string RemoveUserFromResource(int resourceID = 0, int userID = 0)
 {
     string response = "";
     try {
         DocsLinqDataContext db = new DocsLinqDataContext();
         resource_user ru = (from r in db.resource_users
                             where r.resourceID.Equals(resourceID) && r.userID.Equals(userID)
                             select r).FirstOrDefault<resource_user>();
         db.resource_users.DeleteOnSubmit(ru);
         db.SubmitChanges();
     } catch (Exception e) {
         response = e.Message;
     }
     return response;
 }
Example #19
0
        public string Update(int resourceID = 0, string name = "", string url = "", string username = "", string password = "", string comments = "")
        {
            string response = "";
            try {
                DocsLinqDataContext db = new DocsLinqDataContext();
                resource_listing listing = (from r in db.resource_listings
                                            where r.resourceID.Equals(resourceID)
                                            select r).FirstOrDefault<resource_listing>();
                listing.resource_name = name;
                listing.resource_url = url;
                listing.username = username;
                listing.password = password;
                listing.comments = comments;

                db.SubmitChanges();

                JavaScriptSerializer js = new JavaScriptSerializer();
                response = js.Serialize(listing);
            } catch (Exception e) {
                response = "{\"error\":\"" + e.Message + "\"]";
            }
            return response;
        }
        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();
        }
Example #21
0
        public ActionResult Edit(string user_id, string username)
        {
            DocsLinqDataContext doc_db = new DocsLinqDataContext();

            // Convert the user_id into an integer and make sure it's valid
            int userID = Convert.ToInt32(user_id);
            if (userID == 0) {
                return RedirectToAction("Index");
            }

            // Declare a List object to hold error messages
            List<string> error_messages = new List<string>();

            username = Request.Form["username"].Trim();
            string password1 = Request.Form["password1"].Trim();
            string password2 = Request.Form["password2"].Trim();
            string email = Request.Form["email"].Trim();
            string fname = Request.Form["fname"].Trim();
            string lname = Request.Form["lname"].Trim();
            string website = Request.Form["website"].Trim();
            string phone = Request.Form["phone"].Trim();
            string fax = Request.Form["fax"].Trim();
            string comments = Request.Form["comments"].Trim();
            string biography = Request.Form["biography"].Trim();
            string photo = Request.Form["photo"].Trim();

            int isActive = 0;
            if (Request.Form["isActive"] != null) {
                isActive = Convert.ToInt32(Request.Form["isActive"].Trim());
            }

            int superUser = 0;
            if (Request.Form["superUser"] != null) {
                superUser = Convert.ToInt32(Request.Form["superUser"]);
            }

            // Make sure passwords match
            if (password1 != password2) { error_messages.Add("Passwords do not match."); }

            // Make sure password is longer than 8 characters
            if (password1.Length < 4) { error_messages.Add("Password is not long enough. Shoot for 8 characters."); }

            // Make sure username is longer than 8 characters
            if (username.Length < 4) { error_messages.Add(" Username is not long enough. Shoot for 8 characters."); }

            // Make sure they entered an e-mail
            if (email.Trim().Length < 5) { error_messages.Add("You must enter a valid e-mail address"); }

            // Get the user's information
            user u = (from users in doc_db.users
                      where users.userID.Equals(user_id)
                      select users).FirstOrDefault<user>();

            int old_isActive = u.isActive;
            int new_isActive = isActive;

            if (error_messages.Count == 0) {
                u.username = username;
                u.password = password1;
                u.email = email;
                u.fname = fname;
                u.lname = lname;
                u.website = website;
                u.phone = phone.Replace("-", "");
                u.fax = fax.Replace("-", "");
                u.isActive = isActive;
                u.comments = comments;
                u.superUser = superUser;
                u.biography = biography;
                u.photo = photo;

                // Attempt to save the user
                try {

                    doc_db.SubmitChanges();

                    // Delete all modules for this user
                    List<user_module> users_modules = (from um in doc_db.user_modules
                                                       where um.userID.Equals(userID)
                                                       select um).ToList<user_module>();
                    // Step through the user's modules and remove them all ::: we'll add the ones that are selected in a minute
                    foreach (user_module module in users_modules) {
                        doc_db.user_modules.DeleteOnSubmit(module);
                    }

                    // Compile List of the modules selected for this user
                    List<string> user_selected_modules = new List<string>();
                    if (Request.Form["module"] != null) {
                        user_selected_modules = Request.Form["module"].Split(',').ToList<string>();
                    }

                    // Step through the select modules and insert to database
                    foreach (string moduleId in user_selected_modules) {
                        user_module newUser_module = new user_module {
                            userID = u.userID,
                            moduleID = Convert.ToInt32(moduleId)
                        };
                        doc_db.user_modules.InsertOnSubmit(newUser_module);
                    }

                    // Attempt to commit user modules
                    try {
                        doc_db.SubmitChanges();

                        if (new_isActive == 1 && old_isActive == 0) { // Send user e-mail message letting them know their account is active
                            Users.AlertNewUser(userID);
                        }

                        return RedirectToAction("Index");
                    } catch (Exception e) { // Failed to submit user modules
                        error_messages.Add(e.Message);
                    }
                    ViewBag.error_messages = error_messages;

                } catch (Exception e) { // Failed to save user info

                    error_messages.Add(e.Message);
                }
            }
            ViewBag.error_messages = error_messages;

            // Store the user object in the ViewBag
            ViewBag.u = u;

            // Get the modules for the user we are editing
            List<module> selected_modules = Users.GetUserModules(u.userID);
            ViewBag.selected_modules = selected_modules;

            // Get the modules for the logged in user
            List<module> modules = Users.GetUserModules(Convert.ToInt32(Session["userID"]));
            ViewBag.modules = modules;

            // Get all the modules
            List<module> allmodules = Users.GetAllModules();
            ViewBag.allmodules = allmodules;

            return View();
        }