Exemplo n.º 1
0
        public ActionResult ViewPendingSubmission(int id, ViewPendingSubmissionViewModel model)
        {
            if(!model.Approved && String.IsNullOrWhiteSpace(model.Reason))
                ModelState.AddModelError(String.Empty, "A reason must be provided to deny this submission");

            if (ModelState.IsValid)
            {
                UnitOfWork work = new UnitOfWork();
                if (model.Approved)
                {
                    work.AchievementRepository.HandleContentSubmission(id, JPPConstants.HandleUserContent.Approve);
                    return RedirectToAction("PendingUserSubmissionsList");
                }
                else
                {
                    work.AchievementRepository.HandleContentSubmission(id, JPPConstants.HandleUserContent.Deny, model.Reason);
                    return RedirectToAction("PendingUserSubmissionsList");
                }
            }
            ViewPendingSubmissionViewModel refresh = ViewPendingSubmissionViewModel.Populate(id);
            refresh.Reason = model.Reason;
            refresh.Approved = model.Approved;
            return View(refresh);
        }
Exemplo n.º 2
0
        public static ViewPendingSubmissionViewModel Populate(int id, UnitOfWork work = null)
        {
            if (work == null)
                work = new UnitOfWork();

            var e = work.EntityContext.achievement_user_content_pending.Find(id);

            if (e == null)
                return null;

            ViewPendingSubmissionViewModel model = new ViewPendingSubmissionViewModel()
            {
                AchievementDescription = e.achievement_template.description,
                AchievementIcon = e.achievement_template.icon,
                AchievementRequirements = new List<string>(),
                AchievementTitle = e.achievement_template.title,
                SubmissionType = e.content_type,
                SubmissionImage = e.image,
                SubmissionText = e.text,
                SubmissionURL = e.url,
                Approved = true
            };

            var req = work.EntityContext.achievement_requirement.Where(r => r.achievement_id == e.achievement_id).ToList();
            foreach( var r in req)
            {
                model.AchievementRequirements.Add(r.description);
            }
            return model;
        }