private void EvidenceLabel_Click(object sender, EventArgs e) { EvidenceForm evidence = new EvidenceForm(); evidence.MdiParent = this; evidence.Show(); }
public async Task <IViewComponentResult> InvokeAsync(int id) { if (id != 0) { CompromisingEvidenceModel compromisingEvidenceModel = _compromisingEvidenceModelService.GetCompromisingEvidenceModel(id); var files = await( from F in _compromisingEvidenceFileModelService.GetCompromisingEvidenceFileModels() where F.CompromisingEvidenceId.Id == id select F ).ToListAsync(); EvidenceForm evidenceForm = new EvidenceForm() { Comment = compromisingEvidenceModel.Comment, PlaceId = compromisingEvidenceModel.VotePlaceId.Id, EvidenceId = compromisingEvidenceModel.Id }; ViewBag.isAuthenticated = HttpContext.User.Identity.IsAuthenticated; ViewBag.Files = files; ViewBag.Create = false; return(View(evidenceForm)); } else { ViewBag.Create = true; return(View()); } }
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 <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 })); }