public void DeleteSourceOwningEntity(SourceOwningEntity soe) { if (soe != null && !soe.AdminUsers.Any() && !soe.Sources.Any()) { this.sourceOwningEntityRepo.Delete(soe); } }
public SourceOwningEntityViewModel(SourceOwningEntity soe) { if (soe != null) { this.Id = soe.Id; this.Name = soe.Name; this.SourcePathPrefix = soe.SourcePathPrefix; } }
public ActionResult Delete(int id) { SourceOwningEntity soe = this.sourcePermissionTasks.GetSourceOwningEntity(id); if (soe != null) { this.sourcePermissionTasks.DeleteSourceOwningEntity(soe); return(RedirectToAction("Index")); } return(new HttpNotFoundResult()); }
public ActionResult Edit(int id) { SourceOwningEntity soe = this.sourcePermissionTasks.GetSourceOwningEntity(id); if (soe != null) { SourceOwningEntityViewModel vm = new SourceOwningEntityViewModel(soe); return(View(vm)); } return(new HttpNotFoundResult()); }
public ActionResult Create(SourceOwningEntityViewModel vm) { if (this.sourcePermissionTasks.GetSourceOwningEntities(vm.Name).Any()) { ModelState.AddModelError("Name", "Name must be unique."); } if (ModelState.IsValid) { SourceOwningEntity soe = new SourceOwningEntity(); soe.Name = vm.Name; soe.SourcePathPrefix = vm.SourcePathPrefix; soe = this.sourcePermissionTasks.SaveSourceOwningEntity(soe); return(RedirectToAction("Index")); } return(Create()); }
public JsonNetResult Name(int id) { SourceOwningEntity e = this.sourcePermissionTasks.GetSourceOwningEntity(id); if (e != null) { return(JsonNet(new { Id = id, Name = e.Name })); } else { return(JsonNet(string.Empty)); } }
public ActionResult Edit(SourceOwningEntityViewModel vm) { SourceOwningEntity soe = this.sourcePermissionTasks.GetSourceOwningEntity(vm.Id); if (soe != null) { if (this.sourcePermissionTasks.GetSourceOwningEntities(vm.Name).Where(x => x.Id != soe.Id).Any()) { ModelState.AddModelError("Name", "Name must be unique."); } if (ModelState.IsValid) { soe.Name = vm.Name; soe.SourcePathPrefix = vm.SourcePathPrefix; soe = this.sourcePermissionTasks.SaveSourceOwningEntity(soe); return(RedirectToAction("Index")); } return(Edit(vm.Id)); } return(new HttpNotFoundResult()); }
public SourceOwningEntity SaveSourceOwningEntity(SourceOwningEntity soe) { return(this.sourceOwningEntityRepo.SaveOrUpdate(soe)); }
protected FeedingSource ProcessUpload(MultipleUploadViewModel vm, int index) { // we use this flag instead of ModelState.IsValid because we need to reset this value for every file; ModelState.IsValid is a single flag for all uploaded files. bool hasError = false; using (Stream fileStream = vm.FileData[index].InputStream) { // Progressively check for duplicates, most reliable check first. Only return one duplicate validation error if any. // check Source hash duplicate string hash = BitConverter.ToString(MD5.Create().ComputeHash(fileStream)).Replace("-", ""); IList <SourceDTO> dtos = this.sourceTasks.GetSources(hash); if (dtos != null && dtos.Count > 0) { hasError = true; ModelState.AddModelError( "FileData", "An identical source (<a href='" + Url.Action("Index", "Sources", new { area = "Profiling" }) + "#info/" + dtos.First().SourceID + "' target='_blank'>" + dtos.First().SourceName + "</a>) exists already with Source ID of " + dtos.First().SourceID + "." ); } else { // check Source name duplicate Source s = this.sourceTasks.GetSource(vm.FileData[index].FileName); if (s != null) { hasError = true; ModelState.AddModelError( "FileData", "<a href='" + Url.Action("Index", "Sources", new { area = "Profiling" }) + "#info/" + s.Id + "' target='_blank'>" + s.SourceName + "</a> exists already with Source ID of " + s.Id + ". If you're sure you have a different file, rename it before uploading." ); } else { // check FeedingSource name duplicate FeedingSource fs = this.feedingSourceTasks.GetFeedingSource(vm.FileData[index].FileName); if (fs != null) { hasError = true; ModelState.AddModelError( "FileData", "<a href='" + Url.Action("Details", "Feeding", new { area = "Sources", id = fs.Id }) + "' target='_blank'>" + vm.FileData[index].FileName + "</a> was already uploaded; delete it or change your file name." ); } } } AdminUser user = this.userTasks.GetAdminUser(User.Identity.Name); if (user == null) { hasError = true; ModelState.AddModelError("UploadedBy", "Logged-in user doesn't appear to be exist."); } if (vm.IsReadOnly && string.IsNullOrEmpty(vm.UploadNotes)) { hasError = true; ModelState.AddModelError("UploadNotes", "Read-only sources should have a justification in the notes."); } if (!hasError) { FeedingSource fs = new FeedingSource(); fs.Name = Path.GetFileName(vm.FileData[index].FileName); fs.Restricted = vm.Restricted; fs.IsReadOnly = vm.IsReadOnly; fs.IsPublic = vm.IsPublic; fs.FileModifiedDateTime = vm.FileModifiedDateTime != null && vm.FileModifiedDateTime[index] != null ? vm.FileModifiedDateTime[index] : DateTime.Now; fs.UploadedBy = user; fs.UploadDate = DateTime.Now; fs.UploadNotes = vm.UploadNotes; if (!string.IsNullOrEmpty(vm.AuthorIds)) { string[] ids = vm.AuthorIds.Split(','); foreach (string id in ids) { int result; if (int.TryParse(id, out result)) { SourceAuthor a = this.sourcePermissionTasks.GetSourceAuthor(result); if (a != null) { fs.SourceAuthors.Add(a); } } } } if (!string.IsNullOrEmpty(vm.OwnerIds)) { string[] ids = vm.OwnerIds.Split(','); foreach (string id in ids) { int result; if (int.TryParse(id, out result)) { SourceOwningEntity e = this.sourcePermissionTasks.GetSourceOwningEntity(result); if (e != null) { fs.SourceOwningEntities.Add(e); } } } } fileStream.Position = 0; // we read the stream earlier when computing hash MemoryStream memoryStream = fileStream as MemoryStream; if (memoryStream == null) { memoryStream = new MemoryStream(); fileStream.CopyTo(memoryStream); } fs.FileData = memoryStream.ToArray(); return(fs); } return(null); } }
public ActionResult Approve(FeedingSourceViewModel vm) { if (vm != null && vm.Id > 0) { AdminUser user = this.userTasks.GetAdminUser(User.Identity.Name); if (user != null) { FeedingSource fs = this.feedingSourceTasks.GetFeedingSource(vm.Id); if (fs != null) { if (!((PrfPrincipal)User).CanAccess(fs)) { return(new HttpUnauthorizedResult()); } if (fs.UploadedBy != user) { fs.ApprovedBy = user; fs.ApprovedDate = DateTime.Now; fs.Restricted = vm.Restricted; fs.IsReadOnly = vm.IsReadOnly; fs.IsPublic = vm.IsPublic; fs.UploadNotes = vm.UploadNotes; if (!string.IsNullOrEmpty(vm.AuthorIds)) { fs.SourceAuthors.Clear(); string[] ids = vm.AuthorIds.Split(','); foreach (string id in ids) { int result; if (int.TryParse(id, out result)) { SourceAuthor a = this.sourcePermissionTasks.GetSourceAuthor(result); if (a != null) { fs.SourceAuthors.Add(a); } } } } if (!string.IsNullOrEmpty(vm.OwnerIds)) { fs.SourceOwningEntities.Clear(); string[] ids = vm.OwnerIds.Split(','); foreach (string id in ids) { int result; if (int.TryParse(id, out result)) { SourceOwningEntity e = this.sourcePermissionTasks.GetSourceOwningEntity(result); if (e != null) { fs.SourceOwningEntities.Add(e); } } } } fs = this.feedingSourceTasks.SaveFeedingSource(fs); Source source = this.feedingSourceTasks.FeedSource(fs.Id); this.emailTasks.SendFeedingSourceApprovedEmail(fs); return(RedirectToAction("Index")); } else { ModelState.AddModelError("ApprovedBy", "User cannot approve a source they uploaded themselves."); } } else { ModelState.AddModelError("Id", "Feeding source doesn't exist."); } } else { ModelState.AddModelError("ApprovedBy", "Logged-in user doesn't exist."); } } else { ModelState.AddModelError("Id", "No Id was sent."); } return(Approve(vm.Id)); }
public ActionResult Edit(UserViewModel vm) { if (ModelState.IsValid) { AdminUser u = this.userTasks.GetAdminUser(vm.Id); u.Email = vm.Email; u.AdminRoles.Clear(); if (!string.IsNullOrEmpty(vm.AdminRoleIds)) { string[] ids = vm.AdminRoleIds.Split(','); foreach (string id in ids) { int result; if (int.TryParse(id, out result)) { AdminRole r = this.userTasks.GetAdminRole(result); if (r != null) { u.AdminRoles.Add(r); } } } } u.Affiliations.Clear(); if (!string.IsNullOrEmpty(vm.SourceOwningEntityIds)) { string[] ids = vm.SourceOwningEntityIds.Split(','); foreach (string id in ids) { int result; if (int.TryParse(id, out result)) { SourceOwningEntity e = this.sourcePermissionTasks.GetSourceOwningEntity(result); if (e != null) { u.Affiliations.Add(e); } } } } if (vm.RequestEntityID.HasValue) { this.requestTasks.SetRequestEntity(vm.RequestEntityID.Value, vm.Id); } else { foreach (RequestEntity re in this.requestTasks.GetRequestEntities()) { u.RemoveRequestEntity(re); } } if (vm.ScreeningEntityID.HasValue) { this.screeningTasks.SetScreeningEntity(vm.ScreeningEntityID.Value, vm.Id); } else { foreach (ScreeningEntity se in this.screeningTasks.GetScreeningEntities()) { u.RemoveScreeningEntity(se); } } } return(RedirectToAction("Details", new { id = vm.Id })); }
public JsonNetResult Edit(SourceViewModel vm) { if (ModelState.IsValid) { Source s = this.sourceTasks.GetSource(vm.Id); s.FullReference = vm.FullReference; s.Notes = vm.Notes; s.IsRestricted = vm.IsRestricted; s.IsReadOnly = vm.IsReadOnly; s.IsPublic = vm.IsPublic; s.Archive = vm.Archive; s.SourceAuthors.Clear(); if (!string.IsNullOrEmpty(vm.SourceAuthorIds)) { string[] ids = vm.SourceAuthorIds.Split(','); foreach (string id in ids) { int result; if (int.TryParse(id, out result)) { SourceAuthor a = this.sourcePermissionTasks.GetSourceAuthor(result); if (a != null) { s.SourceAuthors.Add(a); } } } } s.SourceOwningEntities.Clear(); if (!string.IsNullOrEmpty(vm.SourceOwningEntityIds)) { string[] ids = vm.SourceOwningEntityIds.Split(','); foreach (string id in ids) { int result; if (int.TryParse(id, out result)) { SourceOwningEntity e = this.sourcePermissionTasks.GetSourceOwningEntity(result); if (e != null) { s.SourceOwningEntities.Add(e); } } } } s = this.sourceTasks.SaveSource(s); // queue indexing BackgroundJob.Enqueue <ISourceTasks>(x => x.IndexSourceQueueable(s.Id, s.HasUploadedBy() ? s.GetUploadedBy().UserID : string.Empty, s.SourceAuthors.Select(y => y.Author).ToList(), s.SourceOwningEntities.Select(y => y.Name).ToList(), s.JhroCase != null ? s.JhroCase.CaseNumber : string.Empty, this.sourceTasks.GetSourceDTO(s.Id).FileSize) ); return(JsonNet(string.Empty)); } return(JsonNet(this.GetErrorsForJson())); }