private ActionResult Confirm(ConfirmOfflineDepositRequest depositConfirm, HttpPostedFileBase idFrontImage, HttpPostedFileBase idBackImage, HttpPostedFileBase receiptImage) { if (ModelState.IsValid == false) { return(this.Failed()); } depositConfirm.CurrentUser = CurrentUser.UserName; depositConfirm.IdFrontImageFile = idFrontImage.GetBytes(); depositConfirm.IdBackImageFile = idBackImage.GetBytes(); depositConfirm.ReceiptImageFile = receiptImage.GetBytes(); var response = GetAdminApiProxy(Request).ConfirmOfflineDeposit(depositConfirm); return(response.Success ? this.Success( new { Message = "app:payment.deposit.successfullyConfirmed", idFrontImage = response.IdFrontImageId, idBackImage = response.IdBackImageId, receiptImage = response.ReceiptImageId, response.PlayerId }) : this.Failed(response.Errors)); }
public void EditUserProfileImages(User user, bool removeAvatar, bool removePhoto, HttpPostedFileBase avatarFile, HttpPostedFileBase photoFile) { var profile = _profileRepository.GetProfile(user.UserID); if (removeAvatar) { _userAvatarRepository.DeleteAvatarsByUserID(user.UserID); profile.AvatarID = null; } if (removePhoto) { _userImageRepository.DeleteImagesByUserID(user.UserID); profile.ImageID = null; } _profileRepository.Update(profile); if (avatarFile != null && avatarFile.ContentLength > 0) { _userAvatarRepository.DeleteAvatarsByUserID(user.UserID); var bytes = _imageService.ConstrainResize(avatarFile.GetBytes(), _settingsManager.Current.UserAvatarMaxWidth, _settingsManager.Current.UserAvatarMaxHeight, 70); var avatarID = _userAvatarRepository.SaveNewAvatar(user.UserID, bytes, DateTime.UtcNow); profile.AvatarID = avatarID; _profileRepository.Update(profile); } if (photoFile != null && photoFile.ContentLength > 0) { _userImageRepository.DeleteImagesByUserID(user.UserID); var bytes = _imageService.ConstrainResize(photoFile.GetBytes(), _settingsManager.Current.UserImageMaxWidth, _settingsManager.Current.UserImageMaxHeight, 70); var imageID = _userImageRepository.SaveNewImage(user.UserID, 0, _settingsManager.Current.IsNewUserImageApproved, bytes, DateTime.UtcNow); profile.ImageID = imageID; _profileRepository.Update(profile); } }
public virtual JsonResult Upload(long id, ApplicationFileType type, HttpPostedFileBase file) { var bytes = file.GetBytes(); var fileId = _files.Add(id, type, file.FileName, bytes); AddFileUploadEvent(id, TypesMapping[type], file.FileName, bytes); return(Json(new { id = fileId })); }
public static void ReadFile(this HttpPostedFileBase file, Action <byte[]> setData, Action <string> setName) { if (file != null) { setData(file.GetBytes()); setName(file.FileName); } else { setData(null); setName(null); } }
public bool UploadResume(string username, string title, string description, HttpPostedFileBase content) { var docType = Helpers.GetWebUploadType(content.ContentType); var list = uow.ValueRepository.GetStopwords(); var stopwords = fileFactory.GetStopwordsFile(DocumentType.Set, list); IResumeFile file; //get bytes int contentLength = content.ContentLength; byte[] bytes = content.GetBytes(); switch (docType) { case DocumentType.Word: { string tmpPath = tempFileService.CreateTempFile(bytes, content.FileName, contentLength); file = fileFactory.GetResumeFile(DocumentType.Word, stopwords, tmpPath); tempFileService.DeleteTempFile(tmpPath); break; } default: { //process bytes file = fileFactory.GetResumeFile(DocumentType.Bytes, stopwords, bytes); break; } } if (bytes == null) { throw new NullReferenceException("Could not retrieve bytes form upload."); } //build entity graph List <Keyword> words = new List <Keyword>(); foreach (var w in file) { words.Add(new Keyword() { Word = w.ToString() }); } var resume = new Resume(title, description, words, bytes, content.ContentType); resume.User = uow.UserRepository.GetUserByUsername(username); uow.ResumeRepository.InsertResume(resume); return(uow.Save()); }
private byte[] GetAvatar(HttpPostedFileBase avatar) { if (avatar != null) { byte[] imageData = avatar.GetBytes(); if (imageData.Length > RegisterUserModel.maxAvatarSize) { return(null); } return(imageData); } else { return(GetDefaultAvatar()); } }
public string CreateTempFile(HttpPostedFileBase file) { var name = Guid.NewGuid().ToString() + "_" + file.FileName; var path = HostingEnvironment.MapPath(WebConfigurationManager.AppSettings["TempPath"]) + "\\" + name; using (var strm = File.OpenWrite(path)) { var length = file.ContentLength; var bytes = file.GetBytes(); if (bytes == null) { throw new NullReferenceException("Could not retrieve bytes from upload"); } strm.Write(bytes, 0, length); strm.Close(); } return(path); }
private ActionResult SaveWithFiles(EditBankAccountRequest bankAccountData, HttpPostedFileBase idFrontImage, HttpPostedFileBase idBackImage, HttpPostedFileBase atmCardImage) { if (ModelState.IsValid == false) { return(this.Failed()); } bankAccountData.IdFrontImageFile = idFrontImage.GetBytes(); bankAccountData.IdBackImageFile = idBackImage.GetBytes(); bankAccountData.AtmCardImageFile = atmCardImage.GetBytes(); var response = GetAdminApiProxy(Request).EditBankAccount(bankAccountData); var bankAccount = bankAccountData; return(response.Success? this.Success(new { Message = "updated", bankAccount.IdFrontImage, bankAccount.IdBackImage, bankAccount.AtmCardImage, bankAccountData.Id }) : this.Failed(response.Errors)); }
public void EditUser(User targetUser, UserEdit userEdit, bool removeAvatar, bool removePhoto, HttpPostedFileBase avatarFile, HttpPostedFileBase photoFile, string ip, User user) { if (!String.IsNullOrWhiteSpace(userEdit.NewEmail)) { ChangeEmail(targetUser, userEdit.NewEmail, user, ip, userEdit.IsApproved); } if (!String.IsNullOrWhiteSpace(userEdit.NewPassword)) { SetPassword(targetUser, userEdit.NewPassword, ip, user); } if (targetUser.IsApproved != userEdit.IsApproved) { UpdateIsApproved(targetUser, userEdit.IsApproved, user, ip); } var profile = _profileRepository.GetProfile(targetUser.UserID); profile.IsSubscribed = userEdit.IsSubscribed; profile.ShowDetails = userEdit.ShowDetails; profile.IsPlainText = userEdit.IsPlainText; profile.HideVanity = userEdit.HideVanity; profile.TimeZone = userEdit.TimeZone; profile.IsDaylightSaving = userEdit.IsDaylightSaving; profile.Signature = _textParsingService.ForumCodeToHtml(userEdit.Signature); profile.Location = userEdit.Location; profile.Dob = userEdit.Dob; profile.Web = userEdit.Web; profile.Aim = userEdit.Aim; profile.Icq = userEdit.Icq; profile.YahooMessenger = userEdit.YahooMessenger; profile.Facebook = userEdit.Facebook; profile.Twitter = userEdit.Twitter; if (removeAvatar) { profile.AvatarID = null; } if (removePhoto) { profile.ImageID = null; } _profileRepository.Update(profile); var newRoles = userEdit.Roles ?? new string[0]; _roleRepository.ReplaceUserRoles(targetUser.UserID, newRoles); foreach (var role in targetUser.Roles) { if (!newRoles.Contains(role)) { _securityLogService.CreateLogEntry(user, targetUser, ip, role, SecurityLogType.UserRemovedFromRole); } } foreach (var role in newRoles) { if (!targetUser.Roles.Contains(role)) { _securityLogService.CreateLogEntry(user, targetUser, ip, role, SecurityLogType.UserAddedToRole); } } if (avatarFile != null && avatarFile.ContentLength > 0) { var avatarID = _userAvatarRepository.SaveNewAvatar(targetUser.UserID, avatarFile.GetBytes(), DateTime.UtcNow); profile.AvatarID = avatarID; _profileRepository.Update(profile); } if (photoFile != null && photoFile.ContentLength > 0) { var imageID = _userImageRepository.SaveNewImage(targetUser.UserID, 0, true, photoFile.GetBytes(), DateTime.UtcNow); profile.ImageID = imageID; _profileRepository.Update(profile); } }