コード例 #1
0
        private ActionResult ListView(int count, IList <Post> posts)
        {
            var summaries = posts.MapTo <PostsViewModel.PostSummary>();

            foreach (var post in posts)
            {
                if (string.IsNullOrWhiteSpace(post.AuthorId))
                {
                    continue;
                }

                var author = RavenSession.Load <User>(post.AuthorId);
                if (author == null)
                {
                    continue;
                }

                var postSummary = summaries.First(x => x.Id == RavenIdResolver.Resolve(post.Id));
                postSummary.Author = author.MapTo <PostsViewModel.PostSummary.UserDetails>();
            }
            return(View("List", new PostsViewModel
            {
                CurrentPage = CurrentPage,
                PostsCount = count,
                Posts = summaries
            }));
        }
コード例 #2
0
        public override void Execute()
        {
            foreach (var e in _evaluators)
            {
                if (e.Action == EvaluatorAction.Add)
                {
                    if (_employeeEvaluation.UserName != e.UserName)
                    {
                        var employee = RavenSession
                                       .Query <Employee, EmployeeByUserName_Search>()
                                       .Where(x => x.UserName == e.UserName)
                                       .FirstOrDefault();

                        if (employee != null)
                        {
                            var evId = _employeeEvaluation.Id ?? EmployeeEvaluation.GenerateEvaluationId(_employeeEvaluation.Period, _employeeEvaluation.UserName);
                            ExecuteCommand(new GenerateCalificationCommand(_employeeEvaluation.Period, _employeeEvaluation.UserName, e.UserName, _employeeEvaluation.TemplateId, CalificationType.Evaluator, evId));
                        }
                        else
                        {
                            throw new ApplicationException(string.Format("Error: Evaluador no valido: {0}.", e.UserName));
                        }
                    }
                }
                else
                {
                    var id           = EvaluationCalification.GenerateCalificationId(_employeeEvaluation.Period, _employeeEvaluation.UserName, e.UserName);
                    var calification = RavenSession.Load <EvaluationCalification>(id);
                    if (calification != null)
                    {
                        RavenSession.Delete(calification);
                    }
                }
            }
        }
