public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
            switch (result)
            {
                case SignInStatus.Success:
                    ServiceReference1.VirtualTourClient client = new ServiceReference1.VirtualTourClient();
                    bool correctPassword = client.checkCredentials(model.Email, model.Password);
                    if (correctPassword){
                        return RedirectToAction("Create", "Home");
                    }
                    else
                    {
                        ModelState.AddModelError("", "Invalid login attempt.");
                        return View(model);
                    }
                case SignInStatus.LockedOut:
                    return View("Lockout");
                case SignInStatus.RequiresVerification:
                    return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
                case SignInStatus.Failure:
                default:
                    ModelState.AddModelError("", "Invalid login attempt.");
                    return View(model);
            }
        }
        public ActionResult GetSiteConfigData(int buildingIDVal)
        {            
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            object jsonData = null;

            ServiceReference1.VirtualTourClient client = new ServiceReference1.VirtualTourClient();
            var b = client.GetBuildingByID(buildingIDVal);
            jsonData = SetImagesAndArrows(b.Image_ID);
            return Content(serializer.Serialize(jsonData), "application/json");
        }
        public ActionResult GetLinks()
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            object jsonData = null;
            string l3 = "javascript:void(0);";

            ServiceReference1.VirtualTourClient vt = new ServiceReference1.VirtualTourClient();
            var buildings = vt.CreateList();
            string l2 = string.Empty;
            foreach (var b in buildings)
            {
                l2 = l2 + "<li><a onclick=" + "\"setMainImage(" + b.Building_ID + ");\"" + "href=" +  "\"javascript:void(0);\"" + ">" + b.Building_name + "</a></li>";
            }

            jsonData = new
            {
                testId = l2
            };
            return Content(serializer.Serialize(jsonData), "application/json");
        }
        public ActionResult ReplaceFwdImage(int imageIDVal)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            object jsonData = null;
            int arrowF = 1;
            int arrowB = 1;
            int arrowR = 1;
            int arrowL = 1;

            ServiceReference1.VirtualTourClient client = new ServiceReference1.VirtualTourClient();
            var a = client.GetImagesForDirections(imageIDVal);
            var i = client.GetImageByID(a.Image_front);
            string base64String = Convert.ToBase64String(i.Image_code);
            var f = client.GetImagesForDirections(a.Image_front);

            if (f.Image_front == 0)
                arrowF = 0;

            if (f.Image_back == 0)
                arrowB = 0;

            if (f.Image_left == 0)
                arrowL = 0;

            if (f.Image_right == 0)
                arrowR = 0;

            jsonData = new
            {
                testId = base64String,
                imageID = a.Image_front,
                showArrowRight = arrowR,
                showArrowLeft = arrowL,
                showArrowFwd = arrowF,
                showArrowBwd = arrowB
            };

            return Content(serializer.Serialize(jsonData), "application/json");
        }
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
                    
                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
                    ServiceReference1.VirtualTourClient vt = new ServiceReference1.VirtualTourClient();
                    vt.SaveCredentials(model.Email, model.Password);
                    return RedirectToAction("Create", "Home");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
        public ActionResult  SaveImageDetails(string imagPathVal, string direction)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            object jsonData = null;
            
            ServiceReference1.VirtualTourClient vt = new ServiceReference1.VirtualTourClient();

            Image img = Image.FromFile(imagPathVal);
            byte[] imgByte = imageToByteConverter(img);
            string base64String = Convert.ToBase64String(imgByte);
            int imgId = vt.SaveImageInfor(base64String, direction);
            vt.SaveImageDirectionData(imgId, direction);

            jsonData = new
            {
                directValue = direction,
                imageIDValue = imgId
            };

            return Content(serializer.Serialize(jsonData), "application/json");    
        }
 public void SaveBuildingDetails(string buildingIDVal, string buildingDescVal)
 {
     ServiceReference1.VirtualTourClient vt = new ServiceReference1.VirtualTourClient();
     vt.SaveBuildingInfo(buildingIDVal, buildingDescVal);
 }
        public object SetImagesAndArrows(int imageID)
        {
            object jsonData = null;
            int arrowF = 1;
            int arrowB = 1;
            int arrowR = 1;
            int arrowL = 1;

            ServiceReference1.VirtualTourClient client = new ServiceReference1.VirtualTourClient();
            var i = client.GetImageByID(imageID);
            string base64String = Convert.ToBase64String(i.Image_code);
            var b = GetImagesByDirection(imageID);

            if (b.Image_front == 0)
                arrowF = 0;

            if (b.Image_back == 0)
                arrowB = 0;

            if (b.Image_left == 0)
                arrowL = 0;

            if (b.Image_right == 0)
                arrowR = 0;

            jsonData = new
            {
                testId = base64String,
                imageID = imageID,
                showArrowRight = arrowR,
                showArrowLeft = arrowL,
                showArrowFwd = arrowF,
                showArrowBwd = arrowB
            };

            return jsonData;
        }
 public ServiceReference1.Image_direction GetImagesByDirection(int imageID)
 {
     ServiceReference1.VirtualTourClient client = new ServiceReference1.VirtualTourClient();
     var a = client.GetImagesForDirections(imageID);
     return a;
 }