public async Task <ActionResult> PlaceDetail(int id) { VotePlaceModel place = _votePlaceModelService.GetVotePlaceModel(id); //if (place == null) //{ // return RedirectToAction("Error", "Vote", new { text = $"There is no any place with id = {id}" }); //} var evidences_raw = (from E in _compromisingEvidenceModelService.GetCompromisingEvidenceModels() where E.VotePlaceId.Id == id select E).Include("UserId"); List <CompromisingEvidenceModel> evidences_pre = evidences_raw.ToList(); List <EvidenceEntity> evidences = new List <EvidenceEntity>(); // TODO: Try to optimize image loading uint index = 0; foreach (var ev in evidences_pre) { //ev.UserId = await _userManager.GetUserAsync(HttpContext.User); index++; evidences.Add( new EvidenceEntity() { Evidence = ev, Files = await( from F in _compromisingEvidenceFileModelService.GetCompromisingEvidenceFileModels() where F.CompromisingEvidenceId.Id == ev.Id select F ).ToListAsync(), Email = ev.UserId?.Email, index = index }); } var TotalVotes = (from V in _voteModelService.GetVoteModels() where V.VotePlaceId.Id == id select V.TargetId).Count(); ViewBag.TotalVotes = TotalVotes; ViewBag.TotalEvidences = evidences.Count(); ViewBag.Region = place.Region; ViewBag.Town = place.Town; ViewBag.Street = place.Street; ViewBag.House = place.House; ViewBag.Id = place.Id; ViewBag.evidences = evidences; ViewBag.isAuthenticated = HttpContext.User.Identity.IsAuthenticated; var evidenceForm = new EvidenceForm() { PlaceId = place.Id }; return(View(evidenceForm)); }
public async Task <ActionResult> Index(VoteForm voteForm) { if (_phoneNumberModelService.GetPhoneNumberModels().Where(phone => phone.PhoneNumber == voteForm.PhoneNumber).ToList().Count != 0) { ModelState.AddModelError("Телефонный номер", "Голос с использованием такого номера уже есть!"); } if (voteForm.Place == null) { ModelState.AddModelError("Место для голосования", "Пожалуйста, выберите место для голосования."); } if (ModelState.IsValid) { TargetModel target = _targetModelService.GetTargetModel(Convert.ToInt32(voteForm.Target)); VotePlaceModel place = _votePlaceModelService.GetVotePlaceModel(Convert.ToInt32(voteForm.Place)); VoteProcessModel process = _voteProcessModelService.GetVoteProcessModels().ToList().Last(); PhoneNumberModel phoneNumber; if (HttpContext.User.Identity.IsAuthenticated) { ApplicationUser user = await _userManager.GetUserAsync(User); phoneNumber = new PhoneNumberModel() { PhoneNumber = user.PhoneNumber }; } else { phoneNumber = new PhoneNumberModel() { PhoneNumber = voteForm.PhoneNumber }; } _voteModelService.InsertVoteModel( new VoteModel() { CreatedAt = DateTime.Now, TargetId = target, VotePlaceId = place, PhoneNumberId = phoneNumber, VoteProcessId = process }); _logger.LogInformation($"{voteForm.PhoneNumber} voted"); await _hubContext.Clients.All.SendAsync("Stat", "update"); return(RedirectToAction(nameof(VoteSuccess))); } else { return(await Index()); } }
public ActionResult PlaceDetail(string id) { VotePlaceModel place = new VotePlaceModel() { Id = 0, House = "", Region = "", Street = "", Town = "", x = 0, y = 0 }; if (id != null) { place = _votePlaceModelService.GetVotePlaceModel(int.Parse(id)); } return(View(place)); }
public ActionResult PlaceDetail(VotePlaceModel place) { if (ModelState.IsValid) { if (place.Id != 0) { _votePlaceModelService.UpdateVotePlaceModel(place); return(RedirectToAction(nameof(PlaceDetail), new { id = place.Id.ToString() })); } else { _votePlaceModelService.InsertVotePlaceModel(place); return(RedirectToAction(nameof(Places))); } } else { return(RedirectToAction(nameof(PlaceDetail), new { id = place.Id.ToString() })); } }
public async Task <IViewComponentResult> InvokeAsync(int id, bool showDetail) { VotePlaceModel place = await(from VP in _context.VotePlace where VP.Id == id select VP).FirstAsync(); var evidences_raw = (from E in _context.CompromisingEvidence where E.VotePlaceId.Id == id select E).Include("UserId").Include("VotePlaceId"); List <CompromisingEvidenceModel> evidences_pre = evidences_raw.ToList(); var TotalVotes = (from V in _context.Vote where V.VotePlaceId.Id == id select V.TargetId).Count(); ViewBag.TotalVotes = TotalVotes; ViewBag.TotalEvidences = evidences_pre.Count(); ViewBag.Region = place.Region; ViewBag.Town = place.Town; ViewBag.Street = place.Street; ViewBag.House = place.House; ViewBag.Id = place.Id; ViewBag.showDetail = showDetail; return(View()); }
public void UpdateVotePlaceModel(VotePlaceModel voteModel) { repository.Update(voteModel); }
public EntityEntry InsertVotePlaceModel(VotePlaceModel voteModel) { return(repository.Insert(voteModel)); }