コード例 #3
0
        public ActionResult ChangePassword(ChangePasswordModel model)
        {
            if (ModelState.IsValid)
            {
                bool changePasswordSucceeded = false;
                try
                {
                    var currentUserName = User.Identity.Name;
                    var user            = RavenSession.Load <User>("Users/" + currentUserName);

                    if (user != null && user.ValidatePassword(model.OldPassword))
                    {
                        user.SetPassword(model.NewPassword);
                        changePasswordSucceeded = true;
                    }
                }
                catch (Exception)
                {
                    //TODO: do something?
                }

                if (changePasswordSucceeded)
                {
                    return(RedirectToAction("ChangePasswordSuccess"));
                }
                else
                {
                    ModelState.AddModelError("", "la contraseña actual no es correcta o la nueva contraseña no es válida.");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
コード例 #4
0
        public ActionResult DeleteConfirmed(int id)
        {
            LogEntry logentry = RavenSession.Load <LogEntry>(id);

            RavenSession.Delete <LogEntry>(logentry);
            return(RedirectToAction("Index"));
        }
コード例 #5
0
        public ActionResult Delete(string id)
        {
            var jobSearch = RavenSession.Load <JobSearch>(id);

            RavenSession.Delete(jobSearch);
            return(RedirectToAction("Index"));
        }
コード例 #6
0
ファイル: UserApiController.cs プロジェクト: jfreal/movidhep
        public ApiResponse SaveUser(UserPostedModel postedModel)
        {
            if (!ModelState.IsValid)
            {
                return(new ApiResponse("Validation errors occured."));
            }

            var user = RavenSession.Load <User>("users/" + postedModel.Id);

            if (user == null || user.AccountId != Account.Id)
            {
                return(new ApiResponse("User not found"));
            }

            if (!Ownership.Owns(user, this))
            {
                return(new ApiResponse("User not found"));
            }

            user.Name  = postedModel.Name;
            user.Email = postedModel.Email;
            RavenSession.SaveChanges();

            return(new ApiResponse(success: string.Format("User {0} edited", user.Email)));
        }
コード例 #7
0
ファイル: UserApiController.cs プロジェクト: jfreal/movidhep
        public ApiResponse Disable(int userId)
        {
            var user = RavenSession.Load <User>("users/" + userId);

            if (user == null || user.AccountId != Account.Id)
            {
                return(new ApiResponse("User not found"));
            }

            if (!Ownership.Owns(user, this))
            {
                return(new ApiResponse("User not found"));
            }

            if (user.Status != UserStatus.Disabled)
            {
                user.Status = UserStatus.Active;
            }

            if (user.Status != UserStatus.Active)
            {
                user.Status = UserStatus.Disabled;
            }

            RavenSession.SaveChanges();

            return(new ApiResponse(success: "User status changed"));
        }
コード例 #8
0
        public ActionResult ChangePassword(ChangePasswordModel input)
        {
            if (!ModelState.IsValid)
            {
                return(View("ChangePassword", input));
            }

            var user = RavenSession.Load <User>(input.Id);

            if (user == null)
            {
                return(HttpNotFound("User does not exist."));
            }

            if (user.ValidatePassword(input.OldPassword) == false)
            {
                ModelState.AddModelError("OldPassword", "Old password did not match existing password");
            }

            if (ModelState.IsValid == false)
            {
                return(View(input));
            }

            user.SetPassword(input.NewPassword);
            return(RedirectToAction("Index"));
        }
コード例 #9
0
        public ActionResult Delete(int id)
        {
            var user = RavenSession.Load <User>("users/" + id);

            if (user == null)
            {
                WarnUser("User could not be found.");
                return(RedirectToAction("Index"));
            }

            if (!Ownership.Owns(user, this))
            {
                return(HttpNotFound());
            }

            var exercises = RavenSession.Query <Exercise>(typeof(ByOwnableAndName).Name).
                            Where(x => !x.Master && (x.AccountId == user.AccountId)).Take(1024);

            foreach (var exercise in exercises)
            {
                RavenSession.Delete(exercise);
            }

            var account = RavenSession.Load <Account>("accounts/" + user.AccountId);

            RavenSession.Delete(account);
            RavenSession.Delete(user);

            RavenSession.SaveChanges();

            this.HighFive("User deleted.");

            return(RedirectToAction("Index"));
        }
コード例 #10
0
        private Boolean DeleteProject(Project project, ModelStateDictionary modelState)
        {
            if (project == null)
            {
                modelState.AddModelError("this", "A project must be supplied for deletion");
                return(false);
            }

            var existingProject = RavenSession.Load <Project>(project.Id);

            if (existingProject == null)
            {
                modelState.AddModelError("Id", "Project no longer exists");
                return(false);
            }
            else
            {
                var associatedUserStories = RavenSession.Query <UserStory>()
                                            .Where(us => us.ProjectId == existingProject.Id)
                                            .ToList();

                if (associatedUserStories != null)
                {
                    associatedUserStories.ForEach(RavenSession.Delete);
                }
            }

            RavenSession.Delete(existingProject);
            RavenSession.SaveChanges();

            return(true);
        }
コード例 #11
0
ファイル: HomeController.cs プロジェクト: CarlosGM/CommonJobs
        public ActionResult Attach(string id)
        {
            var entity = RavenSession.Load <object>(id);

            if (entity == null)
            {
                return(HttpNotFound("Specified entity does not exists"));
            }

            using (var attachmentReader = new RequestAttachmentReader(Request))
            {
                if (attachmentReader.Count != 1)
                {
                    throw new NotSupportedException("One and only one attachment is required.");
                }

                var attachment = attachmentReader.First();

                var result = ExecuteCommand(new SaveAttachment(
                                                entity,
                                                attachment.Key,
                                                attachment.Value));

                return(Json(new { success = true, attachment = result }));
            }
        }
コード例 #12
0
        //
        // GET: /Meeting/Details/5

        public ActionResult Details(int id)
        {
            MeetingDetailViewModel vm = new MeetingDetailViewModel();

            vm.Meeting = RavenSession.Load <Meeting>(id);
            return(View(vm));
        }
コード例 #13
0
        public ActionResult Details(string id)
        {
            var post = RavenSession
                       .Include <Post>(x => x.CommentsId)
                       .Load(id);

            if (post == null)
            {
                return(HttpNotFound());
            }

            var comments = RavenSession.Load <PostComments>(post.CommentsId);

            var vm = new AdminPostDetailsViewModel
            {
                Post = post.MapTo <AdminPostDetailsViewModel.PostDetails>(),

                Comments = comments.Comments
                           .Concat(comments.Spam)
                           .OrderBy(comment => comment.CreatedAt)
                           .MapTo <AdminPostDetailsViewModel.Comment>(),

                NextPost          = RavenSession.GetNextPrevPost(post, true),
                PreviousPost      = RavenSession.GetNextPrevPost(post, false),
                AreCommentsClosed = comments.AreCommentsClosed(post, BlogConfig.NumberOfDayToCloseComments),
            };

            return(View("Details", vm));
        }
コード例 #14
0
        public ActionResult Edit(ExerciseViewModel postedModel, string categories)
        {
            if (!ModelState.IsValid)
            {
                return(View(postedModel));
            }

            var exr = RavenSession.Load <MasterExercise>("masterexercises/" + postedModel.Id);

            if (!ApplicationAdministrator)
            {
                return(HttpNotFound());
            }

            UpdateModel(exr);

            string[] lines = categories.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
            exr.Categories = new List <string>(lines.Where(x => !string.IsNullOrWhiteSpace(x)));

            exr.Name = exr.Name.Trim();

            RavenSession.SaveChanges();
            HighFive("Master exercise edited ok.");

            return(RedirectToAction("List"));
        }
コード例 #15
0
        public ActionResult Get(string id, bool returnName = true)
        {
            var attachment = RavenSession.Load <Attachment>(id);

            if (attachment == null)
            {
                return(HttpNotFound());
            }

            var stream = Query(new ReadAttachment(attachment));

            if (stream == null)
            {
                return(HttpNotFound());
            }

            if (returnName)
            {
                return(File(stream, attachment.ContentType, attachment.FileName));
            }
            else
            {
                return(File(stream, attachment.ContentType));
            }
        }
コード例 #16
0
        public virtual ActionResult Index(BlogConfig config)
        {
            if (ModelState.IsValid == false)
            {
                ViewBag.Message = ModelState.FirstErrorMessage();
                if (Request.IsAjaxRequest())
                {
                    return(Json(new { Success = false, ViewBag.Message }));
                }
                return(View(BlogConfig));
            }

            var current = RavenSession.Load <BlogConfig>(BlogConfig.Key);

            if (IsFuturePostsEncryptionOptionsChanged(current, config))
            {
                RemoveFutureRssAccessOnEncryptionConfigChange();
            }

            RavenSession.Advanced.Evict(current);
            RavenSession.Store(config, BlogConfig.Key);
            RavenSession.SaveChanges();

            OutputCacheManager.RemoveItem(MVC.Section.Name, MVC.Section.ActionNames.ContactMe);

            ViewBag.Message = "Configurations successfully saved!";
            if (Request.IsAjaxRequest())
            {
                return(Json(new { Success = true, ViewBag.Message }));
            }
            return(View(config));
        }
コード例 #17
0
        public ActionResult Config(Config model)
        {
            Settings settings;

            using (RavenSession.Advanced.DocumentStore.DisableAggressiveCaching())
            {
                settings = RavenSession.Load <Settings>(Settings.DefaultId);
            }
            if (settings == null)
            {
                return(RedirectToAction("Auth"));
            }

            if (!ModelState.IsValid)
            {
                return(ConfigView(settings, model));
            }

            Mapper.Map(model, settings);
            RavenSession.Store(settings);

            Response.RemoveOutputCacheItem(Url.Content("~/Widgets/AnalyticsSummary"));

            return(RedirectToAction("Index"));
        }
コード例 #18
0
        public ActionResult Delete(string id)
        {
            var applicant = RavenSession.Load <Applicant>(id);

            RavenSession.Delete(applicant);
            return(RedirectToAction("Index"));
        }
コード例 #19
0
        public virtual ActionResult Details(int id, string slug, Guid key)
        {
            var post = RavenSession
                       .Include <Post>(x => x.CommentsId)
                       .Include(x => x.AuthorId)
                       .Load(id);

            if (post == null)
            {
                return(HttpNotFound());
            }

            if (post.IsPublicPost(key) == false)
            {
                return(HttpNotFound());
            }

            SeriesInfo seriesInfo = GetSeriesInfo(post.Title);

            var comments = RavenSession.Load <PostComments>(post.CommentsId) ?? new PostComments();
            var vm       = new PostViewModel
            {
                Post     = post.MapTo <PostViewModel.PostDetails>(),
                Comments = comments.Comments
                           .OrderBy(x => x.CreatedAt)
                           .MapTo <PostViewModel.Comment>(),
                NextPost          = RavenSession.GetNextPrevPost(post, true),
                PreviousPost      = RavenSession.GetNextPrevPost(post, false),
                AreCommentsClosed = comments.AreCommentsClosed(post, BlogConfig.NumberOfDayToCloseComments),
                SeriesInfo        = seriesInfo
            };

            vm.Post.Author = RavenSession.Load <User>(post.AuthorId).MapTo <PostViewModel.UserDetails>();

            var comment = TempData["new-comment"] as CommentInput;

            if (comment != null)
            {
                vm.Comments.Add(new PostViewModel.Comment
                {
                    CreatedAt = DateTimeOffset.Now.ToString(),
                    Author    = comment.Name,
                    Body      = MarkdownResolver.Resolve(comment.Body),
                    Id        = -1,
                    Url       = UrlResolver.Resolve(comment.Url),
                    Tooltip   = "Comment by " + comment.Name,
                    EmailHash = EmailHashResolver.Resolve(comment.Email)
                });
            }

            if (vm.Post.Slug != slug)
            {
                return(RedirectToActionPermanent("Details", new { id, vm.Post.Slug }));
            }

            SetWhateverUserIsTrustedCommenter(vm);

            return(View("Details", vm));
        }
コード例 #20
0
        public ActionResult QuickAttachment()
        {
            //The normal binding does not work
            var id            = RouteData.Values["id"] as string;
            var slotId        = Request.Form["slot"] as string;
            var name          = Request.Form["name"] as string;
            var uploadToNotes = string.IsNullOrEmpty(slotId);

            Employee employee;

            if (id == null)
            {
                employee = CreateEmployee(name);
            }
            else
            {
                employee = RavenSession.Load <Employee>(id);
                if (employee == null)
                {
                    return(HttpNotFound());
                }
            }

            using (var attachmentReader = new RequestAttachmentReader(Request))
            {
                var reading = attachmentReader.Select(x => ExecuteCommand(new SaveAttachment(employee, x.Key, x.Value)));
                if (!uploadToNotes)
                {
                    reading = reading.Take(1);
                }
                var attachments          = reading.ToArray();
                SlotWithAttachment added = null;

                if (string.IsNullOrEmpty(slotId))
                {
                    QuickAttachToNotes(employee, attachments);
                }
                else
                {
                    var slot = RavenSession.Load <AttachmentSlot>(slotId);
                    if (slot == null)
                    {
                        return(HttpNotFound());
                    }

                    added = employee.AddAttachment(attachments.First(), slot);
                }

                return(Json(new
                {
                    success = true,
                    entityId = employee.Id,
                    editUrl = Url.Action("Edit", new { id = employee.Id }),
                    attachment = attachments.FirstOrDefault(),
                    attachments = attachments,
                    added = added
                }));
            }
        }
コード例 #21
0
        //
        // GET: /Administration/Delete/5

        public ActionResult Delete(int id)
        {
            AdminDeleteViewModel vm = new AdminDeleteViewModel();

            vm.Meeting = RavenSession.Load <Meeting>(id);

            return(View(vm));
        }
コード例 #22
0
            public ActionResult Edit(int id)
            {
                var sampleData = RavenSession.Load <SampleData>(id);

                return(View("Index", new List <SampleData> {
                    sampleData
                }));
            }
コード例 #23
0
        public ActionResult Update(PostInput input)
        {
            if (!ModelState.IsValid)
            {
                return(View("Edit", input));
            }

            var post = RavenSession.Load <Post>(input.Id) ?? new Post {
                CreatedAt = DateTimeOffset.Now
            };

            input.MapPropertiesToInstance(post);

            // Be able to record the user making the actual post
            var user = RavenSession.GetCurrentUser();

            if (string.IsNullOrEmpty(post.AuthorId))
            {
                post.AuthorId = user.Id;
            }
            else
            {
                post.LastEditedByUserId = user.Id;
                post.LastEditedAt       = DateTimeOffset.Now;
            }

            if (post.PublishAt == DateTimeOffset.MinValue)
            {
                var postScheduleringStrategy = new PostSchedulingStrategy(RavenSession, DateTimeOffset.Now);
                post.PublishAt = postScheduleringStrategy.Schedule();
            }

            // Actually save the post now
            RavenSession.Store(post);

            if (input.IsNewPost())
            {
                // Create the post comments object and link between it and the post
                var comments = new PostComments
                {
                    Comments = new List <PostComments.Comment>(),
                    Spam     = new List <PostComments.Comment>(),
                    Post     = new PostComments.PostReference
                    {
                        Id        = post.Id,
                        PublishAt = post.PublishAt,
                    }
                };

                RavenSession.Store(comments);

                // Once the Comments have been saved, update and save the post
                post.CommentsId = comments.Id;
                RavenSession.Store(post);
            }

            return(RedirectToAction("Details", new { Id = post.MapTo <PostReference>().DomainId }));
        }
コード例 #24
0
        public ActionResult Edit(int id)
        {
            var post = RavenSession.Load <Post>(id);

            if (post == null)
            {
                return(HttpNotFound("Post does not exist."));
            }
            return(View(post.MapTo <PostInput>()));
        }
コード例 #25
0
ファイル: ExerciseController.cs プロジェクト: jfreal/movidhep
        public bool RefreshThumb(string exerciseId, string videoId)
        {
            var exr = RavenSession.Load <Exercise>("exercises/" + exerciseId);

            Thumbnailer.GenerateThumbs(exr.Id, exr.VideoId);

            RavenSession.SaveChanges();

            return(true);
        }
コード例 #26
0
        public ActionResult Edit(int id)
        {
            var section = RavenSession.Load <Section>(id);

            if (section == null)
            {
                return(HttpNotFound("Section does not exist."));
            }
            return(View(section));
        }
コード例 #27
0
        public virtual ActionResult Edit(string id)
        {
            var user = RavenSession.Load <User>("users/" + id);

            if (user == null)
            {
                return(HttpNotFound("User does not exist."));
            }
            return(View(user.MapTo <UserInput>()));
        }
コード例 #28
0
ファイル: ProgramController.cs プロジェクト: jfreal/movidhep
        public ActionResult Resend(int programId)
        {
            var program = RavenSession.Load <Program>("programs/" + programId);

            new ProgramEmailer(this).SendToPatient(program.Id, program.Email, program.ShortUrl);

            HighFive("Program resent to " + program.Email);

            return(RedirectToAction("List"));
        }
コード例 #29
0
        public virtual ActionResult Edit(string id)
        {
            var post = RavenSession.Load <Post>("posts/" + id);

            if (post == null)
            {
                return(HttpNotFound("Post does not exist."));
            }
            return(View(post.MapTo <PostInput>()));
        }
コード例 #30
0
        public ActionResult Edit(int id)
        {
            var user = RavenSession.Load <User>(id);

            if (user == null)
            {
                return(HttpNotFound("User does not exist."));
            }
            return(View(user.MapTo <UserInput>()));
        }