public ActionResult MyAccount() { SmartService smartService = new SmartService(); AccountType Account = null; MyAccount MyAccount = new MyAccount(); if (Request.IsAuthenticated) { string key, toHash, token; token = smartService.AuthToken(); if (token == "") { } else { string username = User.Identity.Name; toHash = username.ToUpper() + "|" + token; key = smartService.GetMd5Hash(MD5.Create(), toHash) + "|" + username; Account = smartService.GetAccountDetails(key, username); } MyAccount.firstname = Account.firstname; MyAccount.lastname = Account.surname; MyAccount.email = Account.email; MyAccount.organization = Account.organisation; MyAccount.jobtitle = Account.jobTitle; MyAccount.address = Account.address; MyAccount.number = Account.telephone; MyAccount.password = Account.password; MyAccount.DropDownItems = MyAccount.getCountry(Account.country); MyAccount.sales = Account.emailService; for (var i = 0; i < Account.areasOfInterest.Count(); i++) { MyAccount.data.Add(new UserTermData() { term = Account.areasOfInterest[i].term, remove = false, qualifier = Account.areasOfInterest[i].qualifier }); } } return(View(MyAccount)); }
public ActionResult ChangePassword(string oldpassword, string newpass, string confirmpass) { if (Request.IsAuthenticated) { if (newpass == confirmpass) { AccountType Account = new AccountType(); SmartService smartService = new SmartService(); string key, toHash, token; token = smartService.AuthToken(); if (token == "") { } else { string username = User.Identity.Name; toHash = username.ToUpper() + "|" + token; key = smartService.GetMd5Hash(MD5.Create(), toHash) + "|" + username; Account = smartService.GetAccountDetails(key, username); string hash = smartService.GetMd5Hash(MD5.Create(), oldpassword); if (Account.password == hash) { Account.password = smartService.GetMd5Hash(MD5.Create(), newpass); string success = smartService.UpdateAccountDetails(key, Account); TempData["Message"] = "Password successfully changed."; } else { ModelState.AddModelError("oldpassword", "The password given doesn't match your current password. Please retype your password and try again"); } } } else { ModelState.AddModelError("confirmpass", "Your passwords don't match. Please retype your passwords and try again"); } } return(View()); }
public ActionResult removeFave(int[] removefavorite) { SmartService smartService = new SmartService(); string key, toHash, token; token = smartService.AuthToken(); if (token == "") { } else { // Create a validation key based on the current logged in username and authentication token string username = User.Identity.Name; toHash = username.ToUpper() + "|" + token; key = smartService.GetMd5Hash(MD5.Create(), toHash) + "|" + username; AccountType Account = smartService.GetAccountDetails(key, username); foreach (int fav in removefavorite) { try { TempData["Message"] = smartService.DeleteFavourite(Account.userId, fav); //not working? } catch (Exception ex) // apparently not throwing the expected fault exception. handling argument exception instead. { if (ex is FaultException) { TempData["Error"] = "Error Message: " + ex.Message; } if (ex is ArgumentException) { TempData["Error"] = "Error Message: " + ex.Message; } } } } return(RedirectToAction("Favourites")); }
public bool UserAdmin(string username) { SmartService smartService = new SmartService(); string key, toHash, token; token = smartService.AuthToken(); if (token == "") { } else { toHash = username.ToUpper() + "|" + token; key = smartService.GetMd5Hash(MD5.Create(), toHash) + "|" + username; AccountType Account = smartService.GetAccountDetails(key, username); if (Account.contentAdmin) { return(true); } } return(false); }
public ActionResult AddToFavourites(int roid) { if (Request.IsAuthenticated) { try { SmartService smartService = new SmartService(); int[] favorite = new int[1]; //InsertFavourites expects an array so, give it one. favorite[0] = roid; string key, toHash, token; token = smartService.AuthToken(); string username = User.Identity.Name; toHash = username.ToUpper() + "|" + token; key = smartService.GetMd5Hash(MD5.Create(), toHash) + "|" + username; AccountType Account = smartService.GetAccountDetails(key, username); TempData["Message"] = smartService.InsertFavourites(Account.userId, favorite); } catch (Exception ex) // apparently not throwing the expected fault exception. handling argument exception instead. { if (ex is FaultException) { TempData["Error"] = "Error Message: " + ex.Message; } if (ex is ArgumentException) { TempData["Error"] = "Error Message: " + ex.Message; } } return(View()); } return(RedirectToAction("Login", "User", new { roid, addToFav = true })); }
public ActionResult SavedSearch() { SmartService smartService = new SmartService(); SavedSearchesType results = new SavedSearchesType(); try { string key, toHash, token; token = smartService.AuthToken(); if (token == "") { } else { // Create a validation key based on the current logged in username and authentication token string username = User.Identity.Name; toHash = username.ToUpper() + "|" + token; key = smartService.GetMd5Hash(MD5.Create(), toHash) + "|" + username; AccountType Account = smartService.GetAccountDetails(key, username); results = smartService.GetSavedSearches(key, Account.userId); //loop through results, check search date and map for (int arraykey = 0; arraykey < results.savedSearchResults.Length; ++arraykey) { DateTime dt = Convert.ToDateTime(results.savedSearchResults[arraykey].searchDate); if (DateTime.Compare(dt, DateTime.Now.AddDays(-7)) < 0) { //if we are in here, then we need to do a new search, and delete the old entry. //first thing to do, delete the old search. try { smartService.DeleteSavedSearch(results.savedSearchResults[arraykey].searchId); } catch (Exception ex) // apparently not throwing the expected fault exception. handling argument exception instead. { TempData["Error"] = ""; if (ex is FaultException) { TempData["Error"] = "Error Message: " + ex.Message; } if (ex is ArgumentException) { TempData["Error"] = "Error Message: " + ex.Message; } if ((TempData["Error"].ToString()) == "") { TempData["Error"] = ex.Message; } return(View()); } //now, do we do a new search based on the old paramiters.. try { System.DateTime fromdate = Convert.ToDateTime(results.savedSearchResults[arraykey].fromDate); System.DateTime todate = Convert.ToDateTime(results.savedSearchResults[arraykey].toDate); var userIdSpecified = false; if (Account.userId != 0) { userIdSpecified = true; } SummaryResultsType searchres = smartService.GetAdvancedSearchSummaryResults(Account.userId, results.savedSearchResults[arraykey].searchTerm, results.savedSearchResults[arraykey].drug, fromdate.Month.ToString(), fromdate.Year.ToString(), todate.Month.ToString(), todate.Year.ToString(), results.savedSearchResults[arraykey].productType, results.savedSearchResults[arraykey].journalTitle, results.savedSearchResults[arraykey].articleTitle, results.savedSearchResults[arraykey].device, results.savedSearchResults[arraykey].indication, results.savedSearchResults[arraykey].therapyArea, results.savedSearchResults[arraykey].manufacturer, results.savedSearchResults[arraykey].Author, results.savedSearchResults[arraykey].doi, results.savedSearchResults[arraykey].pubmedId, results.savedSearchResults[arraykey].citation, results.savedSearchResults[arraykey].sponsoredBy, "", "DESC"); smartService.InsertSavedSearch(results.savedSearchResults[arraykey].searchName, Account.userId, searchres.search_id); results.savedSearchResults[arraykey].searchId = searchres.search_id; } catch (Exception ex) // apparently not throwing the expected fault exception. handling argument exception instead. { TempData["Error"] = ""; if (ex is FaultException) { TempData["Error"] = "Error Message: " + ex.Message; } if (ex is ArgumentException) { TempData["Error"] = "Error Message: " + ex.Message; } if ((TempData["Error"].ToString()) == "") { TempData["Error"] = ex.Message; } } //logic in here to search again and delete old entries. } } } } catch (Exception ex) // apparently not throwing the expected fault exception. handling argument exception instead. { if (ex is FaultException) { TempData["Error"] = "Error Message: " + ex.Message; } if (ex is ArgumentException) { TempData["Error"] = "Error Message: " + ex.Message; } } return(View(results)); }
public ActionResult Favourites() { SearchResultsList ResultList = new SearchResultsList(); try { if (!Request.IsAuthenticated) { //must be logged in to see this page, so kick em out if they arnt. TempData["Error"] = "You must be logged in to view your favourites"; return(RedirectToAction("Index", "Home")); } SmartService smartService = new SmartService(); string key, toHash, token; token = smartService.AuthToken(); if (token == "") { } else { // Create a validation key based on the current logged in username and authentication token string username = User.Identity.Name; toHash = username.ToUpper() + "|" + token; key = smartService.GetMd5Hash(MD5.Create(), toHash) + "|" + username; AccountType Account = smartService.GetAccountDetails(key, username); FullResultsType results = smartService.GetFavourites(key, Account.userId); if (results.numResults == 0) { } else { foreach (ArticleType at in results.contentTypeResults) { //do this with a model instead SearchResults SearchResults = new SearchResults(); SearchResults.articleId = at.articleId; SearchResults.reprintOpprtunityId = at.reprintOpprtunityId; SearchResults.articleTitle = at.articleTitle; SearchResults.authors = at.authors; SearchResults.journalTitle = at.journalTitle; SearchResults.publicationDate = at.publicationDate; SearchResults.citation = at.citation; SearchResults.PDFlink = at.PDFlink; SearchResults.abstractText = at.abstractText; SearchResults.keySentence = at.keySentence; ResultList.SearchResultObjList.Add(SearchResults); } } } } catch (Exception ex) // apparently not throwing the expected fault exception. handling argument exception instead. { if (ex is FaultException) { TempData["Error"] = "Error Message: " + ex.Message; //TempData["ErrorDetail"] = "Error Detail: " + ex.Detail.errorDetails; } if (ex is ArgumentException) { TempData["Error"] = "Error Message: " + ex.Message; } } return(View(ResultList)); }
public ActionResult MyAccount(MyAccount model) { if (ModelState.IsValid) { SmartService smartService = new SmartService(); AccountType Account = new AccountType(); string key, toHash, token; token = smartService.AuthToken(); if (token == "") { } else { // Create a validation key based on the authentication token //toHash = token; // string username = User.Identity.Name; toHash = username.ToUpper() + "|" + token; key = smartService.GetMd5Hash(MD5.Create(), toHash) + "|" + username; //load account so we can preserve the password without the form on the front end. Account = smartService.GetAccountDetails(key, username); Account.username = username; //usernames are emails addresses... | might need changing Account.password = Account.password; //to preserve the password Account.firstname = model.firstname; Account.surname = model.lastname; Account.email = model.email; Account.jobTitle = model.jobtitle; Account.organisation = model.organization; Account.telephone = model.number; //Account.emailService = model.aoitext.ToString(); Account.country = model.country; Account.address = model.address; Account.emailService = model.sales; List <TermType> Termlist = new List <TermType>(); foreach (UserTermData data in model.data) { if (data.remove == false) { TermType Term = new TermType(); Term.term = data.term; Term.qualifier = data.qualifier; Termlist.Add(Term); } } if (model.addterm != null && model.addterm.Trim() != "") { //This needs to be made a lot better. added for now so we can test List <string> drug = new List <string>(smartService.Drugs(model.addterm, 1)); List <string> man = new List <string>(smartService.Manufacturers(model.addterm, 1)); List <string> indi = new List <string>(smartService.Indications(model.addterm, 1)); List <string> dev = new List <string>(smartService.Devices(model.addterm, 1)); TermType Term = new TermType(); Term.term = model.addterm; Term.qualifier = ""; Term.qualifier = (drug.Count() > 0) ? "Drug" : ""; Term.qualifier = (man.Count() > 0) ? "Manufacturer" : Term.qualifier; Term.qualifier = (indi.Count() > 0) ? "Indication" : Term.qualifier; Term.qualifier = (dev.Count() > 0) ? "Device" : Term.qualifier; if (model.linkedterm != null && model.linkedterm.Trim() != "") { Term.term = String.Format("{0} AND {1}", Term.term, model.linkedterm); List <string> drug1 = new List <string>(smartService.Drugs(model.linkedterm, 1)); List <string> man1 = new List <string>(smartService.Manufacturers(model.linkedterm, 1)); List <string> indi1 = new List <string>(smartService.Indications(model.linkedterm, 1)); List <string> dev1 = new List <string>(smartService.Devices(model.linkedterm, 1)); if (drug1.Count() > 0) { Term.qualifier = String.Format("{0} AND {1}", Term.qualifier, "Drug"); } else if (man1.Count() > 0) { Term.qualifier = String.Format("{0} AND {1}", Term.qualifier, "Manufacturer"); } else if (indi1.Count() > 0) { Term.qualifier = String.Format("{0} AND {1}", Term.qualifier, "Indication"); } else if (dev1.Count() > 0) { Term.qualifier = String.Format("{0} AND {1}", Term.qualifier, "Device"); } } Termlist.Add(Term); } Account.areasOfInterest = Termlist.ToArray(); try { Account.emailServiceSpecified = true; TempData["Message"] = smartService.UpdateAccountDetails(key, Account); } catch (Exception ex) // apparently not throwing the expected fault exception. handling argument exception instead. { if (ex is FaultException) { TempData["Error"] = "Error Message: " + ex.Message; //TempData["ErrorDetail"] = "Error Detail: " + ex.Detail.errorDetails; } if (ex is ArgumentException) { TempData["Error"] = "Error Message: " + ex.Message; } } } return(RedirectToAction("MyAccount", "User")); //force it to reload the get request. } return(View(model)); }