Beispiel #1
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));
        }