public async Task <ActionResult> UserDelete(string Id) { var user = await _userManager.FindByIdAsync(Id); var evidences = _compromisingEvidenceModelService.GetCompromisingEvidenceModels(); var evidences_files = _compromisingEvidenceFileModelService.GetCompromisingEvidenceFileModels(); IList <NotificationModel> notifications = (from N in _notificationModelService.GetNotificationModels() where N.ApplicationGetterId == user select N).ToList(); IList <CompromisingEvidenceModel> user_evidences = ( from E in evidences where E.UserId == user select E).ToList(); foreach (var evidence in user_evidences) { IList <CompromisingEvidenceFileModel> files = (from F in evidences_files where F.CompromisingEvidenceId == evidence select F).ToList(); foreach (var file in files) { _compromisingEvidenceFileModelService.DeleteCompromisingEvidenceFileModel(file.Id); } _compromisingEvidenceModelService.DeleteCompromisingEvidenceModel(evidence.Id); } foreach (var notification in notifications) { _notificationModelService.DeleteNotificationModel(notification.Id); } await _userManager.DeleteAsync(user); return(RedirectToAction(nameof(Users))); }
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 })); }