Пример #1
0
        public override async Task <AuthenticationState> GetAuthenticationStateAsync()
        {
            var uId = await _storage.GetAsync <string>("UserId");

            var name = await _storage.GetAsync <string>("Name");

            var role = await _storage.GetAsync <string>("Role");

            var expireTime = await _storage.GetAsync <DateTime>("ExpireTime");

            ClaimsIdentity identity;

            if (string.IsNullOrWhiteSpace(uId) || string.IsNullOrWhiteSpace(role) || string.IsNullOrWhiteSpace(name) || expireTime < DateTime.Now)
            {
                identity = new ClaimsIdentity(); // No auth in session storage
            }
            else
            {
                _        = _storage.SetAsync("ExpireTime", DateTime.Now.AddHours(5));
                identity = new ClaimsIdentity(new[]
                {
                    new Claim("UserId", uId),
                    new Claim(ClaimTypes.Role, role),
                    new Claim(ClaimTypes.Name, name),
                }, "Session");
            }

            var claims = new ClaimsPrincipal(identity);

            return(await Task.FromResult(new AuthenticationState(claims)));
        }
Пример #2
0
        private async Task <TResult> GetAsyncWithCaching <TResult>(string api)
        {
            var cachedValue = await protectedSessionStorage.GetAsync <TResult>(api);

            if (cachedValue != null)
            {
                return(cachedValue);
            }

            var result = await InternalGetAsync <TResult>(api);

            await protectedSessionStorage.SetAsync(api, result);

            return(result);
        }
        protected override async Task OnInitializedAsync()
        {
            Loader                  = "none";
            NewLoader               = "none";
            model                   = new RegistrationViewModel();
            model.Year              = DateTime.Now.Year.ToString();
            model.GradutionName     = "Graduation";
            model.PostGradutionName = "Post Graduation";
            if (ShowOptions == "B_Ed")
            {
                model.CourseName = "Bachelor of Education";
                IsM_Ed           = false;
                HeadingText      = "B.Ed";
            }
            else
            {
                model.CourseName    = "Master of Education";
                IsM_Ed              = true;
                model.GradutionName = "Bachelor of Education";
                HeadingText         = "M.Ed";
            }

            // To get Email and Mobile Number from DB.
            var authState = await authenticationStateTask;
            var user      = await UserManager.GetUserAsync(authState.User);

            if (user != null)
            {
                model.EmailAddress = user.Email;
                model.MobileNo     = user.PhoneNumber;
            }

            DomicileUksList          = new List <string>();
            FreedomFightersList      = new List <string>();
            DefencePersonalList      = new List <string>();
            PhysicallyChallengesList = new List <string>();
            PunishedByCourtList      = new List <string>();
            DabarredCollegeList      = new List <string>();
            ExamCenterList           = new List <string>();
            GroupList                    = new List <string>();
            MaritalStatusList            = new List <string>();
            NationalityList              = new List <string>();
            CategoryList                 = new List <string>();
            PhysicallyChallengesTypeList = new List <string>();
            GendersList                  = new List <string>();
            StreamList                   = new List <string>();
            CoursesList                  = new List <string>();
            PassingYearList              = new List <string>();
            StateList                    = new List <string>();
            EWS = new List <string>();
            M_EdGraducationRequired = new List <string>();
            await LoadDropDownData();

            await ProtectedSessionStorage.SetAsync("gradu", true);
        }
        protected async Task UploadSignatureAsync(UploadChangeEventArgs args)
        {
            if (args.Files.Any())
            {
                try
                {
                    var file = args.Files.FirstOrDefault();
                    if (file != null)
                    {
                        if (file.FileInfo.Size < 1000 || file.FileInfo.Size > 200000)
                        {
                            await ToastObjRegistration.Show(new ToastModel
                            {
                                Title    = "Error!", Content = "Please upload file in betwen 1 kB to 200 KB!",
                                CssClass = "e-toast-danger", Icon = "e-error toast-icons"
                            });
                        }
                        else
                        {
                            string uniqueFileName = Guid.NewGuid().ToString() + "_" + file.FileInfo.Name;
                            await ProtectedSessionStorage.SetAsync("UniqueSignatureName", uniqueFileName);

                            model.SignatureFile = file;
                        }
                    }
                    else
                    {
                        await ToastObjRegistration.Show(new ToastModel
                        {
                            Title = "Error!", Content = "Please upload the file!", CssClass = "e-toast-danger",
                            Icon  = "e-error toast-icons"
                        });
                    }
                }
                catch (Exception ex)
                {
                    await ToastObjRegistration.Show(new ToastModel
                    {
                        Title = "Error!", Content = ex.Message, CssClass = "e-toast-danger",
                        Icon  = "e-error toast-icons"
                    });
                }
            }
        }
        protected async Task CheckCrimicalRecord(string value)
        {
            if (value == "Yes")
            {
                await ToastObjRegistration.Show(new ToastModel
                {
                    Title    = "Error!",
                    Content  = "You are not eligible!",
                    CssClass = "e-toast-danger",
                    Icon     = "e-error toast-icons"
                });

                await ProtectedSessionStorage.SetAsync("gradu", false);
            }
            else
            {
                await ProtectedSessionStorage.SetAsync("gradu", true);
            }
        }
        protected async Task RegisterNewFormAsync()
        {
            NewLoader = "inline";
            StateHasChanged();
            try
            {
                var changeEventValue = await ProtectedSessionStorage.GetAsync <bool>("gradu");

                if (changeEventValue)
                {
                    var UniqueSignatureName = await ProtectedSessionStorage.GetAsync <string>("UniqueSignatureName");

                    var UniquePhotoName = await ProtectedSessionStorage.GetAsync <string>("UniquePhotoName");

                    if (!string.IsNullOrEmpty(UniqueSignatureName) && !string.IsNullOrEmpty(UniqueSignatureName))
                    {
                        var authState = await authenticationStateTask;
                        var user      = await UserManager.GetUserAsync(authState.User);

                        //model.UniqueKey = Guid.NewGuid().ToString().GetHashCode().ToString("x");
                        model.UserId = user.Id;
                        var result = await CenterService.InsertRegistrationFormDataAsync(model);

                        if (result == "success")
                        {
                            await ToastObjRegistration.Show(new ToastModel
                            {
                                Title    = "Success!",
                                Content  = "You have submitted your registration form successfully.",
                                CssClass = "e-toast-success",
                                Icon     = "e-success toast-icons"
                            });

                            model      = new RegistrationViewModel();
                            NewLoader  = "none";
                            model.Year = DateTime.Now.Year.ToString();
                            await ProtectedSessionStorage.SetAsync("gradu", true);

                            model.GradutionName     = "Graduation";
                            model.PostGradutionName = "Post Graduation";
                            await Js.CloseModel("modalConfirmDelete");
                        }
                        else if (result == "failure")
                        {
                            NewLoader = "none";
                            await ToastObjRegistration.Show(new ToastModel
                            {
                                Title    = "Error!",
                                Content  = "You are sending bad request, please try again later!",
                                CssClass = "e-toast-danger",
                                Icon     = "e-error toast-icons"
                            });

                            await Js.CloseModel("modalConfirmDelete");
                        }
                        else
                        {
                            NewLoader = "none";
                            await ToastObjRegistration.Show(new ToastModel
                            {
                                Title    = "Error!",
                                Content  = result,
                                CssClass = "e-toast-danger",
                                Icon     = "e-error toast-icons"
                            });

                            await Js.CloseModel("modalConfirmDelete");
                        }
                    }
                    else
                    {
                        NewLoader = "none";
                        await ToastObjRegistration.Show(new ToastModel
                        {
                            Title    = "Error!",
                            Content  = "Please upload both files then try again!",
                            CssClass = "e-toast-danger",
                            Icon     = "e-error toast-icons"
                        });

                        await Js.CloseModel("modalConfirmDelete");
                    }
                }
                else
                {
                    NewLoader = "none";
                    await ToastObjRegistration.Show(new ToastModel
                    {
                        Title    = "Error!",
                        Content  = "You are not eligible!",
                        CssClass = "e-toast-danger",
                        Icon     = "e-error toast-icons"
                    });

                    await Js.CloseModel("modalConfirmDelete");
                }
            }
            catch (Exception ex)
            {
                NewLoader = "none";
                await ToastObjRegistration.Show(new ToastModel
                {
                    Title    = "Error!",
                    Content  = ex.Message,
                    CssClass = "e-toast-danger",
                    Icon     = "e-error toast-icons"
                });

                await Js.CloseModel("modalConfirmDelete");
            }
        }
        protected async Task GraduationPercentageCalc()
        {
            if (model.GradutionObtMarks != "")
            {
                if (model.GradutionMaxMarks != "")
                {
                    double percentage = Convert.ToDouble((Convert.ToInt32(model.GradutionObtMarks) * 100) /
                                                         Convert.ToInt32(model.GradutionMaxMarks));
                    model.GradutionPercentageMarks = percentage.ToString();
                    if (model.Category.ToLower() == "Unreserved General".ToLower())
                    {
                        if (percentage > 50)
                        {
                            await ProtectedSessionStorage.SetAsync("gradu", true);
                        }
                        else
                        {
                            await ToastObjRegistration.Show(new ToastModel
                            {
                                Title    = "Error!",
                                Content  = "You are not eligible!",
                                CssClass = "e-toast-danger",
                                Icon     = "e-error toast-icons"
                            });

                            await ProtectedSessionStorage.SetAsync("gradu", false);
                        }
                    }
                    else
                    {
                        if (percentage > 45)
                        {
                            await ProtectedSessionStorage.SetAsync("gradu", true);
                        }
                        else
                        {
                            await ToastObjRegistration.Show(new ToastModel
                            {
                                Title    = "Error!",
                                Content  = "You are not eligible!",
                                CssClass = "e-toast-danger",
                                Icon     = "e-error toast-icons"
                            });

                            await ProtectedSessionStorage.SetAsync("gradu", false);
                        }
                    }
                }
                else
                {
                    await ToastObjRegistration.Show(new ToastModel
                    {
                        Title    = "Error!",
                        Content  = "Please fill graduation maximum marks!",
                        CssClass = "e-toast-danger",
                        Icon     = "e-error toast-icons"
                    });
                }
            }
            else
            {
                await ToastObjRegistration.Show(new ToastModel
                {
                    Title    = "Error!",
                    Content  = "Please fill graduation obtained marks!",
                    CssClass = "e-toast-danger",
                    Icon     = "e-error toast-icons"
                });
            }
        }