public static string AddImage(int partID = 0, int sizeid = 0, string webfile = "", string localfile = "") { try { CurtDevDataContext db = new CurtDevDataContext(); JavaScriptSerializer js = new JavaScriptSerializer(); char sort = 'a'; try { sort = db.PartImages.Where(x => x.partID.Equals(partID)).Where(x => x.sizeID.Equals(sizeid)).OrderByDescending(x => x.sort).Select(x => x.sort).First<char>(); sort = GetNextLetter(sort.ToString()); } catch {}; System.Drawing.Image img = System.Drawing.Image.FromFile(localfile); PartImage image = new PartImage { partID = partID, sizeID = sizeid, path = webfile, height = img.Height, width = img.Width, sort = sort }; img.Dispose(); db.PartImages.InsertOnSubmit(image); db.SubmitChanges(); return js.Serialize(image); } catch { return "error"; } }
/// <summary> /// Retrieves a list of DetailedCategories objects /// </summary> /// <returns>List of DetailedCategories objects</returns> public static List<DetailedCategories> GetCategories() { List<DetailedCategories> cats = new List<DetailedCategories>(); CurtDevDataContext db = new CurtDevDataContext(); cats = (from c in db.Categories select new DetailedCategories { catID = c.catID, dateAdded = c.dateAdded, parentID = c.parentID, parentCat = (from c2 in db.Categories where c2.catID.Equals(c.parentID) select c2.catTitle).FirstOrDefault<string>(), catTitle = c.catTitle, shortDesc = c.shortDesc, longDesc = c.longDesc, image = c.image, isLifestyle = c.isLifestyle, vehicleSpecific = c.vehicleSpecific, partCount = (from p in db.Parts join cp in db.CatParts on p.partID equals cp.partID where cp.catID.Equals(c.catID) select p).Distinct().Count(), content = (from cb in db.ContentBridges join co in db.Contents on cb.contentID equals co.contentID join ct in db.ContentTypes on co.cTypeID equals ct.cTypeID where cb.catID.Equals(c.catID) orderby co.cTypeID select new FullContent { content_type_id = co.cTypeID, content_type = ct.type, contentID = co.contentID, content = co.text }).ToList<FullContent>() }).Distinct().OrderBy(x => x.catTitle).ToList<DetailedCategories>(); return cats; }
public ActionResult AddNews(int displayOrder = 0, string title = "", string pageContent = "", string subTitle = "", string isActive = "", string showDealers = "", string showPublic = "") { try { TechNews item = new TechNews(); Boolean blnIsActive = false; blnIsActive = (isActive == "on") ? true : false; Boolean blnShowPublic = false; blnShowPublic = (showPublic == "on") ? true : false; Boolean blnShowDealers = false; blnShowDealers = (showDealers == "on") ? true : false; item.title = title; item.pageContent = pageContent; item.subTitle = subTitle; item.displayOrder = displayOrder; item.active = blnIsActive; item.showDealers = blnShowDealers; item.showPublic = blnShowPublic; item.dateModified = DateTime.Now; ViewBag.item = item; CurtDevDataContext db = new CurtDevDataContext(); db.TechNews.InsertOnSubmit(item); db.SubmitChanges(); return RedirectToAction("News", new { successMsg = "The news item was successfully added." }); } catch (Exception e) { ViewBag.error = "Could not add news item: " + e.Message; } return View(); }
public static void generateCustomAPIKey(Guid userID, List<string> selectedModuleIDs) { CurtDevDataContext db = new CurtDevDataContext(); // create API Key with custom type ApiKey customKey = new ApiKey(); customKey.id = Guid.NewGuid(); customKey.api_key = Guid.NewGuid(); customKey.type_id = db.ApiKeyTypes.Where(x => x.type == "Custom").Select(x => x.id).FirstOrDefault<Guid>(); customKey.user_id = userID; customKey.date_added = DateTime.Now; db.ApiKeys.InsertOnSubmit(customKey); db.SubmitChanges(); // create record for each selected module ID in the APIAcess table List<ApiAccess> listOfNewAPIAccesses = new List<ApiAccess>(); foreach (string modID in selectedModuleIDs) { ApiAccess apiAccess = new ApiAccess(); apiAccess.id = Guid.NewGuid(); apiAccess.key_id = customKey.id; apiAccess.module_id = new Guid(modID); listOfNewAPIAccesses.Add(apiAccess); } db.ApiAccesses.InsertAllOnSubmit(listOfNewAPIAccesses); db.SubmitChanges(); // submit changes }
public static PostWithCategories Get(string date = "", string title = "") { try { DateTime post_date = Convert.ToDateTime(date); CurtDevDataContext db = new CurtDevDataContext(); PostWithCategories post = new PostWithCategories(); post = (from p in db.BlogPosts where p.slug.Equals(title) && Convert.ToDateTime(p.publishedDate).Day.Equals(post_date.Day) && Convert.ToDateTime(p.publishedDate).Year.Equals(post_date.Year) && Convert.ToDateTime(p.publishedDate).Month.Equals(post_date.Month) select new PostWithCategories { blogPostID = p.blogPostID, post_title = p.post_title, post_text = p.post_text, slug = p.slug, publishedDate = p.publishedDate, createdDate = p.createdDate, lastModified = p.lastModified, meta_title = p.meta_title, meta_description = p.meta_description, active = p.active, author = GetAuthor(p.userID), categories = (from c in db.BlogCategories join pc in db.BlogPost_BlogCategories on c.blogCategoryID equals pc.blogCategoryID where pc.blogPostID.Equals(p.blogPostID) select c).ToList<BlogCategory>(), comments = (from cm in db.Comments where cm.blogPostID.Equals(p.blogPostID) && cm.active.Equals(true) && cm.approved.Equals(true) select cm).ToList<Comment>() }).First<PostWithCategories>(); return post; } catch (Exception e) { return new PostWithCategories(); } }
public static List<FullVehicle> FindVehicles(string term = "") { List<FullVehicle> vehicles = new List<FullVehicle>(); CurtDevDataContext db = new CurtDevDataContext(); double query_year = 0; Double.TryParse(term, out query_year); vehicles = (from v in db.Vehicles join y in db.Years on v.yearID equals y.yearID join ma in db.Makes on v.makeID equals ma.makeID join mo in db.Models on v.modelID equals mo.modelID join s in db.Styles on v.styleID equals s.styleID where s.style1.Contains(term) || mo.model1.Contains(term) || ma.make1.Contains(term) || y.year1.Equals(query_year) orderby v.vehicleID select new FullVehicle { vehicleID = v.vehicleID, yearID = v.yearID, makeID = v.makeID, modelID = v.modelID, styleID = v.styleID, aaiaID = s.aaiaID, year = y.year1, make = ma.make1, model = mo.model1, style = s.style1 }).ToList<FullVehicle>(); return vehicles; }
public ContentPage Get(string name = "", int menuid = 0, bool authenticated = false) { ContentPage content = new ContentPage(); try { CurtDevDataContext db = new CurtDevDataContext(); content = (from s in db.SiteContents where s.slug == name && s.published == true && s.active == true && s.websiteID.Equals(this.websiteID) select new ContentPage { contentID = s.contentID, page_title = s.page_title, content_type = s.content_type, lastModified = s.lastModified, createdDate = s.createdDate, published = s.published, meta_title = s.meta_title, meta_description = s.meta_description, keywords = s.keywords, canonical = s.canonical, active = s.active, isPrimary = s.isPrimary, slug = s.slug, requireAuthentication = s.requireAuthentication, revision = (db.SiteContentRevisions.Where(x => x.contentID == s.contentID).Where(x => x.active == true).First<SiteContentRevision>()), menu = new MenuModel().GetByContentID(s.contentID, menuid, authenticated) }).First<ContentPage>(); return content; } catch (Exception e) { return content; } }
public static DealerLocation GetDealerLocation(int locationID = 0) { CurtDevDataContext db = new CurtDevDataContext(); DealerLocation location = new DealerLocation(); try { location = (from cl in db.CustomerLocations join c in db.Customers on cl.cust_id equals c.cust_id join dt in db.DealerTypes on c.dealer_type equals dt.dealer_type join dtr in db.DealerTiers on c.tier equals dtr.ID where cl.locationID.Equals(locationID) select new DealerLocation { State = cl.State, customername = c.name, dealerType = dt, dealerTier = dtr, locationID = cl.locationID, name = cl.name, address = cl.address, city = cl.city, stateID = cl.stateID, postalCode = cl.postalCode, email = cl.email, phone = cl.phone, fax = cl.fax, latitude = cl.latitude, longitude = cl.longitude, cust_id = cl.cust_id, isprimary = cl.isprimary, contact_person = cl.contact_person, websiteurl = (c.eLocalURL == null || c.eLocalURL.Trim() == "") ? ((c.website == null || c.website.Trim() == "") ? "" : c.website) : c.eLocalURL, showWebsite = c.showWebsite }).FirstOrDefault<DealerLocation>(); } catch { }; return location; }
public static CommentWithPost Get(int id = 0) { try { CurtDevDataContext db = new CurtDevDataContext(); CommentWithPost comment = new CommentWithPost(); comment = (from c in db.Comments where c.commentID.Equals(id) select new CommentWithPost { commentID = c.commentID, blogPostID = c.blogPostID, name = c.name, email = c.email, comment_text = c.comment_text, createdDate = c.createdDate, approved = c.approved, active = c.active, post = (from p in db.BlogPosts where p.blogPostID.Equals(c.blogPostID) select p).First<BlogPost>() }).First<CommentWithPost>(); return comment; } catch (Exception e) { return new CommentWithPost(); } }
public static FullFile Get(int id = 0) { FullFile file = new FullFile(); try { CurtDevDataContext db = new CurtDevDataContext(); file = (from f in db.Files where f.fileID.Equals(id) orderby f.createdDate descending select new FullFile { fileID = f.fileID, name = f.name, path = f.path, height = f.height, width = f.width, size = f.size, createdDate = f.createdDate, created = String.Format("{0:ddd, dd MMM yyyy HH:mm:ss}", f.createdDate), fileGalleryID = f.fileGalleryID, fileExtID = f.fileExtID, extension = (from fe in db.FileExts where fe.fileExtID.Equals(f.fileExtID) select new FileExtension { fileExtID = fe.fileExtID, fileExt1 = fe.fileExt1, fileExtIcon = fe.fileExtIcon, fileTypeID = fe.fileTypeID, FileType = db.FileTypes.Where(x => x.fileTypeID.Equals(fe.fileTypeID)).FirstOrDefault<FileType>() }).First<FileExtension>() }).FirstOrDefault<FullFile>(); } catch (Exception e) { } return file; }
public static List<FullFile> GetAll() { List<FullFile> images = new List<FullFile>(); try { CurtDevDataContext db = new CurtDevDataContext(); images = (from f in db.Files orderby f.name, f.createdDate descending select new FullFile { fileID = f.fileID, name = f.name, path = f.path, height = f.height, width = f.width, size = f.size, createdDate = f.createdDate, fileGalleryID = f.fileGalleryID, fileExtID = f.fileExtID, extension = (from fe in db.FileExts where fe.fileExtID.Equals(f.fileExtID) select new FileExtension { fileExtID = fe.fileExtID, fileExt1 = fe.fileExt1, fileExtIcon = fe.fileExtIcon, fileTypeID = fe.fileTypeID, FileType = db.FileTypes.Where(x => x.fileTypeID.Equals(fe.fileTypeID)).FirstOrDefault<FileType>() }).First<FileExtension>() }).ToList<FullFile>(); } catch (Exception e) { } return images; }
public static FullVideo Create(Google.YouTube.Video ytVideo = null) { if (ytVideo == null) { throw new Exception("Invalid link"); } CurtDevDataContext db = new CurtDevDataContext(); Video new_video = new Video { embed_link = ytVideo.VideoId, title = ytVideo.Title, screenshot = (ytVideo.Thumbnails.Count > 0) ? ytVideo.Thumbnails[2].Url : "/Content/img/noimage.jpg", description = ytVideo.Description, watchpage = ytVideo.WatchPage.ToString(), youtubeID = ytVideo.VideoId, dateAdded = DateTime.Now, sort = (db.Videos.Count() == 0) ? 1 : db.Videos.OrderByDescending(x => x.sort).Select(x => x.sort).First() + 1 }; db.Videos.InsertOnSubmit(new_video); db.SubmitChanges(); FullVideo fullvideo = new FullVideo { videoID = new_video.videoID, embed_link = new_video.embed_link, dateAdded = new_video.dateAdded, sort = new_video.sort, videoTitle = new_video.title, thumb = (ytVideo.Thumbnails.Count > 0) ? ytVideo.Thumbnails[0].Url : "/Content/img/noimage.jpg" }; return fullvideo; }
public static List<Archive> GetMonths() { try { CurtDevDataContext db = new CurtDevDataContext(); List<Archive> archives = new List<Archive>(); archives = (from p in db.BlogPosts where p.publishedDate.Value != null && p.publishedDate.Value <= DateTime.Now && p.active.Equals(true) orderby p.publishedDate.Value.Year descending, p.publishedDate.Value.Month descending select new Archive { monthnum = Convert.ToInt16(Convert.ToDateTime(p.publishedDate).Month.ToString()), month = Convert.ToDateTime(p.publishedDate).Month.ToString(), year = Convert.ToDateTime(p.publishedDate).Year.ToString() }).Distinct().ToList<Archive>(); archives = (from a in archives orderby a.year descending, a.monthnum select a).Distinct().ToList<Archive>(); return archives; } catch { return new List<Archive>(); } }
public ActionResult Save(int id = 0, string question = "", string answer = "") { try { if (question.Length == 0) { throw new Exception("You must enter a question"); } if (answer.Length == 0) { throw new Exception("You must enter an answer"); } CurtDevDataContext db = new CurtDevDataContext(); if (id == 0) { FAQ faq = new FAQ { answer = answer, question = question }; db.FAQs.InsertOnSubmit(faq); } else { FAQ faq = db.FAQs.Where(x => x.faqID == id).FirstOrDefault<FAQ>(); faq.question = question; faq.answer = answer; } db.SubmitChanges(); return RedirectToAction("Index"); } catch (Exception e) { if (id == 0) { return RedirectToAction("Add", new { err = e.Message, q = question, a = answer }); } else { return RedirectToAction("Edit", new { id = id, err = e.Message, q = question, a = answer }); } } }
public static string DeleteCustomer(int id) { try { CurtDevDataContext db = new CurtDevDataContext(); // Delete any pricing entries for this customer List<CustomerPricing> prices = new List<CustomerPricing>(); prices = (from cp in db.CustomerPricings where cp.cust_id.Equals(id) select cp).ToList<CustomerPricing>(); db.CustomerPricings.DeleteAllOnSubmit<CustomerPricing>(prices); // Delete all locations for this customer List<CustomerLocation> locations = new List<CustomerLocation>(); locations = (from cl in db.CustomerLocations where cl.cust_id.Equals(id) select cl).ToList<CustomerLocation>(); db.CustomerLocations.DeleteAllOnSubmit<CustomerLocation>(locations); // Delete the customer record Customer cust = new Customer(); cust = (from c in db.Customers where c.cust_id.Equals(id) select c).FirstOrDefault<Customer>(); db.Customers.DeleteOnSubmit(cust); db.SubmitChanges(); return ""; } catch (Exception e) { return "Error while deleting."; } }
public static List<CommentWithPost> GetAll() { try { CurtDevDataContext db = new CurtDevDataContext(); List<CommentWithPost> comments = new List<CommentWithPost>(); comments = (from c in db.Comments where c.active.Equals(true) orderby c.approved, c.createdDate select new CommentWithPost { commentID = c.commentID, blogPostID = c.blogPostID, name = c.name, email = c.email, comment_text = c.comment_text, createdDate = c.createdDate, approved = c.approved, active = c.active, post = (from p in db.BlogPosts where p.blogPostID.Equals(c.blogPostID) select p).First<BlogPost>() }).ToList<CommentWithPost>(); return comments; } catch (Exception e) { return new List<CommentWithPost>(); } }
/// <summary> /// Returns a List of all customers in the database, sorted by name ascending. /// </summary> /// <returns>List of Customer objects.</returns> public static List<FileType> GetAll() { CurtDevDataContext db = new CurtDevDataContext(); List<FileType> types = db.FileTypes.OrderBy(x => x.fileType1).ToList<FileType>(); return types; }
public static PostWithCategories Get(int id = 0) { try { CurtDevDataContext db = new CurtDevDataContext(); PostWithCategories post = new PostWithCategories(); //post = db.Posts.Where(x => x.postID == id).Where(x => x.active == true).FirstOrDefault<Post>(); post = (from p in db.BlogPosts where p.blogPostID.Equals(id) select new PostWithCategories { blogPostID = p.blogPostID, post_title = p.post_title, slug = p.slug, userID = p.userID, post_text = p.post_text, publishedDate = p.publishedDate, createdDate = p.createdDate, lastModified = p.lastModified, keywords = p.keywords, meta_title = p.meta_title, meta_description = p.meta_description, active = p.active, author = GetAuthor(p.userID), categories = (from c in db.BlogCategories join pc in db.BlogPost_BlogCategories on c.blogCategoryID equals pc.blogCategoryID where pc.blogPostID.Equals(p.blogPostID) select c).ToList<BlogCategory>(), comments = (from cm in db.Comments where cm.blogPostID.Equals(p.blogPostID) && cm.approved.Equals(true) && cm.active.Equals(true) select cm).ToList<Comment>(), mod_comments = (from cm in db.Comments where cm.blogPostID.Equals(p.blogPostID) && cm.approved.Equals(false) && cm.active.Equals(true) select cm).ToList<Comment>() }).First<PostWithCategories>(); return post; } catch (Exception e) { return new PostWithCategories(); } }
public static FullVehicle GetFullVehicle(int vehicleID = 0) { CurtDevDataContext db = new CurtDevDataContext(); FullVehicle vehicle = new FullVehicle(); if (vehicleID > 0) { vehicle = (from v in db.Vehicles join y in db.Years on v.yearID equals y.yearID join ma in db.Makes on v.makeID equals ma.makeID join mo in db.Models on v.modelID equals mo.modelID join s in db.Styles on v.styleID equals s.styleID where v.vehicleID.Equals(vehicleID) select new FullVehicle { vehicleID = v.vehicleID, yearID = v.yearID, makeID = v.makeID, modelID = v.modelID, styleID = v.styleID, aaiaID = s.aaiaID, year = y.year1, make = ma.make1, model = mo.model1, style = s.style1 }).FirstOrDefault<FullVehicle>(); } return vehicle; }
public static List<PostWithCategories> GetAll() { try { CurtDevDataContext db = new CurtDevDataContext(); List<PostWithCategories> posts = new List<PostWithCategories>(); posts = (from p in db.BlogPosts where p.active.Equals(true) orderby p.publishedDate, p.createdDate select new PostWithCategories { blogPostID = p.blogPostID, post_title = p.post_title, slug = p.slug, userID = p.userID, post_text = p.post_text, publishedDate = p.publishedDate, createdDate = p.createdDate, lastModified = p.lastModified, meta_title = p.meta_title, meta_description = p.meta_description, active = p.active, author = GetAuthor(p.userID), categories = (from c in db.BlogCategories join pc in db.BlogPost_BlogCategories on c.blogCategoryID equals pc.blogCategoryID where pc.blogPostID.Equals(p.blogPostID) select c).ToList<BlogCategory>(), comments = (from cm in db.Comments where cm.blogPostID.Equals(p.blogPostID) && cm.approved.Equals(true) && cm.active.Equals(true) select cm).ToList<Comment>(), mod_comments = (from cm in db.Comments where cm.blogPostID.Equals(p.blogPostID) && cm.approved.Equals(false) && cm.active.Equals(true) select cm).ToList<Comment>() }).ToList<PostWithCategories>(); return posts; } catch (Exception e) { return new List<PostWithCategories>(); } }
public ContentPage GetPrimary() { ContentPage content = new ContentPage(); try { CurtDevDataContext db = new CurtDevDataContext(); content = (from s in db.SiteContents where s.isPrimary == true && s.websiteID.Equals(this.websiteID) select new ContentPage { contentID = s.contentID, page_title = s.page_title, content_type = s.content_type, lastModified = s.lastModified, createdDate = s.createdDate, published = s.published, meta_title = s.meta_title, meta_description = s.meta_description, canonical = s.canonical, keywords = s.keywords, active = s.active, isPrimary = s.isPrimary, slug = s.slug, requireAuthentication = s.requireAuthentication, revision = (db.SiteContentRevisions.Where(x => x.contentID == s.contentID).Where(x => x.active == true).First<SiteContentRevision>()) }).First<ContentPage>(); return content; } catch { return content; } }
public static bool ForgotPassword(Customer customer) { try { CurtDevDataContext db = new CurtDevDataContext(); SmtpClient SmtpServer = new SmtpClient("mail.curtmfg.com"); SmtpServer.Port = 25; string contactuslink = "http://www.curtmfg.com/Contact"; MailMessage mail = new MailMessage(); mail.From = new MailAddress("*****@*****.**"); mail.To.Add(customer.email); mail.Subject = "CURT Manufacturing - Account Password"; mail.IsBodyHtml = true; string htmlBody = "<p>Hi there,</p>"; htmlBody += "<p>Here is the password for your CURT Manufacturing Dealer Account.</p>"; htmlBody += "<div style='border:2px solid #ccc;display:inline-block;padding:10px;padding-top:0px'>"; htmlBody += "<p><strong>Password:</strong> " + customer.password + "</p></div>"; htmlBody += "<p>Please <a href='" + contactuslink + "'>contact us</a> if you have further questions or problems logging in. Thanks.</p>"; htmlBody += "<p>Sincerely,<br />CURT Support Staff</p>"; mail.Body = htmlBody; SmtpServer.Send(mail); return true; } catch { return false; } }
public ActionResult AddType() { string error = ""; CurtDevDataContext db = new CurtDevDataContext(); #region Form Submission try { if (Request.Form.Count > 0) { // Save form values string fileType = (Request.Form["fileType"] != null) ? Request.Form["fileType"] : ""; // Validate the form fields if (fileType.Length == 0) throw new Exception("Name is required."); // Create the new customer and save FileType new_type = new FileType { fileType1 = fileType }; db.FileTypes.InsertOnSubmit(new_type); db.SubmitChanges(); return RedirectToAction("Types"); } } catch (Exception e) { error = e.Message; } #endregion ViewBag.error = error; return View(); }
public static bool Send(Contact contact) { try { CurtDevDataContext db = new CurtDevDataContext(); SmtpClient SmtpServer = new SmtpClient(); List<ContactReceiver> receivers = (from cr in db.ContactReceivers join crt in db.ContactReceiver_ContactTypes on cr.contactReceiverID equals crt.contactReceiverID join ct in db.ContactTypes on crt.contactTypeID equals ct.contactTypeID where ct.name.ToLower().Trim().Equals(contact.type.ToLower().Trim()) select cr).ToList<ContactReceiver>(); if (receivers.Count() == 0) { receivers = db.ContactReceivers.ToList<ContactReceiver>(); } db.Contacts.InsertOnSubmit(contact); db.SubmitChanges(); foreach (ContactReceiver receiver in receivers) { MailMessage mail = new MailMessage(); mail.To.Add(receiver.email); mail.Subject = "New Website Contact: " + contact.subject; mail.IsBodyHtml = true; string mailhtml = contact.first_name + " " + contact.last_name + " said: " + contact.message; string mailto = "mailto" + ":" + contact.email + "?subject=Re: " + contact.subject + "&body=" + mailhtml; string htmlBody = "<p>Hi " + receiver.first_name + ",</p>"; htmlBody += "<p>We've received a new web contact.<br /><a style=\"border: 2px solid #e64d2d; text-transform: uppercase; color: #e64d2d; font-weight: bold; padding: 2px 6px; font-size: 14px; text-decoration: none;\" href=\"" + mailto + "\">Click to Reply</a></p>"; htmlBody += "<table><tr><td style=\"vertical-align: top;\"><strong>Name: </strong></td><td>" + contact.first_name + " " + contact.last_name + "</td></tr>"; htmlBody += "<tr><td style=\"vertical-align: top;\"><strong>Reason: </strong></td><td>" + contact.type + "</td></tr>"; htmlBody += "<tr><td style=\"vertical-align: top;\"><strong>Email: </strong></td><td>" + contact.email + "</td></tr>"; if (contact.phone != "") { htmlBody += "<tr><td style=\"vertical-align: top;\"><strong>Phone: </strong></td><td>" + contact.phone + "</td></tr>"; } if (contact.address1 != "") { htmlBody += "<tr><td style=\"vertical-align: top;\"><strong>Address1: </strong></td><td>" + contact.address1 + "</td></tr>"; } if (contact.address2 != "") { htmlBody += "<tr><td style=\"vertical-align: top;\"><strong>Address2: </strong></td><td>" + contact.address2 + "</td></tr>"; } if (contact.city != "") { htmlBody += "<tr><td style=\"vertical-align: top;\"><strong>City: </strong></td><td>" + contact.city + "</td></tr>"; } if (contact.state != "") { htmlBody += "<tr><td style=\"vertical-align: top;\"><strong>State / Province: </strong></td><td>" + contact.state + "</td></tr>"; } if (contact.postalcode != "") { htmlBody += "<tr><td style=\"vertical-align: top;\"><strong>Postal Code: </strong></td><td>" + contact.postalcode + "</td></tr>"; } if (contact.country != "") { htmlBody += "<tr><td style=\"vertical-align: top;\"><strong>Country: </strong></td><td>" + contact.country + "</td></tr>"; } htmlBody += "<tr><td style=\"vertical-align: top;\"><strong>Subject: </strong></td><td>" + contact.subject + "</td></tr>"; htmlBody += "<tr><td style=\"vertical-align: top;\"><strong>Message: </strong></td><td>" + contact.message + "</td></tr></table>"; mail.Body = htmlBody; SmtpServer.Send(mail); } return true; } catch { return false; } }
/// <summary> /// Delete the given category from the database and break relationship to any parts. /// </summary> /// <param name="catID">ID of the category</param> /// <returns>Error message (string)</returns> public static string DeleteCategory(int catID = 0) { if (catID == 0) { throw new Exception("There was error while processing. Category data is invalid."); } try { CurtDevDataContext db = new CurtDevDataContext(); Categories cat = (from c in db.Categories where c.catID.Equals(catID) select c).FirstOrDefault<Categories>(); db.Categories.DeleteOnSubmit(cat); List<ContentBridge> bridges = db.ContentBridges.Where(x => x.catID.Equals(catID)).ToList<ContentBridge>(); List<int> contentids = bridges.Select(x => x.contentID).ToList(); List<Content> contents = db.Contents.Where(x => contentids.Contains(x.contentID)).ToList<Content>(); db.ContentBridges.DeleteAllOnSubmit(bridges); db.Contents.DeleteAllOnSubmit(contents); // Remove the CatPart relationships for this category List<CatParts> cp = (from cat_parts in db.CatParts where cat_parts.catID.Equals(catID) select cat_parts).ToList<CatParts>(); db.CatParts.DeleteAllOnSubmit<CatParts>(cp); db.SubmitChanges(); } catch (Exception e) { return e.Message; } return ""; }
// // GET: /Contact/ public ActionResult Index(string page = "contact", string defaultvalue = "") { CurtDevDataContext db = new CurtDevDataContext(); List<string> errors = (List<string>)TempData["errors"]; ViewBag.first_name = ((string)TempData["first_name"] != null) ? (string)TempData["first_name"] : ""; ViewBag.last_name = ((string)TempData["last_name"] != null) ? (string)TempData["last_name"] : ""; ViewBag.email = ((string)TempData["email"] != null) ? (string)TempData["email"] : ""; ViewBag.type = ((string)TempData["type"] != null) ? (string)TempData["type"] : ""; ViewBag.phone = ((string)TempData["phone"] != null) ? (string)TempData["phone"] : ""; ViewBag.address1 = ((string)TempData["address1"] != null) ? (string)TempData["address1"] : ""; ViewBag.address2 = ((string)TempData["address2"] != null) ? (string)TempData["address2"] : ""; ViewBag.city = ((string)TempData["city"] != null) ? (string)TempData["city"] : ""; ViewBag.state = (TempData["state"] != null) ? (int)TempData["state"] : 0; ViewBag.postalcode = ((string)TempData["postalcode"] != null) ? (string)TempData["postalcode"] : ""; ViewBag.subject = ((string)TempData["subject"] != null) ? (string)TempData["subject"] : ""; ViewBag.contactmessage = ((string)TempData["contactmessage"] != null) ? (string)TempData["contactmessage"] : ""; ViewBag.errors = (errors == null) ? new List<string>() : errors; try { ContentPage content = new SiteContentModel().Get(page); ViewBag.content = content; } catch { ViewBag.content = null; } List<FullCountry> countries = DealerModel.GetCountries(); ViewBag.countries = countries; List<ContactType> types = db.ContactTypes.OrderBy(x => x.name).ToList<ContactType>(); ViewBag.types = types; if(ViewBag.type == "") ViewBag.type = defaultvalue; return View(); }
protected override void OnActionExecuting(ActionExecutingContext filterContext) { string key = ""; if (Request.QueryString["key"] != null && Request.QueryString["key"] != "") { key = Request.QueryString["key"]; } if (Request.Form["key"] != null && Request.Form["key"] != "") { key = Request.Form["key"]; } if (key == null || key.Length == 0) { throwError("Invalid API Key"); } else { try { CurtDevDataContext db = new CurtDevDataContext(); string cID = db.Customers.Where(x => x.APIKey.Equals(key)).Select(x => x.customerID).ToString(); if (cID.Length == 0 || cID == "0") { throwError("Invalid API Key"); } } catch (Exception e) { throwError(e.Message); } } base.OnActionExecuting(filterContext); }
public static string AddCategoryToPart(int catID = 0, int partID = 0) { if (catID == 0 || partID == 0) { return "Invalid parameters."; } try { CurtDevDataContext db = new CurtDevDataContext(); // Make sure this category isn't already tied to this product int existing = (from cp in db.CatParts where cp.catID.Equals(catID) && cp.partID.Equals(partID) select cp).Count(); if (existing > 0) { return "The association exists."; } CatParts cat_part = new CatParts { catID = catID, partID = partID }; db.CatParts.InsertOnSubmit(cat_part); db.SubmitChanges(); UpdatePart(partID); } catch (Exception e) { return e.Message; } return ""; }
public static string Save(int pVideoID = 0, int partID = 0, int vTypeID = 0, string video = "", bool isPrimary = false) { CurtDevDataContext db = new CurtDevDataContext(); PartVideo v = new PartVideo(); try { if(pVideoID > 0) { v = db.PartVideos.Where(x => x.pVideoID == pVideoID).First<PartVideo>(); v.video = video; v.isPrimary = isPrimary; v.vTypeID = vTypeID; v.partID = partID; db.SubmitChanges(); } else { v = new PartVideo { isPrimary = isPrimary, vTypeID = vTypeID, video = video, partID = partID }; db.PartVideos.InsertOnSubmit(v); db.SubmitChanges(); } ProductModels.UpdatePart(partID); } catch { return "error"; } return JsonConvert.SerializeObject(Get(v.pVideoID)); }
/// <summary> /// Returns a List of all customers in the database, sorted by name ascending. /// </summary> /// <returns>List of Customer objects.</returns> public static List<Contact> GetAll() { CurtDevDataContext db = new CurtDevDataContext(); List<Contact> contacts = db.Contacts.OrderByDescending(x => x.createdDate).ToList<Contact>(); return contacts; }