Exemple #1
0
        protected void ButtonUploadPictureProfile_ServerClick(object sender,
                                                              EventArgs e)
        {
            try
            {
                var postedFile    = Request.Files[ImageFileProfile.Name];
                var politicianKey = LabelPoliticianKey.Text;
                var uploadTime    = DateTime.UtcNow;

                if ((postedFile == null) || (postedFile.ContentLength == 0))
                {
                    return;
                }
                Size originalSize;
                ImageManager.UpdatePoliticianProfileImages(politicianKey,
                                                           postedFile.InputStream, uploadTime, out originalSize);
                CommonCacheInvalidation.ScheduleInvalidation("politicianimage",
                                                             politicianKey);

                // We only want to propagate the profile to the headshot if there
                // is no current Headshot -- we check Headshot100
                if (PoliticiansImagesBlobs.GetHeadshot100(politicianKey) == null)
                {
                    ImageManager.UpdateResizedPoliticianHeadshotImages(politicianKey,
                                                                       postedFile.InputStream, uploadTime, out originalSize);
                }

                var memoryStream = new MemoryStream();
                postedFile.InputStream.Position = 0;
                postedFile.InputStream.CopyTo(memoryStream);
                postedFile.InputStream.Position = 0;
                var imageBlob = memoryStream.ToArray();
                LogPoliticiansImagesOriginal.Insert(politicianKey, imageBlob, uploadTime,
                                                    UserSecurityClass, UserName, 0);

                UpdateRowCountAfterChange();

                Msg.Text =
                    Ok("The profile image for ID " + politicianKey + " was uploaded.");
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
        }
Exemple #2
0
        protected void ButtonRevertToLog_ServerClick(object sender, EventArgs e)
        {
            try
            {
                var    politicianKey = LabelPoliticianKey.Text;
                string user;
                var    latestLogDate =
                    LogDataChange.GetSecondLatestProfileImageDate(politicianKey, out user);

                var logTime    = new DateTime(latestLogDate.Ticks);
                var loggedBlob = LatestLoggedImagePage.GetLoggedImageByDate(
                    politicianKey, logTime);
                if ((latestLogDate == DefaultDbDate) || (loggedBlob == null) ||
                    (loggedBlob.Length == 0))
                {
                    Msg.Text =
                        Fail("No log profile image for ID " + politicianKey + " was found.");
                }
                else
                {
                    var  now = DateTime.UtcNow;
                    Size originalSize;
                    ImageManager.UpdatePoliticianProfileImages(politicianKey,
                                                               new MemoryStream(loggedBlob), now, out originalSize);
                    CommonCacheInvalidation.ScheduleInvalidation("politicianimage",
                                                                 politicianKey);
                    LogPoliticiansImagesOriginal.Insert(politicianKey, loggedBlob, now,
                                                        UserSecurityClass, UserName, 0);
                    Msg.Text =
                        Ok("The profile image for ID " + politicianKey +
                           " was reverted to the most recent logged version.");
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
        }