//post a userupload object public async Task <bool> PostUserUpload(UserUpload userupload) { RestClient <UserUpload> restClient = new RestClient <UserUpload>(); var response = await restClient.PostAsyncUserUpload(userupload); return(response); }
//Upload files private void UploadFiles(UserDetail data, CreateViewModel model) { foreach (var file in model.FormFiles) { if (file.ContentLength > 0) { var upload = new UserUpload(); //Check and change this after migration upload.UserUploadId = Guid.NewGuid(); upload.TransactionId = data.TransactionId; upload.UserDetailId = data.UserDetailId; // Get FileName //upload.FileName = Path.GetFileName(file.FileName); string folderPath = "/Files/"; string fileName = Path.GetFileNameWithoutExtension(file.FileName); string extension = Path.GetExtension(file.FileName); fileName = fileName + Guid.NewGuid() + extension; upload.FileName = file.FileName; string filePath = folderPath + fileName; upload.FilePath = filePath; fileName = Path.Combine(Server.MapPath(folderPath), fileName); file.SaveAs(fileName); db.UserUpload.Add(upload); db.SaveChanges(); // create file path // save file to local storage // save filepath on upload class } } }
public static UserUpload GetUserUpload(Expression <Func <UserUpload, bool> > searchFunc) { UserUpload retUserUpload = null; try { using (ImgurPlusContext dbContext = new ImgurPlusContext()) retUserUpload = dbContext.UserUploads.FirstOrDefault(searchFunc.Compile()); } catch { return(null); } return(retUserUpload); }
/// <summary> /// Calls Personality Insights and Natural Language Understanding APIs on the user's resume /// </summary> /// <param name="personalityResult"></param> /// <param name="nluResult"></param> private void GetResultsFromWatson(out string personalityResult, out string nluResult) { string textForPI = ""; string textForNLU = ""; //Get the user's resume and cover letter extracted text List <UserUpload> files = _userUploadRepository.GetAll().Where(p => p.CreatorUserId == AbpSession.UserId).ToList(); StringBuilder sb = new StringBuilder(); //Make sure we have a resume if (files.Any(f => f.UploadType == 1 && !String.IsNullOrEmpty(f.ExtractedText))) { UserUpload resume = files.First(f => f.UploadType == 1); sb.Append(resume.ExtractedText); //get facts from the resume textForNLU = resume.ExtractedText; //is there a cover letter? Use it for PI UserUpload coverLetter = files.FirstOrDefault(f => f.UploadType == 2); if (coverLetter != null && !String.IsNullOrEmpty(coverLetter.ExtractedText)) { sb.Append(". "); sb.Append(coverLetter.ExtractedText); } textForPI = sb.ToString(); try { DetailedResponse <IBM.Watson.PersonalityInsights.v3.Model.Profile> pi = _watsonPI.GetInsights(textForPI); personalityResult = pi.Response; } catch (Exception ex) { personalityResult = "error_" + ex.Message; } try { DetailedResponse <IBM.Watson.NaturalLanguageUnderstanding.v1.Model.AnalysisResults> nlu = _watsonNLU.GetAnalysis(textForNLU); nluResult = nlu.Response; } catch (Exception ex) { nluResult = "error_" + ex.Message; } } else { throw new UserFriendlyException("Oops! COOBOT looked around and couldn't find content to analyze. \nPlease make sure you've uploaded a resume and verified the extracted text."); } }
public static UserUpload AddUserUpload(UserUpload userUpload) { UserUpload retUserUpload = null; try { using (ImgurPlusContext dbContext = new ImgurPlusContext()) { retUserUpload = dbContext.UserUploads.Add(userUpload).Entity; dbContext.SaveChanges(); } } catch (Exception ex) { return(null); } return(retUserUpload); }
public static int DeteleUserUpload(Expression <Func <UserUpload, bool> > searchFunc) { int retUserUpload = 0; try { using (ImgurPlusContext dbContext = new ImgurPlusContext()) { UserUpload userUpd = GetUserUpload(searchFunc); userUpd.DeleteDate = DateTimeOffset.Now; dbContext.UserUploads.Update(userUpd); retUserUpload = dbContext.SaveChanges(); } } catch { return(0); } return(retUserUpload); }
public async Task <User> Update(User userParam, IFormFile[] images, string password = null) { if (userParam.FirstName.Length < 5) { throw new AppException("First name is too short"); } if (userParam.FirstName.Length > 15) { throw new AppException("First name is too long"); } if (userParam.Surname.ToUpper().Contains("ROTATE") || userParam.FirstName.ToUpper().Contains("ROTATE") || userParam.Surname.ToUpper().Contains("PAY") || userParam.FirstName.ToUpper().Contains("PAY")) { throw new AppException("Surname or Firstname is not available"); } var user = await _context.Users.FindAsync(userParam.Id); if (user == null) { throw new AppException("User is not found"); } if (images != null) { for (int i = 0; i < images.Length; i++) { if (images[i] != null && images[i].Length > 0) { var file = images[i]; if (file.Length > 0) { if (!file.ContentType.StartsWith("image")) { var fileLength = file.Length / 1024; var maxFileLength = 5120; if (fileLength > maxFileLength) { throw new AppException("Each uploaded file must not be more than 5MB!"); } } } } } } // update user properties user.Surname = userParam.Surname; user.FirstName = userParam.FirstName; user.PhoneNumber = userParam.PhoneNumber; user.HomeAddress = userParam.HomeAddress; user.Lga = userParam.Lga; user.State = userParam.State; user.Country = userParam.Country; user.WorkStatus = userParam.WorkStatus; user.PlaceOfWorkName = userParam.PlaceOfWorkName; user.PlaceOfWorkAddress = userParam.PlaceOfWorkAddress; user.DateOfBirth = userParam.DateOfBirth; user.ContributionAmount = userParam.ContributionAmount; user.CanGuaranteeRequested = userParam.CanGuaranteeRequested; //user.BVN = userParam.BVN; //user.DesiredContributionAmount = userParam.DesiredContributionAmount; //user.OptOutOfContributionLimit = userParam.OptOutOfContributionLimit; user.BankName = userParam.BankName; user.AccountNumber = userParam.AccountNumber; if (!String.IsNullOrEmpty(userParam.BankCode)) { user.BankCode = userParam.BankCode; } string[] userImageNamesDB = new string[images.Length]; if (user.ImageNames != null) { var imageNamesArray = user.ImageNames.Split("......"); userImageNamesDB = imageNamesArray.Skip(1).ToArray(); } string profilePictureFileName = ""; string officialIDCardFileName = ""; string utilityBillFileName = ""; /*string bankStatementFileName = ""; * string workIDCardFileName = "";*/ string[] userImageNames = new string[images.Length]; if (images != null) { for (int i = 0; i < images.Length; i++) { Bitmap originalFile = null; Bitmap resizedFile = null; int imgWidth = 0; int imgHeigth = 0; if (images[i] != null && images[i].Length > 0) { var uploads = Path.GetFullPath(Path.Combine(GlobalVariables.ImagePath, @"images\user")); var file = images[i]; if (file.Length > 0) { var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim(); string uniqueFileName = userParam.FirstName + i + DateTime.Now + file.FileName; string uniqueFileNameTrimmed = uniqueFileName.Replace(":", "").Replace("-", "").Replace(" ", "").Replace("/", ""); if (i == 0) { if (file.FileName == "profilePictureRTPay") { profilePictureFileName = file.FileName; userImageNames[i] = file.FileName; } else { profilePictureFileName = uniqueFileNameTrimmed; userImageNames[i] = uniqueFileNameTrimmed; } } else if (i == 1) { if (file.FileName == "officialIDCardRTPay") { officialIDCardFileName = file.FileName; userImageNames[i] = file.FileName; } else { officialIDCardFileName = uniqueFileNameTrimmed; userImageNames[i] = uniqueFileNameTrimmed; } } else if (i == 2) { if (file.FileName == "utilityBillRTPay") { utilityBillFileName = file.FileName; userImageNames[i] = file.FileName; } else { utilityBillFileName = uniqueFileNameTrimmed; userImageNames[i] = uniqueFileNameTrimmed; } } /*else if (i == 3) { * if (file.FileName == "bankStatementRTPay") { * bankStatementFileName = file.FileName; * userImageNames[i] = file.FileName; * } else { * bankStatementFileName = uniqueFileNameTrimmed; * userImageNames[i] = uniqueFileNameTrimmed; * } * } else if (i == 4) { * if (file.FileName == "workIDCardRTPay") { * workIDCardFileName = file.FileName; * userImageNames[i] = file.FileName; * } else { * workIDCardFileName = uniqueFileNameTrimmed; * userImageNames[i] = uniqueFileNameTrimmed; * } * } */ using (var fileStream = new FileStream(Path.Combine(uploads, uniqueFileNameTrimmed), FileMode.Create)) { await file.CopyToAsync(fileStream); if (file.ContentType.StartsWith("image")) { int width = 100; int height = 100; originalFile = new Bitmap(fileStream); resizedFile = ResizeImage.GetResizedImage(fileStream, width, height, width, height); } } if (resizedFile != null) { imgWidth = resizedFile.Width; imgHeigth = resizedFile.Height; using (var fileStreamUp = new FileStream(Path.Combine(uploads, uniqueFileNameTrimmed), FileMode.Create)) { resizedFile.Save(fileStreamUp, ImageFormat.Jpeg); } } } } else { if (i == 0) { profilePictureFileName = userImageNamesDB[i]; userImageNames[i] = userImageNamesDB[i]; } else if (i == 1) { officialIDCardFileName = userImageNamesDB[i]; userImageNames[i] = userImageNamesDB[i]; } else if (i == 2) { utilityBillFileName = userImageNamesDB[i]; userImageNames[i] = userImageNamesDB[i]; } /*else if (i == 3) { * bankStatementFileName = userImageNamesDB[i]; * userImageNames[i] = userImageNamesDB[i]; * } else if (i == 4) { * workIDCardFileName = userImageNamesDB[i]; * userImageNames[i] = userImageNamesDB[i]; * } */ } } } var userUpload = new UserUpload { UserId = user.Id, ProfilePicture = profilePictureFileName, OfficialIDCard = officialIDCardFileName, UtilityBill = utilityBillFileName, /*BankStatement = bankStatementFileName, * WorkIDCard = workIDCardFileName,*/ }; user.ImageNames = ""; userUpload.ImageNames = ""; for (int i = 0; i < images.Length; i++) { user.ImageNames = user.ImageNames + "......" + userImageNames[i]; userUpload.ImageNames = userUpload.ImageNames + "......" + userImageNames[i]; } DateTime userLocalDate_Nigeria = new DateTime(); string windowsTimeZone = GetWindowsFromOlson.GetWindowsFromOlsonFunc("Africa/Lagos"); userLocalDate_Nigeria = TimeZoneInfo.ConvertTime(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById(windowsTimeZone)); user.DateEdited = userLocalDate_Nigeria; user.LastSeen = userLocalDate_Nigeria; _context.Users.Update(user); await _context.SaveChangesAsync(); if (userParam.ImageNames.Contains("Changed")) { //ThreadPool.QueueUserWorkItem(o => { string body = "<br/><br/>The attached documents were sent by: " + user.FirstName + " (" + user.Email + ")<br/><br/>"; var message = new Message(new string[] { GlobalVariables.DocumentEmail }, "[RotatePay] Profile documents by " + user.Email, body, images); _emailSenderService.SendEmail(message); //}); userUpload.DateAdded = userLocalDate_Nigeria; _context.UserUploads.Add(userUpload); await _context.SaveChangesAsync(); } //await _logService.Create(log); return(user); }