Example #1
0
 public static string ChangeProfileImage(Image gotImg)
 {
     using (Bitmap roundedBmp = new Bitmap(GraphicsStudio.ClipToCircle(gotImg), new Size(200, 200)))
     {
         JObject profileImgIdJson = null;
         byte[]  imgByteArray     = Universal.ImageToByteArray(roundedBmp, gotImg.RawFormat);
         ServerHub.WorkingInstance.ServerHubProxy.Invoke <JObject>("ChangeProfileImage", Consumer.LoggedIn.Id, imgByteArray).ContinueWith(task =>
         {
             if (!task.IsFaulted)
             {
                 profileImgIdJson = task.Result;
             }
         }).Wait();
         if (profileImgIdJson == null)
         {
             return(null);
         }
         try
         {
             string oldProfileImgId = profileImgIdJson["old_image_id"].ToString();
             if (oldProfileImgId != null && oldProfileImgId.Length > 5)
             {
                 LocalDataFileAccess.EraseOldProfileImageFromLocalData(oldProfileImgId);
             }
             string newImgId = profileImgIdJson["new_image_id"].ToString();
             LocalDataFileAccess.SaveProfileImageToLocal(roundedBmp, newImgId);
             return(newImgId);
         }
         catch (Exception e)
         {
             Console.WriteLine("Error occured in ChangeProfileImage() => " + e.Message);
             return(null);
         }
     }
 }
Example #2
0
        public JObject ChangeProfileImage(long userId, byte[] imageArray)
        {
            Output.ShowLog("ChangeProfileImage() => " + userId);
            Image  img             = new Bitmap(GraphicsStudio.ClipToCircle(Universal.ByteArrayToImage(imageArray)), new Size(200, 200));
            string newProfileImgId = "DP_" + userId + "_" + Time.CurrentTime.TimeStampString;
            string oldProfileImgId = ConsumerRepository.Instance.ReassignConsumerProfileImgId(userId, newProfileImgId);

            if (oldProfileImgId != null && oldProfileImgId.Length >= 5)
            {
                ImageFileAccess.EraseProfileImage(oldProfileImgId);
            }
            JObject profileImgIdJson = new JObject();

            profileImgIdJson["old_image_id"] = null;
            profileImgIdJson["new_image_id"] = null;
            if (ImageFileAccess.SaveProfileImage(img, newProfileImgId))
            {
                profileImgIdJson["old_image_id"] = oldProfileImgId;
                profileImgIdJson["new_image_id"] = newProfileImgId;
                Output.ShowLog(profileImgIdJson);
            }
            return(profileImgIdJson);
        }