示例#1
0
        private VolunteerInfo GenerateOrganizerVolunteerInfo(int codeCampId)
        {
            var registration = RegistrationDataAccess.GetItemByUserId(UserInfo.UserID, codeCampId);

            if (registration == null)
            {
                RegistrationDataAccess.CreateItem(new RegistrationInfo()
                {
                    CodeCampId       = codeCampId,
                    IsRegistered     = true,
                    Notes            = "Registered automatically by Volunteer view.",
                    RegistrationDate = DateTime.Now,
                    ShirtSize        = "XL",
                    UserId           = UserInfo.UserID
                });

                registration = RegistrationDataAccess.GetItemByUserId(UserInfo.UserID, codeCampId);
            }

            VolunteerDataAccess.CreateItem(new VolunteerInfo()
            {
                CodeCampId     = codeCampId,
                Notes          = "Automatically generated by the Volunteer view.",
                RegistrationId = registration.RegistrationId
            });

            return(VolunteerDataAccess.GetItemByRegistrationId(registration.RegistrationId, codeCampId));
        }
        public HttpResponseMessage CreateRegistration(RegistrationInfo registration)
        {
            try
            {
                var response = new ServiceResponse <RegistrationInfo>();

                if (registration.UserId <= 0)
                {
                    // user isn't logged in and therefore doesn't likely have a user account on the site
                    // we need to register them into DNN for them

                    var firstName = registration.CustomPropertiesObj.FirstOrDefault(p => p.Name == "FirstName").Value;
                    var lastName  = registration.CustomPropertiesObj.FirstOrDefault(p => p.Name == "LastName").Value;
                    var email     = registration.CustomPropertiesObj.FirstOrDefault(p => p.Name == "Email").Value;
                    var portalId  = int.Parse(registration.CustomPropertiesObj.FirstOrDefault(p => p.Name == "PortalId").Value);

                    var ctlUser = new DnnUserController();
                    var status  = ctlUser.CreateNewUser(firstName, lastName, email, portalId);

                    switch (status)
                    {
                    case UserCreateStatus.DuplicateEmail:
                        ServiceResponseHelper <RegistrationInfo> .AddUserCreateError("DuplicateEmail", ref response);

                        break;

                    case UserCreateStatus.DuplicateUserName:
                        ServiceResponseHelper <RegistrationInfo> .AddUserCreateError("DuplicateUserName", ref response);

                        break;

                    case UserCreateStatus.Success:
                        var user = UserController.GetUserByName(email);
                        registration.UserId = user.UserID;

                        UserController.UserLogin(portalId, user, PortalSettings.PortalName, string.Empty, false);
                        break;

                    case UserCreateStatus.UnexpectedError:
                        ServiceResponseHelper <RegistrationInfo> .AddUserCreateError("UnexpectedError", ref response);

                        break;

                    case UserCreateStatus.UsernameAlreadyExists:
                        ServiceResponseHelper <RegistrationInfo> .AddUserCreateError("UsernameAlreadyExists", ref response);

                        break;

                    case UserCreateStatus.UserAlreadyRegistered:
                        ServiceResponseHelper <RegistrationInfo> .AddUserCreateError("UserAlreadyRegistered", ref response);

                        break;

                    default:
                        ServiceResponseHelper <RegistrationInfo> .AddUnknownError(ref response);

                        break;
                    }
                }

                if (response.Errors.Count == 0)
                {
                    registration.RegistrationDate = DateTime.Now;

                    RegistrationDataAccess.CreateItem(registration);

                    var registrations     = RegistrationDataAccess.GetItems(registration.CodeCampId).OrderByDescending(r => r.RegistrationId);
                    var savedRegistration = registrations.FirstOrDefault(r => r.UserId == registration.UserId);

                    response.Content = savedRegistration;

                    if (savedRegistration == null)
                    {
                        ServiceResponseHelper <RegistrationInfo> .AddNoneFoundError("registration", ref response);
                    }
                }

                return(Request.CreateResponse(HttpStatusCode.OK, response.ObjectToJson()));
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ERROR_MESSAGE));
            }
        }