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 void UpdateCompromisingEvidenceModel(CompromisingEvidenceModel voteModel) { repository.Update(voteModel); }
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 })); }
public EntityEntry InsertCompromisingEvidenceModel(CompromisingEvidenceModel voteModel) { return(repository.Insert(voteModel)); }
static public void EvidenceEdited(INotificationModelService notificationModelService, CompromisingEvidenceModel evidence) { notificationModelService.InsertNotificationModel(new NotificationModel { ApplicationGetterId = evidence.UserId, CreatedAt = DateTime.Now, Message = $"EvidenceChanged" }); }