Inheritance: ISpeakerInfo
        public HttpResponseMessage CreateSpeaker(SpeakerInfo speaker)
        {
            try
            {
                var timeStamp = DateTime.Now;

                speaker.CreatedByDate = timeStamp;
                speaker.CreatedByUserId = UserInfo.UserID;
                speaker.LastUpdatedByDate = timeStamp;
                speaker.LastUpdatedByUserId = UserInfo.UserID;

                if (speaker.RegistrationId == 0)
                {
                    speaker.RegistrationId = null;
                }

                SpeakerDataAccess.CreateItem(speaker);

                var speakers = SpeakerDataAccess.GetItems(speaker.CodeCampId);

                var savedSpeaker = speakers.OrderByDescending(s => s.CreatedByDate).FirstOrDefault(s => s.Email == speaker.Email);

                var response = new ServiceResponse<SpeakerInfo> { Content = savedSpeaker };

                return Request.CreateResponse(HttpStatusCode.OK, response.ObjectToJson());
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
                return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ERROR_MESSAGE);
            }
        }
Example #2
0
 private void UpdateSpeakerWithSessions(ref SpeakerInfo item)
 {
     if (item != null)
     {
         item.Sessions = GetSessionsForSpeaker(item.CodeCampId, item.SpeakerId);
     }
 }
 public void DeleteItem(SpeakerInfo i)
 {
     using (IDataContext ctx = DataContext.Instance())
     {
         var rep = ctx.GetRepository <SpeakerInfo>();
         rep.Delete(i);
     }
 }
        public SpeakerInfo GetItem(int itemId, int codeCampId)
        {
            SpeakerInfo i = null;

            using (IDataContext ctx = DataContext.Instance())
            {
                var rep = ctx.GetRepository <SpeakerInfo>();
                i = rep.GetById(itemId, codeCampId);
            }
            return(i);
        }
        public SpeakerInfo GetItemByRegistrationId(int codeCampId, int registrationId)
        {
            SpeakerInfo i = null;

            using (IDataContext ctx = DataContext.Instance())
            {
                var rep = ctx.GetRepository <SpeakerInfo>();

                i = rep.Find("WHERE CodeCampId = @0 AND RegistrationId = @1", codeCampId, registrationId).FirstOrDefault();
            }

            return(i);
        }
 public SpeakerInfoLite(SpeakerInfo originalSpeaker)
 {
     if (originalSpeaker != null)
     {
         SpeakerId = originalSpeaker.SpeakerId;
         CodeCampId = originalSpeaker.CodeCampId;
         RegistrationId = originalSpeaker.RegistrationId;
         SpeakerName = originalSpeaker.SpeakerName;
         CompanyName = originalSpeaker.CompanyName;
         CompanyTitle = originalSpeaker.CompanyTitle;
         URL = originalSpeaker.URL;
         Email = originalSpeaker.Email;
         Bio = originalSpeaker.Bio;
         IconFile = originalSpeaker.IconFile;
         IsAuthor = originalSpeaker.IsAuthor;
     }
 }
 public SpeakerInfoLite(SpeakerInfo originalSpeaker)
 {
     if (originalSpeaker != null)
     {
         SpeakerId      = originalSpeaker.SpeakerId;
         CodeCampId     = originalSpeaker.CodeCampId;
         RegistrationId = originalSpeaker.RegistrationId;
         SpeakerName    = originalSpeaker.SpeakerName;
         CompanyName    = originalSpeaker.CompanyName;
         CompanyTitle   = originalSpeaker.CompanyTitle;
         URL            = originalSpeaker.URL;
         Email          = originalSpeaker.Email;
         Bio            = originalSpeaker.Bio;
         IconFile       = originalSpeaker.IconFile;
         IsAuthor       = originalSpeaker.IsAuthor;
     }
 }
        public HttpResponseMessage CreateSpeaker(SpeakerInfo speaker)
        {
            try
            {
                var portalId = PortalSettings.PortalId;

                var timeStamp = DateTime.Now;

                speaker.CreatedByDate = timeStamp;
                speaker.CreatedByUserId = UserInfo.UserID;
                speaker.LastUpdatedByDate = timeStamp;
                speaker.LastUpdatedByUserId = UserInfo.UserID;

                if (speaker.RegistrationId == 0)
                {
                    speaker.RegistrationId = null;
                }

                SpeakerDataAccess.CreateItem(speaker);

                if (!string.IsNullOrEmpty(speaker.AvatarDataURIData))
                {
                    // NOTE: This is super slow for some reason?
                    // var decodedAvatar = B64Decode(speaker.AvatarDataURIData);

                    var fileData = Convert.FromBase64String(speaker.AvatarDataURIData);

                    // get the folder from the API
                    var folderInfo = FolderManager.Instance.GetFolder(
                        portalId: portalId,
                        folderPath: string.Format(Globals.SPEAKER_AVATAR_FOLDER_PATH_FORMAT, speaker.CodeCampId));

                    if (folderInfo == null)
                    {
                        // add the folder since it doesn't yet exist
                        folderInfo = FolderManager.Instance.AddFolder(
                            portalId: portalId,
                            folderPath: string.Format(Globals.SPEAKER_AVATAR_FOLDER_PATH_FORMAT, speaker.CodeCampId));
                    }

                    IFileInfo fileInfo = null;
                    using (var reader = new MemoryStream(fileData))
                    {
                        var filename = string.Format(Globals.SPEAKER_AVATAR_FILENAME_FORMAT, speaker.SpeakerId,
                            DateTime.Now.ToString(Globals.SPEAKER_AVATAR_FILENAME_STAMP_FORMAT),
                            Globals.SPEAKER_AVATAR_FILEEXTENSION);

                        fileInfo = FileManager.Instance.AddFile(folderInfo, filename, reader, true);
                        speaker.IconFile = string.Format(Globals.SPEAKER_ICON_FILE_PATH, portalId, fileInfo.RelativePath);
                    }
                    SpeakerDataAccess.UpdateItem(speaker);
                }

                var speakers = SpeakerDataAccess.GetItems(speaker.CodeCampId);

                var savedSpeaker = speakers.OrderByDescending(s => s.CreatedByDate).FirstOrDefault(s => s.Email == speaker.Email);

                var response = new ServiceResponse<SpeakerInfo> { Content = savedSpeaker };

                return Request.CreateResponse(HttpStatusCode.OK, response.ObjectToJson());
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
                return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ERROR_MESSAGE);
            }
        }
        public HttpResponseMessage UpdateSpeaker(SpeakerInfo speaker)
        {
            try
            {
                var portalId = PortalSettings.PortalId;

                var updatesToProcess = false;
                var originalSpeaker = SpeakerDataAccess.GetItem(speaker.SpeakerId, speaker.CodeCampId);

                if (!string.Equals(speaker.SpeakerName, originalSpeaker.SpeakerName))
                {
                    originalSpeaker.SpeakerName = speaker.SpeakerName;
                    updatesToProcess = true;
                }

                if (!string.Equals(speaker.URL, originalSpeaker.URL))
                {
                    originalSpeaker.URL = speaker.URL;
                    updatesToProcess = true;
                }

                if (!string.Equals(speaker.Email, originalSpeaker.Email))
                {
                    originalSpeaker.Email = speaker.Email;
                    updatesToProcess = true;
                }

                if (!string.Equals(speaker.CompanyName, originalSpeaker.CompanyName))
                {
                    originalSpeaker.CompanyName = speaker.CompanyName;
                    updatesToProcess = true;
                }

                if (!string.Equals(speaker.CompanyTitle, originalSpeaker.CompanyTitle))
                {
                    originalSpeaker.CompanyTitle = speaker.CompanyTitle;
                    updatesToProcess = true;
                }

                if (!string.Equals(speaker.Bio, originalSpeaker.Bio))
                {
                    originalSpeaker.Bio = speaker.Bio;
                    updatesToProcess = true;
                }

                if (speaker.IsAuthor != originalSpeaker.IsAuthor)
                {
                    originalSpeaker.IsAuthor = speaker.IsAuthor;
                    updatesToProcess = true;
                }

                if (!string.IsNullOrEmpty(speaker.AvatarDataURIData))
                {
                    var fileData = Convert.FromBase64String(speaker.AvatarDataURIData);

                    // get the folder from the API
                    var folderInfo = FolderManager.Instance.GetFolder(
                        portalId: portalId,
                        folderPath: string.Format(Globals.SPEAKER_AVATAR_FOLDER_PATH_FORMAT, speaker.CodeCampId));

                    if (folderInfo == null)
                    {
                        // add the folder since it doesn't yet exist
                        folderInfo = FolderManager.Instance.AddFolder(
                            portalId: portalId,
                            folderPath: string.Format(Globals.SPEAKER_AVATAR_FOLDER_PATH_FORMAT, speaker.CodeCampId));
                    }

                    IFileInfo fileInfo = null;
                    using (var reader = new MemoryStream(fileData))
                    {
                        var filename = string.Format(Globals.SPEAKER_AVATAR_FILENAME_FORMAT, speaker.SpeakerId,
                            DateTime.Now.ToString(Globals.SPEAKER_AVATAR_FILENAME_STAMP_FORMAT),
                            Globals.SPEAKER_AVATAR_FILEEXTENSION);

                        fileInfo = FileManager.Instance.AddFile(folderInfo, filename, reader, true);
                        speaker.IconFile = string.Format(Globals.SPEAKER_ICON_FILE_PATH, portalId, fileInfo.RelativePath);
                        originalSpeaker.IconFile = speaker.IconFile;
                    }

                    updatesToProcess = true;
                }

                if (speaker.RemoveAvatar)
                {
                    speaker.IconFile = string.Empty;
                    originalSpeaker.IconFile = speaker.IconFile;
                    updatesToProcess = true;
                }

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

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

                if (updatesToProcess)
                {
                    SpeakerDataAccess.UpdateItem(originalSpeaker);
                }

                var savedSpeaker = SpeakerDataAccess.GetItem(speaker.SpeakerId, speaker.CodeCampId);

                var response = new ServiceResponse<SpeakerInfo> { Content = savedSpeaker };

                return Request.CreateResponse(HttpStatusCode.OK, response.ObjectToJson());
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
                return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ERROR_MESSAGE);
            }
        }
