public HttpResponseMessage GetRegistrationByUserId(int userId, int codeCampId)
        {
            try
            {
                var response = new ServiceResponse <RegistrationInfo>();
                RegistrationInfo registration = null;

                if (userId > 0)
                {
                    registration     = RegistrationDataAccess.GetItemByUserId(userId, codeCampId);
                    response.Content = registration;
                }

                if (registration == 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));
            }
        }
Esempio n. 2
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 UpdateRegistration(RegistrationInfo registration)
        {
            try
            {
                var originalRegistration = RegistrationDataAccess.GetItemByUserId(registration.UserId, registration.CodeCampId);
                var updatesToProcess     = false;

                // only update the fields that would be udpdated from the UI to keep the DB clean

                if (originalRegistration.TwitterHandle != registration.TwitterHandle)
                {
                    originalRegistration.TwitterHandle = registration.TwitterHandle;
                    updatesToProcess = true;
                }

                if (originalRegistration.ShirtSize != registration.ShirtSize)
                {
                    originalRegistration.ShirtSize = registration.ShirtSize;
                    updatesToProcess = true;
                }

                if (originalRegistration.HasDietaryRequirements != registration.HasDietaryRequirements)
                {
                    originalRegistration.HasDietaryRequirements = registration.HasDietaryRequirements;
                    updatesToProcess = true;
                }

                if (originalRegistration.Notes != registration.Notes)
                {
                    originalRegistration.Notes = registration.Notes;
                    updatesToProcess           = true;
                }

                if (originalRegistration.CustomProperties != null)
                {
                    // parse custom properties for updates
                    foreach (var property in originalRegistration.CustomPropertiesObj)
                    {
                        if (registration.CustomPropertiesObj.Any(p => p.Name == property.Name))
                        {
                            // see if the existing property needs to be updated
                            var prop = registration.CustomPropertiesObj.FirstOrDefault(p => p.Name == property.Name);
                            if (!string.Equals(prop.Value, property.Value))
                            {
                                property.Value   = prop.Value;
                                updatesToProcess = true;
                            }
                        }
                        else
                        {
                            // delete the property
                            originalRegistration.CustomPropertiesObj.Remove(property);
                            updatesToProcess = true;
                        }
                    }
                }

                if (registration.CustomPropertiesObj != null)
                {
                    // add any new properties
                    if (originalRegistration.CustomProperties == null)
                    {
                        foreach (var property in registration.CustomPropertiesObj)
                        {
                            originalRegistration.CustomPropertiesObj.Add(property);
                            updatesToProcess = true;
                        }
                    }
                    else
                    {
                        foreach (var property in registration.CustomPropertiesObj.Where(property => !originalRegistration.CustomPropertiesObj.Contains(property)))
                        {
                            originalRegistration.CustomPropertiesObj.Add(property);
                            updatesToProcess = true;
                        }
                    }
                }

                if (updatesToProcess)
                {
                    RegistrationDataAccess.UpdateItem(originalRegistration);
                }

                var response = new ServiceResponse <string> {
                    Content = SUCCESS_MESSAGE
                };

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