[ValidateAntiForgeryToken]                                         // Ensures that the form that send the request is the right one
        public IActionResult Index(IndexViewModel model, string returnUrl) //To pass ReturnUrl value from view to controller.
        {
            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction(nameof(HomeController.Index)));
            }

            //The user role initializeation.
            string role = null;

            //To pass ReturnUrl value from controller to view, ViewData's life only lasts during current http request.
            ViewData["ReturnUrl"] = returnUrl;
            bool isCodeOk = false;

            if (ModelState.IsValid)
            {
                role = model.SignInUserRole.Equals("0") ? "Organizer" : (model.SignInUserRole.Equals("1") ? "Spanner" : null);

                //Check the existance of the entered code
                if (role.Equals("Organizer"))
                {
                    isCodeOk      = _flightSpannersData.ValidateOrganizerCode(model.Code);
                    ViewBag.error = isCodeOk ? null : "This Code is not registered as Organizer";
                }
                else if (role.Equals("Spanner"))
                {
                    isCodeOk      = _flightSpannersData.ValidateSpannerCode(model.Code);
                    ViewBag.error = isCodeOk ? null : "This Code is not registered as Spanner";
                }
                else if (String.IsNullOrEmpty(role))
                {
                    ViewBag.error = "Select The role of your sign in";
                }
            }

            if (!ModelState.IsValid || !isCodeOk || String.IsNullOrEmpty(role))
            {
                return(View(nameof(HomeController.Index), model));
            }
            //return RedirectToAction(nameof(HomeController.SignIn));

            return(View(nameof(HomeController.SignIn),
                        new SignInViewModel()
            {
                Code = model.Code,
                SignInUserRole = model.SignInUserRole,
                ReturnUrl = returnUrl,
                OrganizerGroups = _flightSpannersData.GetOrganizerGroupSelectListItems(model.Code)
            }));
        }
        //Constructor injection
        public OrganizerDataViewModel(IHttpContextAccessor httpContext, IFlightSpannersData flightSpannersData)
        {
            string code = httpContext.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;

            //Return the organizer based on the code
            var organizer = flightSpannersData.GetOrganizerByCode(code);

            this.OrganizerCode       = organizer.OrganizerCode;
            this.OrganizerEmail      = organizer.OrganizerEmail;
            this.OrganizerFName      = organizer.OrganizerFName;
            this.OrganizerLName      = organizer.OrganizerLName;
            this.OrganizerM1Name     = organizer.OrganizerM1Name;
            this.OrganizerM2Name     = organizer.OrganizerM2Name;
            this.OrganizerMobile1    = organizer.OrganizerMobile1;
            this.OrganizerMobile2    = organizer.OrganizerMobile2;
            this.OrganizerOccupation = organizer.OrganizerOccupation;

            //Get the OrganizerGroupList item of the model using GetOrganizerGroupNames(code) method
            this.OrganizerGroupList = flightSpannersData.GetOrganizerGroupSelectListItems(code);
            //ViewBag.OrganizerGroupList = model.OrganizerGroupList;
        }