private void NewVotingData(VotingViewModel model) { var voting = new Voting { ActivityInClass = model.ActivityInClass, AvailabilityTeacherOutsideLessons = model.AvailabilityTeacherOutsideLessons, ClarityAndAccessibility = model.ClarityAndAccessibility, CommentsTheWork = model.CommentsTheWork, DepthPossessionOf = model.DepthPossessionOf, HowWellTheProcedurePerformedGrading = model.HowWellTheProcedurePerformedGrading, InterestInTheSubject = model.InterestInTheSubject, NumberOfAttendance = model.NumberOfAttendance, OverallSubject = model.OverallSubject, PreparationTime = model.PreparationTime, ProcedureGrading = model.ProcedureGrading, QualityMasteringTheSubject = model.QualityMasteringTheSubject, QualityTeachingMaterials = model.QualityTeachingMaterials, RelevantToStudents = model.RelevantToStudents, SomethingNew = model.SomethingNew, TheDifficultyOfTheCourse = model.TheDifficultyOfTheCourse, ThePracticalValue = model.ThePracticalValue, TeacherSubjectId = model.idTeacher }; db.Votings.Add(voting); db.SaveChanges(); }
public static MvcHtmlString Ratings(this HtmlHelper helper, VotingViewModel vote) { TagBuilder spanTag = new TagBuilder("span"); spanTag.AddCssClass("rating"); spanTag.MergeAttribute("id", string.Format("span{0}", vote.PhotoId)); spanTag.MergeAttribute("rating", string.Format("{0}", vote.Rating)); spanTag.MergeAttribute("photo", string.Format("{0}", vote.PhotoId)); spanTag.MergeAttribute("title", "Click to vote!"); for (int i = 1; i <= 5; i++) { TagBuilder imgTag = new TagBuilder("img"); imgTag.AddCssClass("star"); imgTag.MergeAttribute("alt", "star"); imgTag.MergeAttribute("width", "20"); imgTag.MergeAttribute("height", "20"); imgTag.MergeAttribute("value", string.Format("{0}", i)); imgTag.MergeAttribute("onclick", "clickStar(this);"); if (i <= vote.Rating) { imgTag.MergeAttribute("src", "/Content/images/star.png"); } else { imgTag.MergeAttribute("src", "/Content/images/starOff.png"); } spanTag.InnerHtml += imgTag.ToString(); } return(new MvcHtmlString(spanTag.ToString())); }
public async Task <IActionResult> Edit(Guid id, [Bind("ID,Name,Description,DueDate,CategoryId")] VotingViewModel voting) { if (id != voting.ID) { return(NotFound()); } if (ModelState.IsValid) { try { await _votingsService.Edit(voting); } catch (DbUpdateConcurrencyException) { if (!VotingExists(voting.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } var categories = await _categoriesService.GetAll(); ViewData["CategoryId"] = new SelectList(categories, "ID", "Name", voting.CategoryId); return(View(voting)); }
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); //this.RestoreState(); StateHelper helper = new StateHelper(State); Item = helper.GetValue("Exercise", Item); DataContext = new VotingViewModel(Item); }
public static VotingEntity ToBllVoting(this VotingViewModel votingViewModel) { return(new VotingEntity() { UserId = votingViewModel.UserId, PhotoId = votingViewModel.PhotoId, Rating = votingViewModel.Rating }); }
public IActionResult CreateVoting(VotingViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var id = _votingStorageService.RegisterVoting(model); return(RedirectToAction("Details", new { id = id })); }
public async Task Edit(VotingViewModel voting) { var _voting = await _votingRepository.GetVoteById(voting.ID); _voting.Name = voting.Name; _voting.Description = voting.Description; _voting.CategoryId = voting.CategoryId; _voting.DueDate = voting.DueDate; await _votingRepository.UpdateAsync(_voting); }
public async Task <IActionResult> Voting(VotingViewModel model) { if (!this.ModelState.IsValid) { model.Gifts = new SelectList(await this._votesRepository.GetAllGifts(), "Id", "Name"); return(View(model)); } await this._votesRepository.VoteForGift(model); return(RedirectToAction("ActiveVotes", "Votes")); }
public ActionResult doVoteProvincial(string VoterGUID, string id, string PartyID, string provinceID) { if (VoterGUID != null && PartyID != null && id != null) { VoterVM voterVM = new VoterVM(); if (voterVM.IsLogedIn(db, VoterGUID) && voterVM.voter.VoteProvinceStatus == false) { voterVM.RefreshGUID(db); VotingViewModel votingViewModel = new VotingViewModel(); votingViewModel.voterView = voterVM; if (votingViewModel.GetElectionDate() != null) { int ids = Convert.ToInt32(id); var v = db.Voters.Where(x => x.VoterID == ids).FirstOrDefault(); if (v != null) { //Gets the Election and increases the total votes by 1 Election getdateElection = votingViewModel.GetElectionDate(); ProvincialResult pr = new ProvincialResult(); pr.PartyID = Convert.ToInt32(PartyID); pr.ElectionID = getdateElection.ElectionID; pr.ProvincialResultsTotalVotes = 1; pr.ProvinceID = Convert.ToInt32(provinceID); v.VoteProvinceStatus = true; db.ProvincialResults.Add(pr); db.SaveChanges(); TempData["success"] = "You have successfully voted for a Provincial Government!"; return(RedirectToAction("VoterHomePage", new { VoterGUID = votingViewModel.voterView.voter.GUID, id = votingViewModel.voterView.voter.VoterID })); } else { TempData["message"] = "An Error Occured Please Try Again!"; return(RedirectToAction("VoteProvincial", new { VoterGUID = votingViewModel.voterView.voter.GUID, id = votingViewModel.voterView.voter.VoterID })); } } else { TempData["message"] = "An Error Occured Please Try Again!"; return(RedirectToAction("VoteProvincial", new { VoterGUID = votingViewModel.voterView.voter.GUID, id = votingViewModel.voterView.voter.VoterID })); } } else { TempData["message"] = "An Error Occured Please Try Again"; return(RedirectToAction("VoteProvincial", new { VoterGUID = VoterGUID, id = id })); } } else { TempData["message"] = "An Error Occured Please try again!"; return(RedirectToAction("VoteProvincial", new { VoterGUID = VoterGUID, id = id })); } }
public int RegisterVoting(VotingViewModel model) { var mapped = _mapper.Map <Voting>(model); mapped.Id = _votings.Count; lock (_votings) { _votings.Add(mapped); } return(mapped.Id); }
public async Task <IActionResult> Create([Bind("Name,Description,DueDate,CategoryId")] VotingViewModel voting) { if (ModelState.IsValid) { await _votingsService.Create(voting); return(RedirectToAction(nameof(Index))); } var categories = await _categoriesService.GetAll(); ViewData["CategoryId"] = new SelectList(categories, "ID", "Name"); return(View(voting)); }
public async Task <IActionResult> Voting(int id, string name) { var gifts = await this._votesRepository.GetAllGifts(); var model = new VotingViewModel() { Gifts = new SelectList(gifts, "Id", "Name"), LoggedUser = this.HttpContext.User.Identity.Name, VoteId = id }; this.ViewBag.Name = name; return(View(model)); }
public async Task VoteForGift(VotingViewModel voteModel) { var values = new SqlValuesBuilder().Add("VoteId", voteModel.VoteId) .Add("GiftId", voteModel.GiftId) .Add("LoggedUser", voteModel.LoggedUser) .Build(); string query = $@"INSERT INTO [dbo].[EmployeeVoteGift] (EmployeeId, VoteId, GiftId) VALUES ((SELECT TOP(1)Id FROM Employees AS e WHERE e.UserName = @LoggedUser), @VoteId, @GiftId )"; await this._context.ExecuteNonQuery(query, values); }
public ICollection <VotingViewModel> GetAllVotingsExceptForCurrentUserByIsClosed(string username, bool isClosed) { using (this.votingRepository) { IList <VotingViewModel> votings = this.votingRepository.GetAllVotingsExceptForCurrentUserByIsClosed(username, isClosed).ToList(); for (int i = 0; i < votings.Count; i++) { VotingViewModel voting = votings[i]; voting.Presents = voting.Presents.OrderByDescending(p => p.GiverNames.Count).ToList(); } return(votings); } }
private List <VoteResult> CheckForElectionWriteIns(VotingViewModel viewModel, List <VoteResult> electionResults, Ballot ballot) { if (viewModel.PresidentWriteIn.PrimeCandidateItem.Name != null) { electionResults = Manager.RankedVotingManager.AddRankingWriteInToElection(electionResults, viewModel.PresidentWriteIn, ballot.BallotId, viewModel.PresidentAndVicePres.First()); } if (viewModel.StateRepWriteIn.CandidateItem.Name != null) { electionResults = Manager.MultiVoteManager.AddMultiVoteWriteInToElection(electionResults, viewModel.StateRepWriteIn, ballot.BallotId, viewModel.StateRep.First()); } return(electionResults); }
public ActionResult Vote(VotingViewModel viewModel) { Log.Info("User Has Voted!"); var ballot = Manager.CreateBallot("National Election" + DateTime.Now, User.Id); Log.Info("Saving Results"); var electionResults = new List <VoteResult>(); electionResults = CheckForElectionWriteIns(viewModel, electionResults, ballot); TallyBallotVotes(viewModel, electionResults, ballot); Manager.SaveElectionResults(electionResults); Log.Info("Sending User to Home Screen"); TempData["Success"] = "You Successfully Voted!"; return(RedirectToAction("Index", "Home")); }
public async System.Threading.Tasks.Task<ActionResult> Votings(VotingViewModel model) { if (!ModelState.IsValid) return View(model); var votingControle = new VotingModel(); var studentData = await UserManager.FindByNameAsync(User.Identity.Name); if (votingControle.CheckVote(model.idTeacher, studentData)) return RedirectToAction("TimeOut"); votingControle.FixVoting(int.Parse(model.idTeacher.ToString()), studentData); votingControle.CalculateVotings(model); return RedirectToAction("VoitingMain", "Raiting"); }
public async Task Create(VotingViewModel voting) { var category = await _categoryRepository.GetCategoryById(voting.CategoryId); var _voting = new Voting { ID = new Guid(), Name = voting.Name, Description = voting.Description, CategoryId = voting.CategoryId, DueDate = voting.DueDate, VotersCount = 0, CreatedDate = DateTime.Now, Category = category }; await _votingRepository.AddAsync(_voting); }
public ActionResult VoteProvincial(string VoterGUID, string id) { VotingViewModel votingViewModel = new VotingViewModel(); if (votingViewModel.GetElectionDate() != null) { if (VoterGUID != null) { VoterVM voterVM = new VoterVM(); if (voterVM.IsLogedIn(db, VoterGUID) && voterVM.voter.VoteProvinceStatus == false) { voterVM.RefreshGUID(db); int ids = Convert.ToInt32(id); votingViewModel.voterView = voterVM; var v = db.Voters.Where(l => l.VoterID == ids).FirstOrDefault(); if (v != null) { votingViewModel.listcandidate = db.Candidates.Include(y => y.Party).Include(k => k.Party.PartyImage).Where(x => x.ProvinceID == v.ProvinceID && x.CandidatePosition_ID != 1).ToList(); return(View(votingViewModel)); } else { TempData["message"] = "You have already voted!"; return(RedirectToAction("VoterHomePage", new { VoterGUID = votingViewModel.voterView.voter.GUID })); } } else { TempData["message"] = "You have already voted!"; return(RedirectToAction("VoterHomePage", new { VoterGUID = VoterGUID })); } } else { TempData["message"] = "An Error Occured Please try again"; return(RedirectToAction("VoterHomePage", new { VoterGUID = VoterGUID })); } } else { TempData["message"] = "You can only vote on the set election date"; return(RedirectToAction("VoterHomePage", new { VoterGUID = VoterGUID })); } }
public ActionResult VoteParty(string VoterGUID, string id) { VotingViewModel votingViewModel = new VotingViewModel(); if (votingViewModel.GetElectionDate() != null) { if (VoterGUID != null) { VoterVM voterVM = new VoterVM(); if (voterVM.IsLogedIn(db, VoterGUID) && voterVM.voter.VotePartyStatus == false) { voterVM.RefreshGUID(db); votingViewModel.voterView = voterVM; votingViewModel.listcandidate = db.Candidates.Include(y => y.Party).Include(j => j.Party.PartyImage).Where(x => x.CandidatePosition_ID == 1).ToList(); votingViewModel.partiesImages = db.PartyImages.ToList(); ViewBag.message = TempData["message"]; ViewBag.success = TempData["success"]; return(View(votingViewModel)); } else { TempData["message"] = "You have already voted!"; return(RedirectToAction("VoterHomePage", "Voter", new { VoterGUID = VoterGUID })); } } else { TempData["message"] = "An Error Occured Please try again"; return(RedirectToAction("VoterHomePage", "Voter", new { VoterGUID = VoterGUID })); } } else { TempData["message"] = "You can only vote on the set election date"; return(RedirectToAction("VoterHomePage", new { VoterGUID = VoterGUID })); } }
public async System.Threading.Tasks.Task <ActionResult> Votings(VotingViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var votingControle = new VotingModel(); var studentData = await UserManager.FindByNameAsync(User.Identity.Name); if (votingControle.CheckVote(model.idTeacher, studentData)) { return(RedirectToAction("TimeOut")); } votingControle.FixVoting(int.Parse(model.idTeacher.ToString()), studentData); votingControle.CalculateVotings(model); return(RedirectToAction("VoitingMain", "Raiting")); }
private static void TallyBallotVotes(VotingViewModel viewModel, List <VoteResult> electionResults, Ballot ballot) { Log.Info("Tallying Votes"); electionResults.AddRange(viewModel.PresidentAndVicePres.Select(presidentAndVice => new VoteResult { VoteResultsId = Guid.NewGuid(), BallotId = ballot.BallotId, RankingVoteId = presidentAndVice.RankingVoteItemId, Ranking = presidentAndVice.Ranking, })); electionResults.AddRange(viewModel.StateRep.Select(stateRep => new VoteResult { VoteResultsId = Guid.NewGuid(), BallotId = ballot.BallotId, MultipleVoteId = stateRep.MultipleVoteItemId, VotedFor = stateRep.VotedFor, })); electionResults.Add(new VoteResult { VoteResultsId = Guid.NewGuid(), BallotId = ballot.BallotId, SingleVoteId = viewModel.SupremeCourt.SingleVoteTicketId, VoteYes = viewModel.SupremeCourt.YesVote, VoteNo = viewModel.SupremeCourt.NoVote, }); electionResults.Add(new VoteResult { VoteResultsId = Guid.NewGuid(), BallotId = ballot.BallotId, SingleVoteId = viewModel.BallotIssue.SingleVoteTicketId, VoteYes = viewModel.BallotIssue.YesVote, VoteNo = viewModel.BallotIssue.NoVote, }); }
public VotingViewModel Voiting(int id, int? groupId, string userId) { var query = (from listTeachers in db.Teachers from Subjectslist in db.Subjects from listTeacherSubject in db.TeacherSubject .Where(list => list.Id == id && list.TeacherId == listTeachers.TeacherId && list.SubjectId == Subjectslist.Id) select listTeachers).ToList(); var querySubjectName = (from subjectsList in db.Subjects from teacherSubjectList in db.TeacherSubject .Where(list => list.Id == id && list.SubjectId == subjectsList.Id) select subjectsList).ToList(); //----- var Group = db.Groups.Where(n => n.GroupId == groupId).ToList(); var listS = new List<int>(); foreach (var s in Group) { foreach (var st in s.TeachersSubjects) { listS.Add(st.Id); } } var queryTeacherList = from listTeacher in db.Teachers from listRaiting in db.Ratings from listSubject in db.Subjects from listTeachersSubject in db.TeacherSubject .Where(listTeachersSubj => (listS.Contains(listTeachersSubj.Id) && listSubject.Id == listTeachersSubj.SubjectId && listTeacher.TeacherId == listTeachersSubj.TeacherId && listRaiting.TeacherId == listTeacher.TeacherId)) orderby listRaiting.AvgRating descending select new ListOfTeachers() { TeacherId = listTeacher.TeacherId, Name = listTeacher.Name, SurName = listTeacher.SurName, LastName = listTeacher.LastName, PathToPhoto = listTeacher.PathToPhoto, Description = listTeacher.Description, AvgRating = listRaiting.AvgRating, IdForVoiting = listTeachersSubject.Id, SubjectName = listSubject.Name }; IEnumerable<StudentVoting> votingUserList = db.StudentVotings.Where(m => m.StudentId == userId && m.Date.Month == DateTime.Now.Month); var teacherVote = new List<int>(); foreach (var votingUserData in votingUserList) { teacherVote.Add(int.Parse(votingUserData.TeachersSubjectId.ToString())); } var teacherNotVote = new List<int>(); foreach (var teacherData in queryTeacherList) { if (!teacherVote.Contains(teacherData.IdForVoiting)) teacherNotVote.Add(teacherData.IdForVoiting); } //-------- var info = new VotingViewModel { idTeacher = id, teacherName = query[0].LastName.ToString() + " " + query[0].Name.ToString() + " " + query[0].SurName.ToString(), pathToPhoto = query[0].PathToPhoto, SubjectName = querySubjectName[0].Name, TeacherNotVote = teacherNotVote }; return info; }
public void CalculateVotings(VotingViewModel model) { NewVotingData(model); RecalculaitingValuation(model.idTeacher); RecalculateRaitingValuation(model.idTeacher); }
public VotingViewModel Voiting(int id, int?groupId, string userId) { var query = (from listTeachers in db.Teachers from Subjectslist in db.Subjects from listTeacherSubject in db.TeacherSubject .Where(list => list.Id == id && list.TeacherId == listTeachers.TeacherId && list.SubjectId == Subjectslist.Id) select listTeachers).ToList(); var querySubjectName = (from subjectsList in db.Subjects from teacherSubjectList in db.TeacherSubject .Where(list => list.Id == id && list.SubjectId == subjectsList.Id) select subjectsList).ToList(); //----- var Group = db.Groups.Where(n => n.GroupId == groupId).ToList(); var listS = new List <int>(); foreach (var s in Group) { foreach (var st in s.TeachersSubjects) { listS.Add(st.Id); } } var queryTeacherList = from listTeacher in db.Teachers from listRaiting in db.Ratings from listSubject in db.Subjects from listTeachersSubject in db.TeacherSubject .Where(listTeachersSubj => (listS.Contains(listTeachersSubj.Id) && listSubject.Id == listTeachersSubj.SubjectId && listTeacher.TeacherId == listTeachersSubj.TeacherId && listRaiting.TeacherId == listTeacher.TeacherId)) orderby listRaiting.AvgRating descending select new ListOfTeachers() { TeacherId = listTeacher.TeacherId, Name = listTeacher.Name, SurName = listTeacher.SurName, LastName = listTeacher.LastName, PathToPhoto = listTeacher.PathToPhoto, Description = listTeacher.Description, AvgRating = listRaiting.AvgRating, IdForVoiting = listTeachersSubject.Id, SubjectName = listSubject.Name }; IEnumerable <StudentVoting> votingUserList = db.StudentVotings.Where(m => m.StudentId == userId && m.Date.Month == DateTime.Now.Month); var teacherVote = new List <int>(); foreach (var votingUserData in votingUserList) { teacherVote.Add(int.Parse(votingUserData.TeachersSubjectId.ToString())); } var teacherNotVote = new List <int>(); foreach (var teacherData in queryTeacherList) { if (!teacherVote.Contains(teacherData.IdForVoiting)) { teacherNotVote.Add(teacherData.IdForVoiting); } } //-------- var info = new VotingViewModel { idTeacher = id, teacherName = query[0].LastName.ToString() + " " + query[0].Name.ToString() + " " + query[0].SurName.ToString(), pathToPhoto = query[0].PathToPhoto, SubjectName = querySubjectName[0].Name, TeacherNotVote = teacherNotVote }; return(info); }
public VotingController() { Manager = new VotingManager(); ViewModel = new VotingViewModel(); User = System.Web.HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId()); }
public ICollection <VotingViewModel> GetAllVotingsExceptForCurrentUserByIsClosed(string username, bool isClosed) { SqlDataReader reader = this.ExecuteReader( @"SELECT vote.Id, vote.CreatorUsername, vote.CreatorName, vote.ReceiverUsername, vote.ReceiverName, eg.Username AS GiverUsername, eg.Name AS GiverName, p.Name AS PresentName, vote.ClosingDate FROM (SELECT v.Id, v.ClosingDate, ec.Username AS CreatorUsername, ec.Name AS CreatorName, er.Username AS ReceiverUsername, er.Name AS ReceiverName FROM Votings AS v JOIN Employees AS ec ON v.CreatorId = ec.Id JOIN Employees AS er ON v.ReceiverId = er.Id WHERE er.Username != @username AND v.IsClosed = @isClosed ) AS vote JOIN VotingPresents AS vp ON vp.VotingId = vote.Id JOIN Presents AS p ON vp.PresentId = p.Id JOIN Employees AS eg ON vp.EmployeeId = eg.Id", new Dictionary <string, object> { { "@username", username }, { "@isClosed", isClosed } }); ICollection <VotingViewModel> votings = new List <VotingViewModel>(); using (reader) { while (reader.Read()) { int id = reader.GetInt32(0); string creatorUsername = reader.GetString(1); string creatorName = reader.GetString(2); string receiverUsername = reader.GetString(3); string receiverName = reader.GetString(4); string giverUsername = reader.GetString(5); string giverName = reader.GetString(6); string presentName = reader.GetString(7); DateTime closingDate = reader.GetDateTime(8); string creatorNameRepresentation = this.CombineUsernameAndName(creatorUsername, creatorName); string receiverNameRepresentation = this.CombineUsernameAndName(receiverUsername, receiverName); string giverNameRepresentation = this.CombineUsernameAndName(giverUsername, giverName); VotingViewModel voting = null; if (votings.Any(v => v.Id == id)) { voting = votings.First(v => v.Id == id); } else { voting = new VotingViewModel(id, closingDate, creatorNameRepresentation, receiverNameRepresentation, isClosed); votings.Add(voting); } PresentWithGiversDescription present = null; if (voting.Presents.Any(p => p.Name == presentName)) { present = voting.Presents.First(p => p.Name == presentName); } else { present = new PresentWithGiversDescription(presentName); voting.Presents.Add(present); } present.GiverNames.Add(giverNameRepresentation); } } return(votings); }
public VotingDTResponse() { ListVoting = new List <VotingViewModel>(); Voting = new VotingViewModel(); }