public override void ViewDidLoad() { base.ViewDidLoad(); storyboard = UIStoryboard.FromName("Main", null); UserInitials = new UILabel() { TextAlignment = UITextAlignment.Center, Frame = new CGRect(0, 0, UserPicture.Frame.Width, UserPicture.Frame.Height), TextColor = UIColor.White, Font = UIFont.FromDescriptor(UIFont.PreferredTitle1.FontDescriptor, 48f) }; UserPicture.AddSubview(UserInitials); LogOutButton.TouchUpInside += async(x, y) => { if (File.Exists(Constants.Images + Profile.Instance.UserId + ".jpg")) { File.Delete(Constants.Images + Profile.Instance.UserId + ".jpg"); } await RemoteService.LogOut(); ProfileImage = null; ((ProfileViewController)(ParentViewController.ParentViewController)).PresentContainerView(0); RemoteService.NeededProfilePageNum = 0; UIApplication.SharedApplication.UnregisterForRemoteNotifications(); }; ChoosePicture.UserInteractionEnabled = true; UILongPressGestureRecognizer longp = new UILongPressGestureRecognizer(LongPress); ChoosePicture.AddGestureRecognizer(longp); }
public async Task <IActionResult> Index(IEnumerable <IFormFile> pictures) { List <string> pictureList = new List <string>(); foreach (var picture in pictures) { var newPictureName = $"{Guid.NewGuid()}{Path.GetExtension(picture.FileName)}"; await _blobStorage.UploadAsync(picture.OpenReadStream(), newPictureName, EContainerName.pictures); pictureList.Add(newPictureName); } var isUser = await _noSqlStorage.Get(UserFakeDBModel.UserId, UserFakeDBModel.UserPartitonKey); if (isUser == null) { isUser = new UserPicture { RowKey = UserFakeDBModel.UserId, PartitionKey = UserFakeDBModel.UserPartitonKey, Paths = pictureList }; } else { pictureList.AddRange(isUser.Paths); isUser.Paths = pictureList; } await _noSqlStorage.Add(isUser); return(RedirectToAction("Index")); }
public async Task <IActionResult> Create([Bind("Id,UserId,ProfilePicture,IsDefault")] UserPicture userPicture, IFormFile ProfilePicture) { string sImagePath = GetImagePath(UserId); string sImageThumbnailPath = GetThumbnailImagePath(UserId); var path = Path.Combine(sImagePath, ProfilePicture.FileName); var thumbpath = Path.Combine(sImageThumbnailPath, ProfilePicture.FileName); using (var stream = new FileStream(path, FileMode.Create)) { await ProfilePicture.CopyToAsync(stream); } Crop(200, 200, ProfilePicture.OpenReadStream(), thumbpath); userPicture.UserId = UserId; userPicture.ProfilePicture = ProfilePicture.FileName; _context.Add(userPicture); if (ProfilePicture == null || ProfilePicture.Length == 0) { return(Content("file not selected")); } await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <ActionResult> Index(IEnumerable <IFormFile> contents) { var pictureNames = new List <string>(); foreach (var item in contents) { var fileName = $"{Guid.NewGuid().ToString()}{Path.GetExtension(item.FileName)}"; await _blobStorageRepository.UploadAsync(item.OpenReadStream(), fileName, ContainerType.picture); pictureNames.Add(fileName); } var user = await _tableStorageRepository.GetAsync(City, UserId); if (user != null) { var picture = JsonConvert.DeserializeObject <List <string> >(user.RawPaths); pictureNames.AddRange(picture); user.RawPaths = JsonConvert.SerializeObject(pictureNames); await _tableStorageRepository.AddAsync(user); } else { var newUser = new UserPicture { RowKey = UserId, PartitionKey = City, RawPaths = JsonConvert.SerializeObject(pictureNames) }; await _tableStorageRepository.AddAsync(newUser); } return(RedirectToAction("Index")); }
public IEntityCRUDResponse SetUserProfilePictureAsDefault(int FileID) { try { //get user picture to update UserPicture UP = _userProfilePictureRepository.Table.Where(x => x.Id == FileID).FirstOrDefault(); if (UP != null) { ResetAllUserPicturesAsNotDefault(); UP.IsCurrentProfilePicture = true; _userProfilePictureRepository.Update(UP); _entityCRUDResponse.Returned_ID = UP.Id; _entityCRUDResponse.Success = true; _entityCRUDResponse.Message = "User Profile Picture was Successfully Updated."; } } catch (Exception e) { _entityCRUDResponse.Returned_ID = 0; _entityCRUDResponse.Success = false; _entityCRUDResponse.Message = "User Profile Picture was not successfully Updated, - " + e.Message; } return(_entityCRUDResponse); }
private void ShowUserInfo_Activated(object sender, EventArgs e) { // 画面が他画面の裏に隠れると、アイコン画像が再描画されない問題の対応 if (UserPicture.Image != null) { UserPicture.Invalidate(false); } }
public ActionResult Create(CreateUserModel model) { if (_membershipService.GetUserByName(model.Username) != null) { ModelState.AddModelError("DisplayName", Resource.UserNameExists); } if (_membershipService.GetUserByEmail(model.Email) != null) { ModelState.AddModelError("Email", Resource.UserEmailExists); } IEnumerable <int> userRoles = StringHelper.Ensure(Request.Form["SelectedRoles"]) .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(id => Convert.ToInt32(id)); IEnumerable <int> branches = StringHelper.Ensure(Request.Form["SelectedBranches"]) .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(id => Convert.ToInt32(id)); if (!ModelState.IsValid) { model.UserRoles = userRoles.ToList(); model.Roles = _roleService.GetAllRoles(); var branches1 = _repoUnit.GetAllBranches().ToList(); model.UserBranches = _repoUnit.GetAllBranches().Where(m => branches.Contains(m.ID)).ToList(); branches1.Insert(0, new Branch { ID = 0, Code = "-- " + Resource.SelectBranch + " --" }); model.Branches = branches1; return(View(model)); } var user = new User { DisplayName = model.Username, Email = model.Email, Password = model.Password, Phone = model.Phone, MobilePhone = model.MobilePhone, BranchID = model.BranchID == 0 ? null : (int?)model.BranchID, Branches = new HashSet <Branch>(), }; user = _membershipService.CreateUser(user); string userPicture = UserPicture.Upload(user.ID, model.Picture); if (!string.IsNullOrEmpty(userPicture)) { _membershipService.UpdateUserPicture(user.ID, userPicture); } _roleService.AssignRoles(user, userRoles); //_roleService.AssignBranches(user, new List<int> {user.BranchID}); TempData["message"] = Resource.AddSuccessful; return(RedirectToAction("Index")); }
/// <summary> /// Maps the user picture to file API dto. /// </summary> /// <returns>The user picture to file API dto.</returns> /// <param name="userPicture">User picture.</param> public FileApiDto MapUserPictureToFileApiDto(UserPicture userPicture) { return(new FileApiDto() { FileId = userPicture.UserPictureId, FileToBase64 = userPicture.FileToBase64, UserId = userPicture.UserPictureId }); }
public void UserPictureShouldHaveUserId() { var userPicture = new UserPicture { UserId = null, PictureId = 1, }; Assert.Throws <InvalidOperationException>( () => this.dbContext.UserPictures.Add(userPicture)); }
public override void ViewDidLoad() { base.ViewDidLoad(); UserInitials = new UILabel() { TextAlignment = UITextAlignment.Center, Frame = new CGRect(0, 0, UserPicture.Frame.Width, UserPicture.Frame.Height), TextColor = UIColor.White, Font = UIFont.FromDescriptor(UIFont.PreferredTitle1.FontDescriptor, 48f) }; UserPicture.AddSubview(UserInitials); }
public string UploadFromAndroid(string fileName, String userEmail, String userName, String Templat) { try { System.Diagnostics.Debug.WriteLine("I was called ?? "); string contentType = "image/jpeg";; CookieContainer cookie = new CookieContainer(); NameValueCollection par = new NameValueCollection(); par["MAX_FILE_SIZE"] = "3145728"; par["refer"] = ""; par["brand"] = ""; par["key"] = "01567DQW77d6d472ef877a4bf1d5b3ff8caebaa1"; par["optimage"] = "1"; par["rembar"] = "1"; par["submit"] = "host it!"; List <String> l = new List <String>(); string resp; par["optsize"] = "resample"; resp = UploadFileEx(@"C:\Users\NhatVHN\Desktop\model.jpg", "http://www.imageshack.us/upload_api.php", "fileupload", contentType, par, cookie); NiceposeUser user; user = dbContext.NiceposeUsers.Where(u => u.email.Equals(userEmail)).FirstOrDefault(); if (user == null) { user = new NiceposeUser(); user.createDate = DateTime.Today; user.email = userEmail; user.name = userName; user.isActive = true; dbContext.NiceposeUsers.Add(user); dbContext.SaveChanges(); } if (resp != null && resp.Length > 5) { UserPicture ip = new UserPicture(); ip.isActive = true; ip.Point = 0; ip.TotalRated = 0; ip.templateLink = Templat; ip.userID = user.id; ip.uploadedDate = DateTime.Today; ip.url = resp; dbContext.UserPictures.Add(ip); dbContext.SaveChanges(); } return(resp); } catch (Exception ex) { return(ex.ToString()); } }
public async Task <IActionResult> WatermarkPictureList() { var files = new List <FileBlobDto>(); UserPicture pictures = await _tableStorageRepository.GetAsync(City, UserId); pictures.WatermarkPaths = JsonConvert.DeserializeObject <List <string> >(pictures.WatermarkRawPaths); pictures.WatermarkPaths.ForEach(x => { files.Add(new FileBlobDto { Name = x, Url = $"{_blobStorageRepository.BlobPath}/{ContainerType.watermarkpicture}/{x}" }); }); return(View(files)); }
protected string GetImageProfilePath(UserPicture userPicture, int gender) { if (!System.IO.File.Exists(string.Format(@"..\img\{0}\{1}", userPicture.UserId.ToString(), userPicture.ProfilePicture))) { if (gender == 1) { return(@"..\img\male.jpg"); } else { return(@"..\img\female.jpg"); } } return(string.Format(@"..\img\{0}\{1}", userPicture.UserId.ToString(), userPicture.ProfilePicture)); }
public async Task <IActionResult> ShowWatermark() { List <FileBlob> fileBlobs = new List <FileBlob>(); UserPicture userPicture = await _noSqlStorage.Get(UserId, City); userPicture.WatermarkPaths.ForEach(x => { fileBlobs.Add(new FileBlob { Name = x, Url = $"{_blobStorage.BlobUrl}/{EContainerName.watermarkpictures}/{x}" }); }); ViewBag.fileBlobs = fileBlobs; return(View()); }
private void LoadPictureButton_Click(object sender, EventArgs e) { OpenFileDialog loadPicture = new OpenFileDialog { Filter = "jpg(*.jpg)|*.jpg|png(*.png)|*.png|Все файлы(*.*)|*.*" }; if (loadPicture.ShowDialog() == DialogResult.OK) { ImagePath = loadPicture.FileName; UserPicture.Load(ImagePath); using (FileStream fileStream = new FileStream(ImagePath, FileMode.Open, FileAccess.Read)) { BinaryReader binaryReader = new BinaryReader(fileStream); Image = binaryReader.ReadBytes((int)fileStream.Length); } } }
public ActionResult EditProfile(AccountModel model) { var oldPassword = EncryptHelper.EncryptPassword(model.OldPassword); if (oldPassword != CurrentUser.Identity.Password) { ModelState.AddModelError("OldPassword", Resource.TheOldPasswordDoNotMatch); } if (ModelState.IsValid) { // Update user profile picture if (model.Picture != null && model.Picture.ContentLength > 0) { UserPicture.Delete(CurrentUser.Identity.ID, CurrentUser.Identity.Picture); string pictureFileName = UserPicture.Upload(CurrentUser.Identity.ID, model.Picture); CurrentUser.Identity.Picture = pictureFileName; } // Update user primitive info //CurrentUser.Identity.Password = model.Password; CurrentUser.Identity.DisplayName = model.Username; CurrentUser.Identity.Email = model.Email; CurrentUser.Identity.Phone = model.Phone; CurrentUser.Identity.MobilePhone = model.MobilePhone; if (!string.IsNullOrEmpty(model.Password)) { CurrentUser.Identity.Password = EncryptHelper.EncryptPassword(model.Password); } if (_membership.UpdateUser(CurrentUser.Identity)) { FormsAuthentication.SetAuthCookie(CurrentUser.Identity.Email, false); } _loginTracker.ReloadUser(CurrentUser.Identity.Email, CurrentUser.Identity); ViewBag.Success = true; ViewBag.Message = Resource.YourProfileHasBeenUpdated; return(EditProfile()); } return(View(model)); }
protected void UpdateUser_Click(object sender, EventArgs e) { string userId = User.Identity.GetUserId(); string fileUp = UserPicture.FileName; string ArtworkFolder = Server.MapPath("/UserPics"); if (UserPicture.HasFile) { try { UserPicture.SaveAs(ArtworkFolder + "/" + fileUp); } catch (Exception ex) { lblError.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message; } } string connStr = System.Configuration.ConfigurationManager.ConnectionStrings["defaultConnection"].ConnectionString; SqlConnection conn = new SqlConnection(connStr); SqlCommand update = new SqlCommand("UPDATE userAccount SET UserPicture=@UserPicture, ArtistIntro=@UserIntro " + "WHERE UserID=@userId", conn); update.Parameters.AddWithValue("@UserPicture", "UserPics/" + UserPicture.FileName); update.Parameters.AddWithValue("@UserIntro", ArtistIntro.Text); update.Parameters.AddWithValue("@userID", userId); try { conn.Open(); object returnObj = update.ExecuteNonQuery(); } catch (Exception ex) { lblError.Text = "Error: " + ex.Message; } conn.Close(); }
public ActionResult Edit(EditUserModel model) { User user = _membershipService.GetUserByName(model.Username); if (user != null && user.ID != model.ID) { ModelState.AddModelError("DisplayName", Resource.UserNameExists); } user = _membershipService.GetUserByEmail(model.Email); if (user != null && user.ID != model.ID) { ModelState.AddModelError("Email", Resource.UserEmailExists); } if (string.IsNullOrEmpty(model.Password) && model.Password != model.ConfirmPassword) { ModelState.AddModelError("User.Password", Resource.PasswordMismatch); } IEnumerable <int> userRoles = StringHelper.Ensure(Request.Form["SelectedRoles"]) .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(id => Convert.ToInt32(id)); //IEnumerable<int> branches = StringHelper.Ensure(Request.Form["SelectedBranches"]) // .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) // .Select(id => Convert.ToInt32(id)); if (!ModelState.IsValid) { //return Edit(model.ID); var brands = _repoUnit.GetAllBranches().ToList(); brands.Insert(0, new Branch { ID = 0, Code = "-- " + Resource.SelectBranch + " --" }); if (user.BranchID == null) { user.BranchID = 0; } var oldUser = _membershipService.GetUser(model.ID); model.UserRoles = _roleService.GetAllRoles().Where(m => userRoles.Contains(m.ID)); model.UserBranches = oldUser.Branches.ToList(); model.Roles = _roleService.GetAllRoles(); model.Branches = brands; model.BranchID = Convert.ToInt32(user.BranchID); return(View(model)); } user = _membershipService.GetUser(model.ID); if (user.BranchID != null && user.BranchID != model.BranchID) { _repoUnit.AddToUserBranchList(model.ID, Convert.ToInt32(user.BranchID)); } var oldBranches = user.Branches.Select(m => m.ID).ToList(); if (user.BranchID != null && user.BranchID > 0 && user.BranchID != model.BranchID) { oldBranches.Add((int)user.BranchID); oldBranches = oldBranches.Distinct().ToList(); _roleService.AssignBranches(user, oldBranches); } user.DisplayName = model.Username; user.Email = model.Email; user.Phone = model.Phone; user.MobilePhone = model.MobilePhone; if (!string.IsNullOrEmpty(model.Password)) { user.Password = EncryptHelper.EncryptPassword(model.Password); } user.BranchID = model.BranchID == 0 ? null : (int?)model.BranchID; //user.LastAccess = model.LastAccess; var success = _membershipService.UpdateUser(user); string userPicture = UserPicture.Upload(model.ID, model.Picture); if (!string.IsNullOrEmpty(userPicture)) { _membershipService.UpdateUserPicture(user.ID, userPicture); } _roleService.AssignRoles(user, userRoles); _loginTracker.ReloadUser(user.Email, user); if (success) { TempData["message"] = Resource.SaveSuccessful; return(RedirectToAction("Index")); } ViewBag.Success = true; ViewBag.Message = Resource.SaveFailed; return(RedirectToAction("Edit", new { Id = model.ID })); }