Example #1
0
        public async Task <IActionResult> Register(AccountRegisterViewModel model)
        {
            var returnModel = new AccountViewModel()
            {
                Register = model
            };

            if (ModelState.IsValid)
            {
                var participant = new LongTermParticipant
                {
                    YearOfBirth          = model.YearOfBirth,
                    UserName             = model.Email,
                    FullName             = model.FullName,
                    Email                = model.Email,
                    IsAllowingPromotions = model.IsAllowingPromotions,
                    PhoneNumber          = model.PhoneNumber,
                };
                var addResult = await Identities.AddNewParticipant(participant, model.Password);

                if (addResult.IsSuccess)
                {
                    await Communication.SendWelcomeMessageAsync(participant);

                    var signInResult = await Identities.LoginAsync(model.Email, model.Password, true);

                    if (signInResult.IsSuccess)
                    {
                        var cookieConsent = HttpContext.Features.Get <ITrackingConsentFeature>();
                        cookieConsent.GrantConsent();
                        return(RedirectToAction("Index", "Personal", new { area = "Participant" }));
                    }
                    else
                    {
                        SetUserError("כשלון בהתחברות לאחר רישום", signInResult.Details);
                        return(View("LoginOrRegister", returnModel));
                    }
                }
                else
                {
                    SetUserError("תקלה ביצירת משתתף", addResult.Errors.FirstOrDefault());
                    return(View("LoginOrRegister", returnModel));
                }
            }
            else
            {
                var invalidProperty = ModelState.First(x => x.Value.ValidationState == ModelValidationState.Invalid);
                SetUserError("תקלה במידע שהתקבל", invalidProperty.Value.Errors.FirstOrDefault()?.ErrorMessage ?? "אנא נסו שוב");
                return(View("LoginOrRegister", returnModel));
            }
        }
        public async Task <Answer> CreateParticipant(ParticipantCreateUpdateViewModel viewmodel)
        {
            var answer = ValidateParticipantFields(viewmodel);

            if (answer.AnswerType != AnswerType.Success)
            {
                return(answer);
            }

            IParticipant         model;
            ConventionEngagement engagement = new ConventionEngagement
            {
                ConventionId        = Actor.ManagedConvention.ConventionId,
                ConventionStartDate = Actor.ManagedConvention.Days
                                      .Min(x => x.Date)
                                      .ToString("yyyy-MM-dd", CultureInfo.InvariantCulture),
                Payment = new PaymentInvoice()
            };

            if (viewmodel.Email.IsEmptyString())
            {
                model = new ShortTermParticipant
                {
                    CreatedById = Actor.Me.Id
                };
            }
            else
            {
                model = new LongTermParticipant
                {
                    UserName             = viewmodel.Email,
                    Email                = viewmodel.Email,
                    IsAllowingPromotions = viewmodel.IsAllowingPromotions,
                };
                engagement.IsLongTerm = true;
            }

            model.FullName    = viewmodel.FullName;
            model.PhoneNumber = viewmodel.PhoneNumber ?? string.Empty;
            model.YearOfBirth = viewmodel.YearOfBirth;

            var result = await Identities.AddNewParticipant(model);

            engagement.ParticipantId = model.Id;
            if (result.IsSuccess)
            {
                Session.Store(engagement);
                Session.SaveChanges();
            }

            if (result.IsSuccess && result.IsLongTerm)
            {
                await Hub.SendCreationPasswordAsync(model as LongTermParticipant, result.Token);
            }

            if (result.IsSuccess == false)
            {
                return(Answer.Error(result.Errors?.AsJson()));
            }

            return(Answer.Success);
        }