Beispiel #1
0
        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));
        }
Beispiel #2
0
        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());
        }
Beispiel #3
0
        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"));
        }
Beispiel #4
0
        public ActionResult DeactivateAccount()
        {
            SmartService smartService = new SmartService();
            string       key, toHash, token;

            token = smartService.AuthToken();
            string username = User.Identity.Name;

            if (token == "")
            {
            }
            else
            {
                // Create a validation key based on the current logged in username and authentication token
                toHash = username.ToUpper() + "|" + token;
                key    = smartService.GetMd5Hash(MD5.Create(), toHash) + "|" + username;
                string deactivate = smartService.DeactivateAccount(key, username);
            }

            FormsAuthentication.SignOut();
            return(RedirectToAction("Index", "Home"));
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        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 }));
        }
Beispiel #7
0
        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));
        }
Beispiel #8
0
        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));
        }
Beispiel #9
0
        public ActionResult Register(RegistrationUserModel model)
        {
            //time for some inefficiant error checking - needs to be made better
            SmartService smartService = new SmartService();

            ViewBag.DisplayItems = true;

            if (model.password != model.confirm)
            {
                ModelState.AddModelError("confirm", "Your passwords don't match. Please retype your passwords and try again");
            }
            if (!model.tandc)
            {
                ModelState.AddModelError("tandc", "You must tick the Terms & Conditions checkbox to register.");
            }

            if (ModelState.IsValid)
            {
                //build account object and pass to insert registration.

                var  sales        = Request.Form["sales"];
                bool emailservice = (sales == null) ? false : true;

                AccountType at   = new AccountType();
                string      hash = smartService.GetMd5Hash(MD5.Create(), model.password);
                at.username     = model.email;
                at.password     = hash;
                at.firstname    = model.firstname;
                at.surname      = model.lastname;
                at.email        = model.email;
                at.jobTitle     = model.jobtitle;
                at.organisation = model.organization;
                at.telephone    = model.number;
                at.emailService = model.sales;
                at.country      = model.country;

                at.address = model.address;
                at.emailServiceSpecified = true;

                at.emailService = emailservice;

                TermType tt0 = new TermType();
                at.areasOfInterest = new TermType[] { tt0 };

                string key, toHash, token;
                token = smartService.AuthToken();
                if (token == "")
                {
                }
                else
                {
                    // Create a validation key based on the authentication token
                    toHash = token;
                    key    = smartService.GetMd5Hash(MD5.Create(), toHash);
                    try
                    {
                        TempData["Message"] = smartService.InsertAccount(key, at);
                        return(Login(new User()
                        {
                            UserName = model.email, Password = model.password
                        }, "", ""));
                    }
                    catch (SoapException se)
                    {
                        var msg = se.Detail["ErrorMessage"]["errorMessage"].InnerText;
                        ModelState.AddModelError("Problem", msg);
                        if (msg.ToLower().Contains("account created pending verification"))
                        {
                            ViewBag.DisplayItems = false;
                        }
                    }
                    catch (Exception ex) // apparently not throwing the expected fault exception. handling argument exception instead.
                    {
                        TempData["Error"] = "Error Message: " + ex.Message;
                    }
                }
            }
            model.DropDownItems = model.getCountry();
            return(View("Index", model));
        }
Beispiel #10
0
        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));
        }