Beispiel #1
0
        /// <summary>
        /// Earn a badge by associating experiences and work
        /// </summary>
        /// <param name="id">Badge Id</param>
        /// <returns></returns>
        public ActionResult Earn(Guid id)
        {
            var badge = RepositoryFactory.BadgeRepository.GetNullableById(id);

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

            var model = new BadgeApplicationModel
                {
                    Badge = badge,
                    BadgeCriterias = badge.BadgeCriterias.ToList(),
                    Fulfillments = new List<BadgeFulfillmentViewModel>()
                };

            var existingBadgeApplication =
                RepositoryFactory.BadgeSubmissionRepository.Queryable.SingleOrDefault(
                    x => x.Badge.Id == badge.Id && x.Creator.Identifier == CurrentUser.Identity.Name);

            if (existingBadgeApplication != null)
            {
                if (existingBadgeApplication.Submitted || existingBadgeApplication.Approved)
                {
                    return RedirectToAction("Badge", "Public", new {id = existingBadgeApplication.Id});
                }

                Message = "Existing badge progress found-- you can continue associating work and experiences below";

                model.BadgeApplication = existingBadgeApplication;
                model.Reflection = existingBadgeApplication.Reflection;

                model.Fulfillments =
                    RepositoryFactory.BadgeFulfillmentRepository.Queryable.Where(
                        x => x.BadgeSubmission.Id == existingBadgeApplication.Id)
                                     .Select(
                                         x =>
                                         new BadgeFulfillmentViewModel
                                             {
                                                 CriteriaId = x.BadgeCriteria.Id,
                                                 Comment = x.Comment,
                                                 Details =
                                                     x.Experience == null
                                                         ? x.SupportingWork.Description
                                                         : x.Experience.Name,
                                                 WorkId = x.Experience == null ? x.SupportingWork.Id : x.Experience.Id,
                                                 WorkType = x.Experience == null ? "work" : "experience"
                                             })
                                     .ToList();
            }

            return View(model);
        }