Ejemplo n.º 1
0
        public ActionResult ThankYou()
        {
            ViewBag.Message = "Thanks For the Vote";
            var canId = Request["CandidateId"];
            // get logged in user id
            String uId = User.Identity.GetUserId();
            //var finprint = Request["UserFingerprint"];
            ViewBag.candidateID = canId;
            ViewBag.userID = uId;
            //ViewBag.fingerprint = finprint;
            // get user status for Voting 
            var userStatusId = "";
            var userDOB = "";
            var userStatusDescription = "";
            // get user DOB and Status in this array
            VoteViewModel voteVM = new VoteViewModel();
            UserDetails userDetails = voteVM.GetUserDetails(uId);
            userStatusId = userDetails.UserStatusId;
            userStatusId = userStatusId.ToString();
            // use DOB 
            userDOB = userDetails.DOB;

            // check if the candidate country is same as the voters country 
            var CandidateCountry = "";
            var UserCountry = "";

            CandidatesViewModel candidatesViewModel = new CandidatesViewModel();
            CandidateDTO canDTO = new CandidateDTO();
            canDTO = candidatesViewModel.GetCandidateDetailsById(canId);
            // candidates Country
            CandidateCountry = canDTO.Country;
            var candidateCampaign = canDTO.CampaignID;
            ViewBag.candidateCampaign = candidateCampaign;

            // users Country
            UserCountry = voteVM.GetLoggedUserCountry(uId);

            userStatusDescription = voteVM.GetUserStatusDescription(userStatusId);

            ViewBag.UserCountry = UserCountry;
            ViewBag.CandidateCountry = CandidateCountry;

            // get user and campaign 
            //UserCampaign userCampaign = new UserCampaign();

            //userCampaign = voteVM.GetUserCampaign(uId, candidateCampaign);

            List<UserCampaign> userCampaign = voteVM.GetUserCampaign();// get all the list of the user id and campaing that voted before




            if (UserCountry == CandidateCountry) //  the user should be the citizen in the country to vote for the candidate
            {
                // check users age at the current time, the user may have grown up and have the age rule 

                GetAgeCalculated gAge = new GetAgeCalculated();
                int userAge = gAge.GetAge(userDOB);
                if (userAge >= 18)
                {
                    ViewBag.result = userAge;

                    if (userCampaign != null)// check if the user campaing table is not empty 
                    {
                        bool userVotedfound = false;
                        foreach (var item in userCampaign)
                        {
                            if (uId == item.UserId && candidateCampaign == item.CampaignID)
                            {
                                userVotedfound = true;
                            }
                            //else
                            //{
                            //    userVotedfound = false;
                            //}
                        }
                        //  than you can vote, check if the user and campaign are not the same 
                        if (userVotedfound == true) // user can vote for multiple campaings but can vote for the second time in the same campaign
                        {
                            //ViewBag.result = "The user already Voted in this campaign";
                            return View("AlreadyVoted");
                        }
                        else // if the user did not vote than let the user vote 
                        {
                            voteVM.InsertDataIntoVoteTable(uId, candidateCampaign, canId); // add the data to Vote table 
                            return View();// return thank you to the user
                        }
                    }
                    else// if the table has no data user did not vote on any campaign than let the user vote 
                    {
                        voteVM.InsertDataIntoVoteTable(uId, candidateCampaign, canId); // add the data to Vote table
                        return View();// return thank you to the user
                    }
                }
                else
                {
                    return View("Rejected");
                }
            }
            else
            {
                return View("Rejected");

            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                // To convert the user uploaded Photo as Byte Array before save to DB
                byte[] imageData = null;
                if (Request.Files.Count > 0)
                {
                    HttpPostedFileBase poImgFile = Request.Files["UserPhoto"];

                    using (var binary = new BinaryReader(poImgFile.InputStream))
                    {
                        imageData = binary.ReadBytes(poImgFile.ContentLength);
                    }
                }
                // set default status Id by the following description
                var statusDescription = "";
                var statusId          = "";

                VoteViewModel    vvM  = new VoteViewModel();
                GetAgeCalculated gAge = new GetAgeCalculated();
                int userAge           = gAge.GetAge(model.DOB);
                if (userAge >= 17)
                {
                    statusDescription = "Not Vote";
                }
                else
                {
                    statusDescription = "Age-rule";
                }
                statusId = vvM.GetUserStatusIdByDescriptio(statusDescription);
                // check if the statusId is empty than add the values to the table
                if (statusId == null)
                {
                    // set the default vote to the vote status table
                    VoteViewModel vM = new VoteViewModel();
                    vM.InsertDescriptionToUserStatus("Vote");
                    vM.InsertDescriptionToUserStatus("Not Vote");
                    vM.InsertDescriptionToUserStatus("Age-rule");

                    statusId = vM.GetUserStatusIdByDescriptio(statusDescription);
                }



                var user = new ApplicationUser
                {
                    FirstName = model.FirstName,
                    Surname   = model.Surname,
                    DOB       = model.DOB,
                    UserName  = model.Email,

                    Email           = model.Email,
                    Gender          = model.Gender,
                    Country         = model.Country,
                    City            = model.City,
                    UserPic         = model.UserPic,
                    UserFingerprint = model.UserFingerprint,
                    UserStatusId    = model.UserStatusId
                };
                user.UserPic      = imageData;
                user.UserStatusId = statusId;
                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 https://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>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> Create(ExpandedUserDTO paramExpandedUserDTO)
        {
            try
            {
                if (paramExpandedUserDTO == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }

                // To convert the user uploaded Photo as Byte Array before save to DB
                byte[] imageData = null;
                if (Request.Files.Count > 0)
                {
                    HttpPostedFileBase poImgFile = Request.Files["UserPhoto"];

                    using (var binary = new BinaryReader(poImgFile.InputStream))
                    {
                        imageData = binary.ReadBytes(poImgFile.ContentLength);
                    }
                }



                var FirstName = paramExpandedUserDTO.FirstName.Trim();

                var Surname         = paramExpandedUserDTO.Surname.Trim();
                var DOB             = paramExpandedUserDTO.DOB.Trim();
                var UserName        = paramExpandedUserDTO.Email.Trim();
                var Email           = paramExpandedUserDTO.Email.Trim();
                var Gender          = paramExpandedUserDTO.Gender.Trim();
                var Country         = paramExpandedUserDTO.Country.Trim();
                var City            = paramExpandedUserDTO.City.Trim();
                var UserFingerprint = paramExpandedUserDTO.UserFingerprint.Trim();
                //var UserPic = paramExpandedUserDTO.UserPic.Trim();


                if (Email == "")
                {
                    throw new Exception("No Email");
                }

                if (paramExpandedUserDTO.Password == "")
                {
                    throw new Exception("No Password");
                }

                // set default status Id by the following description
                var statusDescription = "";
                var statusId          = "";

                VoteViewModel    vvM  = new VoteViewModel();
                GetAgeCalculated gAge = new GetAgeCalculated();
                int userAge           = gAge.GetAge(paramExpandedUserDTO.DOB);
                if (userAge >= 17)
                {
                    statusDescription = "Not Vote";
                }
                else
                {
                    statusDescription = "Age-rule";
                }
                statusId = vvM.GetUserStatusIdByDescriptio(statusDescription);
                // check if the statusId is empty than add the values to the table
                if (statusId == null)
                {
                    // set the default vote to the vote status table
                    VoteViewModel vM = new VoteViewModel();
                    vM.InsertDescriptionToUserStatus("Vote");
                    vM.InsertDescriptionToUserStatus("Not Vote");
                    vM.InsertDescriptionToUserStatus("Age-rule");

                    statusId = vM.GetUserStatusIdByDescriptio(statusDescription);
                }
                // UserName is LowerCase of the Email
                UserName = Email.ToLower();

                // Create user
                var objNewAdminUser = new ApplicationUser
                {
                    FirstName = paramExpandedUserDTO.FirstName,
                    Surname   = paramExpandedUserDTO.Surname,
                    DOB       = paramExpandedUserDTO.DOB,
                    UserName  = paramExpandedUserDTO.Email,

                    Email           = paramExpandedUserDTO.Email,
                    Gender          = paramExpandedUserDTO.Gender,
                    Country         = paramExpandedUserDTO.Country,
                    City            = paramExpandedUserDTO.City,
                    UserPic         = paramExpandedUserDTO.UserPic,
                    UserFingerprint = paramExpandedUserDTO.UserFingerprint,
                    UserStatusId    = paramExpandedUserDTO.UserStatusId
                };
                objNewAdminUser.UserPic      = imageData;
                objNewAdminUser.UserStatusId = statusId;
                //var AdminUserCreateResult = UserManager.Create(objNewAdminUser, paramExpandedUserDTO.Password);
                var result = await UserManager.CreateAsync(objNewAdminUser, paramExpandedUserDTO.Password);

                if (result.Succeeded)
                {
                    string strNewRole = Convert.ToString(Request.Form["Roles"]);

                    if (strNewRole != "0")
                    {
                        // Put user in role
                        UserManager.AddToRole(objNewAdminUser.Id, strNewRole);
                    }

                    return(Redirect("~/Admin"));
                }
                else
                {
                    ViewBag.Roles = GetAllRolesAsSelectList();
                    ModelState.AddModelError(string.Empty,
                                             "Error: Failed to create the user. Check password requirements.");
                    return(View(paramExpandedUserDTO));
                }
            }
            catch (Exception ex)
            {
                ViewBag.Roles = GetAllRolesAsSelectList();
                ModelState.AddModelError(string.Empty, "Error: " + ex);
                return(View("Create"));
            }
        }