Example #1
0
        private void SetEntryOptions(GiveawayParticipationViewModel vm, GiveawayParticipant participant)
        {
            Dictionary <GiveawayEntryType, int> groupedEntries = participant.Entries.GroupBy(x => x.Type).Select(x => new { EntryType = x.Key, EntryCount = x.Sum(y => y.Points) }).ToDictionary(x => x.EntryType, y => y.EntryCount);

            List <GiveawayEntryType> entryOptionsList = Enum.GetValues(typeof(GiveawayEntryType)).Cast <GiveawayEntryType>().ToList();

            foreach (GiveawayEntryType entryType in entryOptionsList)
            {
                KeyValuePair <GiveawayEntryType, int> entrySum = groupedEntries.FirstOrDefault(x => x.Key == entryType);

                GiveawayEntryOptionViewModel existing = vm.EntryOptions.FirstOrDefault(x => x.Type == entryType);
                if (existing != null)
                {
                    existing.Type        = entryType;
                    existing.Points      = entrySum.Value;
                    existing.IsMandatory = IsOptionMandatory(participant, entrySum);
                }
                else
                {
                    vm.EntryOptions.Add(new GiveawayEntryOptionViewModel
                    {
                        Type        = entryType,
                        Name        = entryType.ToUiInfo().Description,
                        Points      = entrySum.Value,
                        IsMandatory = IsOptionMandatory(participant, entrySum)
                    });
                }
            }
        }
Example #2
0
        public IActionResult YouAreIn(Guid id)
        {
            string sessionEmail = GetSessionValue(SessionValues.Email);

            OperationResultVo result = giveawayAppService.GetGiveawayParticipantInfo(CurrentUserId, id, sessionEmail);

            if (result.Success)
            {
                OperationResultVo <GiveawayParticipationViewModel> castRestult = result as OperationResultVo <GiveawayParticipationViewModel>;

                if (string.IsNullOrWhiteSpace(sessionEmail) || castRestult.Value.Status == GiveawayStatus.Ended)
                {
                    return(RedirectToAction("details", "giveaway", new { area = "tools", id = id }));
                }

                string[] emailSplit = sessionEmail.Split("@");

                ViewData["mailProvider"] = emailSplit.Length > 1 ? String.Format("https://{0}", emailSplit[1]) : "#";

                GiveawayParticipationViewModel model = castRestult.Value;

                model.ShareUrl = string.Format("{0}{1}", ViewBag.BaseUrl, model.ShareUrl);

                SetEntryOptions(model, id);

                return(View("YouAreIn", model));
            }
            else
            {
                return(RedirectToAction("details", "giveaway", new { area = "tools", id = id }));
            }
        }
Example #3
0
        private void SetEntryOptions(GiveawayParticipationViewModel model, Guid giveawayId)
        {
            foreach (GiveawayEntryOptionViewModel item in model.EntryOptions)
            {
                switch (item.Type)
                {
                case GiveawayEntryType.Daily:
                    item.Url = Url.Action("dailyentry", "giveaway", new { area = "tools", giveawayId = giveawayId, participantId = model.ParticipantId });
                    break;

                default:
                    break;
                }
            }
        }
Example #4
0
        public OperationResultVo GetGiveawayParticipantInfo(Guid currentUserId, Guid giveawayId, string email)
        {
            try
            {
                GiveawayBasicInfo existing = giveawayDomainService.GetGiveawayBasicInfoById(giveawayId);

                if (existing == null)
                {
                    return(new OperationResultVo(false, "Giveaway not found!"));
                }

                GiveawayParticipant participant = giveawayDomainService.GetParticipantByEmail(giveawayId, email);

                if (participant == null)
                {
                    return(new OperationResultVo(false, "No participant found for that email!"));
                }

                GiveawayParticipationViewModel vm = mapper.Map <GiveawayParticipationViewModel>(existing);

                SetViewModelState(currentUserId, vm);

                vm.EntryCount = participant.Entries.Sum(x => x.Points);

                vm.ShareUrl = participant.ShortUrl;

                vm.EmailConfirmed = participant.Entries.Any(x => x.Type == GiveawayEntryType.EmailConfirmed);

                SetImagesToShow(vm, false);

                SetEntryOptions(vm, participant);

                vm.ParticipantId = participant.Id;

                return(new OperationResultVo <GiveawayParticipationViewModel>(vm));
            }
            catch (Exception ex)
            {
                return(new OperationResultVo(ex.Message));
            }
        }