public HttpResponseMessage GetRegistrations(int codeCampId) { try { var registrations = RegistrationDataAccess.GetItems(codeCampId); var response = new ServiceResponse <List <RegistrationInfo> > { Content = registrations.ToList() }; return(Request.CreateResponse(HttpStatusCode.OK, response.ObjectToJson())); } catch (Exception ex) { Exceptions.LogException(ex); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ERROR_MESSAGE)); } }
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)); } }