public override void Read(BinaryReader reader) { this.user_id = reader.ReadInt32(); this.date = reader.ReadInt32(); this.photo = Tl.Parse <UserProfilePhoto>(reader); this.previous = reader.ReadUInt32() == 0x997275b5; }
public UpdateUserPhotoConstructor(int user_id, int date, UserProfilePhoto photo, bool previous) { this.user_id = user_id; this.date = date; this.photo = photo; this.previous = previous; }
public async Task <ActionResult> RemoveProfilePicture() { var UserId = User.Identity.GetUserId(); var loggedUserByUserId = _applicationDbContext.Users.SingleOrDefault(i => i.Id == UserId); if (loggedUserByUserId.Career == "General") { var user = await UserManager.FindByIdAsync(User.Identity.GetUserId()); if (user != null) { UserProfilePhoto userP = _applicationDbContext.UserProfilePhotos.SingleOrDefault(Id => Id.UserId == user.Id); // int Id = Convert.ToInt32(userP.UserProfilePhotoId); _applicationDbContext.UserProfilePhotos.Remove(userP); await _applicationDbContext.SaveChangesAsync(); } else { return(RedirectToAction("Index", new { Message = ManageMessageId.Error })); } return(RedirectToAction("Index", new { Message = ManageMessageId.RemoveProfileImage })); } else { AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); return(RedirectToAction("Login", "Account")); } }
internal async Task <bool> SetUserProfileImageAsync(int userProfileId, MediaFile file) { bool isUploaded = false; // Update image on displayed form immediately. MyProfileImage = ImageSource.FromStream(() => { var stream = file.GetStream(); file.Dispose(); return(stream); }); var fileInfo = new FileInfo(file.Path); if (IsConnected && file != null) { // Save file to API/Azure. var stream = file.GetStream(); UserProfilePhoto userProfilePhoto = new UserProfilePhoto() { UserProfileId = userProfileId, FileName = fileInfo.Name, Data = stream.ToArray() }; isUploaded = await DataLoader.SaveUserProfileImageAsync(userProfilePhoto); if (isUploaded) { // Get the thumbnail that was just created by the server API. await RefreshUserProfileImageAsync(userProfileId); } } return(isUploaded); }
public async Task <bool> SaveUserProfileImageAsync(UserProfilePhoto userProfilePhoto) { if (userProfilePhoto == null || userProfilePhoto.UserProfileId <= 0) { return(false); } bool retVal = false; MultipartFormDataContent content = new MultipartFormDataContent(); ByteArrayContent baContent = new ByteArrayContent(userProfilePhoto.Data); content.Add(baContent, "File", userProfilePhoto.FileName); StringContent userProfileIdContent = new StringContent(userProfilePhoto.UserProfileId.ToString()); content.Add(userProfileIdContent, "userProfileId"); // Upload MultipartFormDataContent content using (var response = await HttpClient.PostAsync($"CM/UserProfileImage", content)) { if (response.IsSuccessStatusCode) { retVal = true; } } return(retVal); }
public GalleryUserProfilePhotoItem(IProtoService protoService, Telegram.Td.Api.User user, UserProfilePhoto photo, string caption) : base(protoService) { _user = user; _photo = photo; _caption = caption; }
public void SetPhoto(UserProfilePhoto photo) { switch (user.Constructor) { case Constructor.userEmpty: return; case Constructor.userSelf: ((UserSelfConstructor)user).photo = photo; break; case Constructor.userContact: ((UserContactConstructor)user).photo = photo; break; case Constructor.userRequest: ((UserRequestConstructor)user).photo = photo; break; case Constructor.userForeign: ((UserForeignConstructor)user).photo = photo; break; case Constructor.userDeleted: return; default: return; } OnPropertyChanged("AvatarPath"); }
public override void Read(BinaryReader reader) { this.id = reader.ReadInt32(); this.first_name = Serializers.String.read(reader); this.last_name = Serializers.String.read(reader); this.access_hash = reader.ReadInt64(); this.photo = Tl.Parse <UserProfilePhoto>(reader); this.status = Tl.Parse <UserStatus>(reader); }
public UserForeignConstructor(int id, string first_name, string last_name, long access_hash, UserProfilePhoto photo, UserStatus status) { this.id = id; this.first_name = first_name; this.last_name = last_name; this.access_hash = access_hash; this.photo = photo; this.status = status; }
private void SetUserPhoto(int userId, int date, UserProfilePhoto photo, bool previous) { if (users.ContainsKey(userId)) { Deployment.Current.Dispatcher.BeginInvoke(() => users[userId].SetPhoto(photo)); } else { logger.warning("update photo for unknown user {0}", userId); } }
public UserSelfConstructor(int id, string first_name, string last_name, string phone, UserProfilePhoto photo, UserStatus status, bool inactive) { this.id = id; this.first_name = first_name; this.last_name = last_name; this.phone = phone; this.photo = photo; this.status = status; this.inactive = inactive; }
void LoadIfl(UserProfilePhoto photo) { if (photo is UserProfilePhotoConstructor) { var flbig = (FileLocationConstructor)((UserProfilePhotoConstructor)photo).photo_big; var flsmall = (FileLocationConstructor)((UserProfilePhotoConstructor)photo).photo_small; ifl_large = new InputFileLocationConstructor(flbig.volume_id, flbig.local_id, flbig.secret); ifl_small = new InputFileLocationConstructor(flsmall.volume_id, flsmall.local_id, flsmall.secret); } }
public static PhotoSize GetBig(this UserProfilePhoto photo) { var local = photo.Sizes.FirstOrDefault(x => string.Equals(x.Type, "i")); if (local != null) { return(local); } return(photo.Sizes.OrderByDescending(x => x.Width).FirstOrDefault()); PhotoSize full = null; int fullLevel = -1; foreach (var i in photo.Sizes) { var size = i.Type.Length > 0 ? i.Type[0] : 'z'; int newFullLevel = -1; switch (size) { case 's': newFullLevel = 4; break; // box 100x100 case 'm': newFullLevel = 3; break; // box 320x320 case 'x': newFullLevel = 1; break; // box 800x800 case 'y': newFullLevel = 0; break; // box 1280x1280 case 'w': newFullLevel = 2; break; // box 2560x2560 case 'a': newFullLevel = 8; break; // crop 160x160 case 'b': newFullLevel = 7; break; // crop 320x320 case 'c': newFullLevel = 6; break; // crop 640x640 case 'd': newFullLevel = 5; break; // crop 1280x1280 } if (newFullLevel < 0) { continue; } if (fullLevel < 0 || newFullLevel < fullLevel) { fullLevel = newFullLevel; full = i; } } return(full); }
public override void Read(BinaryReader reader) { // userContact#cab35e18 id:int first_name:string last_name:string username:string access_hash:long phone:string photo:UserProfilePhoto status:UserStatus = User; this.id = reader.ReadInt32(); this.first_name = Serializers.String.read(reader); this.last_name = Serializers.String.read(reader); this.Username = Serializers.String.read(reader); this.access_hash = reader.ReadInt64(); this.phone = Serializers.String.read(reader); this.photo = Tl.Parse <UserProfilePhoto>(reader); this.status = Tl.Parse <UserStatus>(reader); }
public static bool UpdateFile(this UserProfilePhoto photo, File file) { var any = false; foreach (var size in photo.Sizes) { if (size.Photo.Id == file.Id) { size.Photo = file; any = true; } } return(any); }
public async Task <UserProfilePhoto> GetUserProfileThumbnailAsync(int userProfileId) { UserProfilePhoto retVal = null; try { retVal = await GetWebAPIDataService(Consts.AUTHORIZED).GetUserProfileThumbnailAsync(userProfileId); } catch (Exception ex) { Crashes.TrackError(ex); } return(retVal); }
public async Task <bool> SaveUserProfileImageAsync(UserProfilePhoto userProfilePhoto) { bool retVal = false; try { retVal = await GetWebAPIDataService(Consts.AUTHORIZED).SaveUserProfileImageAsync(userProfilePhoto); } catch (Exception ex) { Crashes.TrackError(ex); } return(retVal); }
/// <summary> /// This method is used to call service method GetEmployeeImage /// to receive the image of an employee /// </summary> /// <param name="id">EmployeeId</param> /// <returns>Employee Image</returns> public IUserProfilePhoto GetEmployeeImage(string email) { if (string.IsNullOrWhiteSpace(email)) { throw new KeyNotFoundException("Email should not be empty."); } var filter = Builders <User> .Filter.Eq("Email", email); var objUser = _context.Users.Find(filter).FirstOrDefaultAsync(); if (objUser == null) { throw new KeyNotFoundException("No image found for this User."); } // UserProfilePhoto localImage var tempUser = _context.Users.AsQueryable().ToList().FirstOrDefault(x => x.Email == email); if (tempUser.Picture != null) { if (tempUser.Picture.Length > 0) { byte[] Photobytes = tempUser.Picture.Select(s => Convert.ToByte(s, 16)).ToArray(); var employeeImage = new UserProfilePhoto() { //ImageID = localImage.ImageID, //Image1 = localImage.Image1, //FileName = localImage.FileName, //ContentType = localImage.ContentType, //CreatedOn = localImage.CreatedOn, ConvertedImage = Convert.ToBase64String(ImageCrop(Photobytes, 174, 184, CommonEnums.AnchorPosition.Center).ToArray()) }; return(employeeImage); } else { return(new Abstraction.UserProfile.UserProfilePhoto()); } } return(new Abstraction.UserProfile.UserProfilePhoto()); }
public async Task <UserProfilePhoto> GetUserProfileThumbnailAsync(int userProfileId) { UserProfilePhoto retVal = new UserProfilePhoto() { UserProfileId = userProfileId }; using (HttpResponseMessage response = await HttpClient.GetAsync($"CM/UserProfileThumbnail/{userProfileId}", HttpCompletionOption.ResponseHeadersRead)) { if (response.IsSuccessStatusCode) { retVal.Data = await response.Content.ReadAsByteArrayAsync(); string contentDispositionString = response.Content.Headers.GetValues("Content-Disposition").FirstOrDefault(); ContentDisposition contentDisposition = new ContentDisposition(contentDispositionString); string filename = contentDisposition.FileName; retVal.FileName = filename; } } return(retVal); }
/// <summary> /// This method allows user to upload employee's image /// </summary> /// <param name="image">IImage object</param> /// <param name="id">EmployeeId</param> /// <returns>Updated Image</returns> public IUserProfilePhoto UpdateEmployeeImage(UserProfilePhoto image, string eMail) { if (image == null) { throw new ArgumentNullException(nameof(image), "Image object should not be null."); } if (string.IsNullOrWhiteSpace(eMail)) { throw new KeyNotFoundException("Email should not be empty."); } var tempUser = _context.Users.AsQueryable().ToList().FirstOrDefault(x => x.Email == eMail); if (tempUser != null) { var filter = Builders <User> .Filter.Eq("Email", eMail); var update = Builders <User> .Update.Set("Picture", Convert.FromBase64String(image.ConvertedImage)); _context.Users.UpdateOneAsync(filter, update); } return(image); }
public override void Read(BinaryReader reader) { //userSelf#7007b451 id:int first_name:string last_name:string username:string phone:string photo:UserProfilePhoto status:UserStatus inactive:Bool = User; this.id = reader.ReadInt32(); this.first_name = Serializers.String.read(reader); this.last_name = Serializers.String.read(reader); var userName = Serializers.String.read(reader); this.phone = Serializers.String.read(reader); //while (true) //{ // var bla = reader.ReadUInt32(); // var hex = new Combinator(bla).ToHex; // var type = new Combinator(bla).ToType; // if (type != null) type.ToString(); //} this.photo = Tl.Parse <UserProfilePhoto>(reader); this.status = Tl.Parse <UserStatus>(reader); this.inactive = reader.ReadUInt32() == 0x997275b5; }
/// <summary> /// /// </summary> /// <param name="image"></param> /// <param name="eMail"></param> /// <returns></returns> public IUserProfilePhoto UpdateEmployeeImage(UserProfilePhoto image, string eMail) { return(_repository.UpdateEmployeeImage(image, eMail)); }
public Task <bool> SaveUserProfileImageAsync(UserProfilePhoto userProfilePhoto) { return(Task.FromResult(true)); }
private void SetUserPhoto(int userId, int date, UserProfilePhoto photo, bool previous) { if(users.ContainsKey(userId)) { Deployment.Current.Dispatcher.BeginInvoke(() => users[userId].SetPhoto(photo)); } else { logger.warning("update photo for unknown user {0}", userId); } }
public async Task <ActionResult> ChangeProfilePicture(HttpPostedFileBase file) { UserProfilePhoto userP = null; string userId = User.Identity.GetUserId(); var allowedExtensions = new[] { ".Jpg", ".png", ".jpg", ".jpeg", ".JPG", ".GIF", ".Gif", ".gif" }; var ext = Path.GetExtension(file.FileName); var retrievedUserPhoto = _applicationDbContext.UserProfilePhotos.SingleOrDefault(u => u.UserId == userId); if (retrievedUserPhoto == null) { } else { string userImageToDelete = retrievedUserPhoto.ImageName; string path = Request.MapPath("~/ProfilePhoto/" + userImageToDelete); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } } if (file != null && allowedExtensions.Contains(ext)) { userP = new UserProfilePhoto(); string filename = null; //string filename = Guid.NewGuid() + Path.GetExtension(file.FileName); //string filename = Guid.NewGuid() + file.FileName; WebImage img = new WebImage(file.InputStream); if (img.Width > 120) { img.Resize(120, 44); } int length = file.FileName.IndexOf("."); if (length > 0) { filename = file.FileName.Substring(0, length); } string randFileName = Guid.NewGuid() + Path.GetExtension(filename); //string filename = file.FileName.Substring(file.FileName.IndexOf(".") + 1).Trim(); img.Save(Path.Combine(Server.MapPath("~/ProfilePhoto"), filename)); if (retrievedUserPhoto == null) { userP.UserId = User.Identity.GetUserId(); userP.ImageName = filename + Path.GetExtension(img.FileName); userP.DateCreated = DateTime.UtcNow; _applicationDbContext.UserProfilePhotos.Add(userP); await _applicationDbContext.SaveChangesAsync(); return(RedirectToAction("Index", new { Message = ManageMessageId.AddProfileImage })); } else { var userPictureToUpdate = _applicationDbContext.UserProfilePhotos .Where(i => i.UserId == userId) .Single(); if (TryUpdateModel(userPictureToUpdate, "", new string[] { "UserProfilePhotoId", "UserId", "ImageName", "DateCreated" })) { try { userPictureToUpdate.ImageName = filename + Path.GetExtension(img.FileName); _applicationDbContext.Entry(userPictureToUpdate).State = EntityState.Modified; await _applicationDbContext.SaveChangesAsync(); return(RedirectToAction("Index", new { Message = ManageMessageId.AddProfileImage })); } catch (Exception /* dex */) { //Log the error (uncomment dex variable name after DataException and add a line here to write a log. ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, do contact us."); } } } } ModelState.AddModelError("", "Failed upload valid photo"); return(View()); }
public async Task <ActionResult> ChangePicture(HttpPostedFileBase file) { UserProfilePhoto userP = null; string userId = User.Identity.GetUserId(); var allowedExtensions = new[] { ".Jpg", ".png", ".jpg", ".jpeg", ".JPG", ".GIF", ".Gif", ".gif" }; var ext = Path.GetExtension(file.FileName); var retrievedUserPhoto = _applicationDbContext.UserProfilePhotos.SingleOrDefault(u => u.UserId == userId); if (retrievedUserPhoto == null) { } else { string userImageToDelete = retrievedUserPhoto.ImageName; string path = Request.MapPath("~/ProfilePhoto/" + userImageToDelete); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } } if (file != null && allowedExtensions.Contains(ext)) { userP = new UserProfilePhoto(); string filename = null; //string filename = Guid.NewGuid() + Path.GetExtension(file.FileName); //string filename = Guid.NewGuid() + file.FileName; WebImage img = new WebImage(file.InputStream); if (img.Width > 700) { img.Resize(700, 500); } int length = file.FileName.IndexOf("."); if (length > 0) { filename = file.FileName.Substring(0, length); } string randFileName = Guid.NewGuid() + Path.GetExtension(filename); //string filename = file.FileName.Substring(file.FileName.IndexOf(".") + 1).Trim(); img.Save(Path.Combine(Server.MapPath("~/ProfilePhoto"), filename)); if (retrievedUserPhoto == null) { userP.UserId = User.Identity.GetUserId(); userP.ImageName = filename + Path.GetExtension(img.FileName); userP.DateCreated = DateTime.UtcNow; _applicationDbContext.UserProfilePhotos.Add(userP); await _applicationDbContext.SaveChangesAsync(); return(RedirectToAction("Dashboard", "Access")); } else { var userPictureToUpdate = _applicationDbContext.UserProfilePhotos .Where(i => i.UserId == userId) .Single(); if (TryUpdateModel(userPictureToUpdate, "", new string[] { "UserProfilePhotoId", "UserId", "ImageName", "DateCreated" })) { try { userPictureToUpdate.ImageName = filename + Path.GetExtension(img.FileName); _applicationDbContext.Entry(userPictureToUpdate).State = EntityState.Modified; await _applicationDbContext.SaveChangesAsync(); return(RedirectToAction("Dashboard", "Access")); } catch (Exception /* dex */) { ViewBag.Error = "Failed to upload.Please try again"; return(View()); } } } } ViewBag.Error = "Select a valid image file"; return(View()); }
public GalleryUserProfilePhoto(IProtoService protoService, User user, UserProfilePhoto photo) : base(protoService) { _user = user; _photo = photo; }
public IUserProfilePhoto UpdateEmployeeImage([FromBody] UserProfilePhoto image, string eMail) { return(_userService.UpdateEmployeeImage(image, eMail)); }
public GalleryUserProfilePhotoItem(IProtoService protoService, Telegram.Td.Api.User user, UserProfilePhoto photo) : base(protoService) { _user = user; _photo = photo; }