public async Task <IActionResult> DeleteConfirmed(Guid id)
        {
            Identity identity = ControllerContext.GetIdentity();

            Volunteer volunteer = await applicationDbContext.Volunteers.FindAsync(id);

            if (identity.ID == id)
            {
                ModelState.AddModelError(nameof(Volunteer.ID), "Can't delete yourself");

                return(View(volunteer));
            }

            ApplicationUser identityUser = await applicationDbContext.Users.FindAsync(volunteer.ID.ToString());

            await userManager.RemoveFromRoleAsync(identityUser, Framework.Identity.CustomIdentityRole.Volunteer);

            await userManager.AddToRoleAsync(identityUser, Framework.Identity.CustomIdentityRole.Guest);

            applicationDbContext.Volunteers.Remove(volunteer);

            await applicationDbContext.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Volunteers()
        {
            Identity identity = ControllerContext.GetIdentity();

            List <Volunteer> volunteers = await applicationDbContext.Volunteers.Where(x => x.NGOID == identity.NGOID).ToListAsync();

            foreach (Volunteer volunteer in volunteers)
            {
                volunteer.Name = applicationDbContext.Users.Find(volunteer.ID.ToString()).Email;
            }

            return(View(volunteers));
        }
        public IActionResult RegisterAsNGO()
        {
            Identity identity = ControllerContext.GetIdentity();

            Volunteer   volunteer   = applicationDbContext.Volunteers.FirstOrDefault(x => x.ID == identity.ID && x.VolunteerStatus == VolunteerStatus.PendingVerification);
            Beneficiary beneficiary = applicationDbContext.Beneficiaries.FirstOrDefault(x => x.ID == identity.ID && x.Status == BeneficiaryStatus.PendingVerification);

            ViewBag.OtherPendingApplication = volunteer != null || beneficiary != null;

            NGO ngo = applicationDbContext.NGOs.FirstOrDefault(x => x.NGOStatus == NGOStatus.PendingVerification && x.CreatedByID == identity.ID);

            return(View(ngo));
        }
        public async Task <IActionResult> Create([Bind(nameof(RegisterVolunteerModel.Email))] RegisterVolunteerModel registerVolunteerModel)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser identityUser = await userManager.FindByEmailAsync(registerVolunteerModel.Email);

                if (identityUser == null || (await applicationDbContext.Volunteers.FindAsync(Guid.Parse(identityUser.Id))) == null)
                {
                    Identity identity = ControllerContext.GetIdentity();

                    if (identityUser == null)
                    {
                        identityUser = new ApplicationUser {
                            UserName = registerVolunteerModel.Email, Email = registerVolunteerModel.Email, EmailConfirmed = true
                        };

                        await userManager.CreateAsync(identityUser, "Test.123");

                        await userManager.AddToRoleAsync(identityUser, Framework.Identity.CustomIdentityRole.Volunteer);
                    }
                    else
                    {
                        await userManager.RemoveFromRoleAsync(identityUser, Framework.Identity.CustomIdentityRole.Guest);

                        await userManager.AddToRoleAsync(identityUser, Framework.Identity.CustomIdentityRole.Volunteer);
                    }

                    Volunteer volunteer = new Volunteer();
                    volunteer.ID    = Guid.Parse(identityUser.Id);
                    volunteer.NGOID = identity.NGOID;

                    applicationDbContext.Volunteers.Add(volunteer);

                    await applicationDbContext.SaveChangesAsync();

                    return(RedirectToAction(nameof(Volunteers)));
                }

                ModelState.AddModelError(nameof(RegisterVolunteerModel.Email), "Email duplicat");
            }

            return(View(registerVolunteerModel));
        }
        public async Task <IActionResult> RegisterAsNGO([Bind(nameof(NGO.Name))] NGO ngo)
        {
            if (ModelState.IsValid)
            {
                Identity identity = ControllerContext.GetIdentity();

                ngo.ID          = Guid.NewGuid();
                ngo.CreatedByID = identity.ID;
                ngo.NGOStatus   = NGOStatus.PendingVerification;

                applicationDbContext.Add(ngo);

                await applicationDbContext.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(ngo));
        }
        public IActionResult RegisterAsVolunteer()
        {
            Identity identity = ControllerContext.GetIdentity();

            NGO         ngo         = applicationDbContext.NGOs.FirstOrDefault(x => x.CreatedByID == identity.ID && x.NGOStatus == NGOStatus.PendingVerification);
            Beneficiary beneficiary = applicationDbContext.Beneficiaries.FirstOrDefault(x => x.ID == identity.ID && x.Status == BeneficiaryStatus.PendingVerification);

            ViewBag.OtherPendingApplication = ngo != null || ngo != null;

            if (!ViewBag.OtherPendingApplication)
            {
                Volunteer volunteer = applicationDbContext.Volunteers.FirstOrDefault(x => x.VolunteerStatus == VolunteerStatus.PendingVerification && x.ID == identity.ID);

                volunteer.Name = applicationDbContext.Users.Find(identity.ID.ToString()).Email;

                return(View(volunteer));
            }

            return(View());
        }
        public async Task <IActionResult> RegisterAsBeneficiary(Guid id)
        {
            Identity identity = ControllerContext.GetIdentity();

            Beneficiary beneficiary = new Beneficiary();

            beneficiary.ID     = identity.ID;
            beneficiary.NGOID  = identity.NGOID;
            beneficiary.Status = BeneficiaryStatus.PendingVerification;

            ApplicationUser identityUser = await userManager.FindByIdAsync(identity.ID.ToString());

            await userManager.RemoveFromRoleAsync(identityUser, Framework.Identity.CustomIdentityRole.Guest);

            await userManager.AddToRoleAsync(identityUser, Framework.Identity.CustomIdentityRole.Beneficiary);

            applicationDbContext.Beneficiaries.Add(beneficiary);

            await applicationDbContext.SaveChangesAsync();

            return(RedirectToAction(nameof(RegisterAsBeneficiary)));
        }