예제 #1
0
        public ActionResult Reject(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.RejectedBy     = user;
                            fs.RejectedDate   = DateTime.Now;
                            fs.RejectedReason = vm.RejectedReason;
                            this.feedingSourceTasks.SaveFeedingSource(fs);

                            this.emailTasks.SendFeedingSourceRejectedEmail(fs);

                            return(RedirectToAction("Index"));
                        }
                        else
                        {
                            ModelState.AddModelError("RejectedBy", "User should delete rather than reject a source they uploaded themselves.");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("Id", "Feeding source doesn't exist.");
                    }
                }

                else
                {
                    ModelState.AddModelError("RejectedBy", "Logged-in user doesn't exist.");
                }
            }
            else
            {
                ModelState.AddModelError("Id", "No Id was sent.");
            }
            return(Approve(vm.Id));
        }
예제 #2
0
        public ActionResult Rename(FeedingSourceViewModel vm)
        {
            if (ModelState.IsValid)
            {
                FeedingSource fs = this.feedingSourceTasks.GetFeedingSource(vm.Id);
                if (fs != null)
                {
                    if (!((PrfPrincipal)User).CanAccess(fs))
                    {
                        return(new HttpUnauthorizedResult());
                    }

                    if (fs.ApprovedBy == null && fs.RejectedBy == null)
                    {
                        FeedingSource existing = this.feedingSourceTasks.GetFeedingSource(vm.Name);
                        if (existing == null || (existing != null && existing.Id == fs.Id))
                        {
                            Source s = this.sourceTasks.GetSource(vm.Name);
                            if (s == null)
                            {
                                fs.Name = vm.Name;
                                fs      = this.feedingSourceTasks.SaveFeedingSource(fs);

                                return(RedirectToAction("Index"));
                            }
                            else
                            {
                                ModelState.AddModelError("Name", "<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
                        {
                            ModelState.AddModelError("Name", "A file has already been uploaded with this name.");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("Name", "File is already approved and imported into database, or is rejected.");
                    }
                }
            }

            return(Rename(vm.Id));
        }
예제 #3
0
        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));
        }