Beispiel #1
0
        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));
        }
Beispiel #2
0
        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());
            }
        }
Beispiel #3
0
        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));
        }
Beispiel #4
0
        public async Task <IActionResult> EditEvidence(EvidenceForm evidenceForm)
        {
            if (evidenceForm.Files != null)
            {
                foreach (var uploadedFile in evidenceForm.Files)
                {
                    if (uploadedFile.Length > 10097152)
                    {
                        ModelState.AddModelError("Прикрепляемые файлы", $"Размер {uploadedFile.FileName} превышает 10 мб");
                    }
                }
            }

            if (ModelState.IsValid)
            {
                CompromisingEvidenceModel evidence = new CompromisingEvidenceModel();
                int Id;
                if (evidenceForm.EvidenceId == 0)
                {
                    evidence.UserId = await _userManager.GetUserAsync(HttpContext.User);

                    evidence.VotePlaceId = _votePlaceModelService.GetVotePlaceModel(evidenceForm.PlaceId);
                    evidence.CreatedAt   = DateTime.Now;
                    evidence.Comment     = evidenceForm.Comment;
                    Id = (_compromisingEvidenceModelService.InsertCompromisingEvidenceModel(evidence).Entity as CompromisingEvidenceModel).Id;
                }
                else
                {
                    evidence         = _compromisingEvidenceModelService.GetCompromisingEvidenceModel(evidenceForm.EvidenceId);
                    Id               = evidence.Id;
                    evidence.Comment = evidenceForm.Comment;
                    if ((await _userManager.GetUserAsync(HttpContext.User)) != evidence.UserId)
                    {
                        Notificator.EvidenceEdited(_notificationModelService, evidence);
                    }
                    _compromisingEvidenceModelService.UpdateCompromisingEvidenceModel(evidence);
                }
                if (evidenceForm.Files != null)
                {
                    List <int> oldFilesId = (
                        from F in _compromisingEvidenceFileModelService.GetCompromisingEvidenceFileModels()
                        where F.CompromisingEvidenceId.Id == Id
                        select F.Id
                        ).ToList();
                    foreach (int oldFileId in oldFilesId)
                    {
                        _compromisingEvidenceFileModelService.DeleteCompromisingEvidenceFileModel(oldFileId);
                    }

                    foreach (var uploadedFile in evidenceForm.Files)
                    {
                        string path = "/Files/" + $@"{Guid.NewGuid()}" + uploadedFile.FileName;

                        using (var fileStream = new FileStream(_appEnvironment.WebRootPath + path, FileMode.Create))
                        {
                            await uploadedFile.CopyToAsync(fileStream);
                        }
                        CompromisingEvidenceFileModel file = new CompromisingEvidenceFileModel {
                            Name = uploadedFile.FileName,
                            Path = path,
                            CompromisingEvidenceId = evidence
                        };
                        _compromisingEvidenceFileModelService.InsertCompromisingEvidenceFileModel(file);
                    }
                }
            }
            return(RedirectToAction(nameof(MapController.PlaceDetail), "Map", new { id = evidenceForm.PlaceId }));
        }