Example #10
0
 public void UpdateItem(SpeakerInfo i)
 {
     repo.UpdateItem(i);
 }
Example #11
0
 public void DeleteItem(SpeakerInfo i)
 {
     repo.DeleteItem(i);
 }
Example #12
0
 public void CreateItem(SpeakerInfo i)
 {
     repo.CreateItem(i);
 }
        public HttpResponseMessage UpdateSpeaker(SpeakerInfo speaker)
        {
            try
            {
                var updatesToProcess = false;
                var originalSpeaker = SpeakerDataAccess.GetItem(speaker.SpeakerId, speaker.CodeCampId);

                if (!string.Equals(speaker.SpeakerName, originalSpeaker.SpeakerName))
                {
                    originalSpeaker.SpeakerName = speaker.SpeakerName;
                    updatesToProcess = true;
                }

                if (!string.Equals(speaker.URL, originalSpeaker.URL))
                {
                    originalSpeaker.URL = speaker.URL;
                    updatesToProcess = true;
                }

                if (!string.Equals(speaker.Email, originalSpeaker.Email))
                {
                    originalSpeaker.Email = speaker.Email;
                    updatesToProcess = true;
                }

                if (!string.Equals(speaker.CompanyName, originalSpeaker.CompanyName))
                {
                    originalSpeaker.CompanyName = speaker.CompanyName;
                    updatesToProcess = true;
                }

                if (!string.Equals(speaker.CompanyTitle, originalSpeaker.CompanyTitle))
                {
                    originalSpeaker.CompanyTitle = speaker.CompanyTitle;
                    updatesToProcess = true;
                }

                if (!string.Equals(speaker.Bio, originalSpeaker.Bio))
                {
                    originalSpeaker.Bio = speaker.Bio;
                    updatesToProcess = true;
                }

                if (speaker.IsAuthor != originalSpeaker.IsAuthor)
                {
                    originalSpeaker.IsAuthor = speaker.IsAuthor;
                    updatesToProcess = true;
                }

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

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

                if (updatesToProcess)
                {
                    SpeakerDataAccess.UpdateItem(originalSpeaker);
                }

                var savedSpeaker = SpeakerDataAccess.GetItem(speaker.SpeakerId, speaker.CodeCampId);

                var response = new ServiceResponse<SpeakerInfo> { Content = savedSpeaker };

                return Request.CreateResponse(HttpStatusCode.OK, response.ObjectToJson());
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
                return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ERROR_MESSAGE);
            }
        }
 public void UpdateItem(SpeakerInfo i)
 {
     repo.UpdateItem(i);
 }
 private void UpdateSpeakerWithSessions(ref SpeakerInfo item)
 {
     if (item != null)
     {
         item.Sessions = GetSessionsForSpeaker(item.CodeCampId, item.SpeakerId);
     }
 }
 public void DeleteItem(SpeakerInfo i)
 {
     repo.DeleteItem(i);
 }
 public void CreateItem(SpeakerInfo i)
 {
     repo.CreateItem(i);
 }