Example #1
0
        public async Task <ApplicantVM> Handle(CreateApplicantCommand request, CancellationToken cancellationToken)
        {
            var response = new ApplicantVM
            {
                Status  = false,
                Message = "error"
            };

            try
            {
                var applicantDto = request.Applicant;

                await  ValidateApplicatint(applicantDto);

                var entity = Applicant.Create(applicantDto.Name, applicantDto.FamilyName, applicantDto.Address, applicantDto.CountryOfOrigin, applicantDto.EMailAdress, applicantDto.Age, applicantDto.Hired);

                var data = await _dbContext.AddAsync(entity);

                await _dbContext.SaveChangesAsync();

                _logger.LogInformation("New Applicant created", data);

                response.Status  = true;
                response.Message = "Applicant created successfully.";
                response.Id      = entity.Id;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message.ToString(), request.Applicant);
                response.Message = ex.Message.ToString();
            }

            return(response);
        }
Example #2
0
        public static AjaxCallResult SignupParticipant(string name, int organizationId, string mail, string password, string phone,
                                                       string street1, string street2, string postalCode, string city, string countryCode, string dateOfBirth,
                                                       int geographyId, bool activist, PersonGender gender, int[] positionIdsVolunteer)
        {
            CommonV5.CulturePreInit(HttpContext.Current.Request);  // Set culture, for date parsing

            if (geographyId == 0)
            {
                geographyId = Geography.RootIdentity; // if geo was undetermined, set it to "Global"
            }

            Organization organization      = Organization.FromIdentity(organizationId);
            DateTime     parsedDateOfBirth = new DateTime(1800, 1, 1); // Default if unspecified

            if (dateOfBirth.Length > 0)
            {
                parsedDateOfBirth = DateTime.Parse(dateOfBirth);
            }

            Person newPerson = Person.Create(name, mail, password, phone, street1 + "\n" + street2.Trim(), postalCode,
                                             city, countryCode, parsedDateOfBirth, gender);


            if (organization.Parameters.ParticipationEntry == "ApplicationApproval")
            {
                Applicant newApplicant = Applicant.Create(newPerson, organization);
                SwarmopsLog.CreateEntry(newPerson, new ApplicantAddedLogEntry(newApplicant));
                OutboundComm.CreateParticipantNotification(newPerson, newPerson, organization,
                                                           NotificationResource.Applicant_Signup);
            }
            else
            {
                // "Application" or null, default

                Participation participation = newPerson.AddParticipation(organization, DateTime.UtcNow.AddYears(1));  // TODO: set duration from organization settings of Participantship
                SwarmopsLog.CreateEntry(newPerson, new PersonAddedLogEntry(participation, newPerson));
                OutboundComm.CreateParticipantNotification(newPerson, newPerson, organization,
                                                           NotificationResource.Participant_Signup);
            }

            // TODO: CREATE APPLICATION INSTEAD DEPENDING ON POLICY

            // TODO: SEND NOTIFICATIONS


            // Create notification


            // Add the bells and whistles

            if (activist)
            {
                newPerson.CreateActivist(false, false);
            }

            if (positionIdsVolunteer.Length > 0)
            {
                Volunteer volunteer = newPerson.CreateVolunteer();
                foreach (int positionId in positionIdsVolunteer)
                {
                    Position position = Position.FromIdentity(positionId);
                    volunteer.AddPosition(position);
                    SwarmopsLog.CreateEntry(newPerson, new VolunteerForPositionLogEntry(newPerson, position));
                }
            }

            newPerson.LastLogonOrganizationId = organizationId;

            // Create a welcome message to the Dashboard

            HttpContext.Current.Response.AppendCookie(new HttpCookie("DashboardMessage", CommonV5.JavascriptEscape(String.Format(Resources.Pages.Public.Signup_DashboardMessage, organization.Name))));

            // Set authentication cookie, which will log the new person in using the credentials just given

            FormsAuthentication.SetAuthCookie(Authority.FromLogin(newPerson, organization).ToEncryptedXml(), true);

            AjaxCallResult result = new AjaxCallResult {
                Success = true
            };

            return(result);
        }