public ActionResult SignUp()
        {
            TouristSignUpViewModel tsuvm = new TouristSignUpViewModel();

            tsuvm.CountryList = new SelectList(entity.Countries, "CountryId", "CountryName");

            return(View(tsuvm));
        }
        public ActionResult SignUp(TouristSignUpViewModel tsuvm)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    bool result;
                    result = tl.CheckEmailExist(tsuvm.TouristEmail);
                    if (result == true)
                    {
                        tsuvm.CountryList = new SelectList(entity.Countries, "CountryId", "CountryName");

                        ViewData["message"] = "Email Duplicate found.";
                        return(View(tsuvm));
                    }
                    else
                    {
                        Tourist tourist = new Tourist();
                        tourist.TouristName  = tsuvm.TouristName;
                        tourist.TouristEmail = tsuvm.TouristEmail;
                        tourist.CountryId    = Convert.ToInt32(tsuvm.CountryId);
                        tourist.CityId       = Convert.ToInt32(tsuvm.CityId);

                        tourist.TouristPhnNo                 = tsuvm.TouristPhnNo;
                        tourist.TouristAddress               = "Not given yet";
                        tourist.TouristEmergencyPhnNo        = "Not given yet";
                        tourist.TouristsStatus               = true;
                        tourist.TouristsHostStatus           = false;
                        tourist.TouristAdminsPermit          = true;
                        tourist.TouristDateOfAccountCreation = DateTime.Now;
                        tourist.TouristPassword              = tsuvm.TouristPassword;

                        entity.Tourists.Add(tourist);
                        if (entity.SaveChanges() > 0)
                        {
                            ModelState.Clear();
                            string userCode = "tourist";
                            Session["userCode"]     = userCode.ToString();
                            Session["TouristEmail"] = tsuvm.TouristEmail;
                            Session["TouristName"]  = tsuvm.TouristName;
                            var d = (from c in entity.Tourists where c.TouristEmail == tsuvm.TouristEmail select c).FirstOrDefault();
                            Session["TouristId"] = d.TouristId;
                            Nullable <int> ProPicId  = d.TouristProfilePicId;
                            int            touristId = (int)Session["TouristId"];
                            Session["CountryId"] = tsuvm.CountryId;
                            Session["CityId"]    = tsuvm.CityId;
                            if (ProPicId != null)
                            {
                                byte[] pic = (from c in entity.TouristPictures where c.TouristId == touristId && c.AlbumTypeId == 1 orderby c.TouristPictureId descending select c.TouristPictureData).First();
                                if (pic != null)
                                {
                                    Session["pp"] = pic;
                                }
                            }


                            string subject = "Registered to Shepherd";
                            string message = "Congratulations, You're now a registered tourist of our site. For any new offers and places you'll get notified via an Email. Thank you.";
                            Admin  ad      = new Admin();
                            ad.SentMail(tsuvm.TouristEmail, message, subject);
                            Subscriber sb = new Subscriber();
                            sb.SubscriberEmail = tsuvm.TouristEmail;
                            entity.Subscribers.Add(sb);
                            entity.SaveChanges();


                            return(RedirectToAction("Index", "Home"));
                        }
                        else
                        {
                            tsuvm.CountryList = new SelectList(entity.Countries, "CountryId", "CountryName");


                            ViewData["message"] = "not saved";
                            return(View(tsuvm));
                        }
                    }
                }
                catch (Exception ex)
                {
                    return(View("Error", new HandleErrorInfo(ex, "Tourist", "SignUp")));
                }
            }
            else
            {
                tsuvm.CountryList = new SelectList(entity.Countries, "CountryId", "CountryName");
                return(View(tsuvm));
            }
        }