public async Task <User> Add(Transaction transaction) { var user = await _context.Users.Where(x => x.Email == transaction.Email).FirstOrDefaultAsync(); if (user == null) { throw new AppException("User is not found"); } DateTime transactionLocalDate_Nigeria = new DateTime(); string windowsTimeZone = GetWindowsFromOlson.GetWindowsFromOlsonFunc("Africa/Lagos"); transactionLocalDate_Nigeria = TimeZoneInfo.ConvertTime(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById(windowsTimeZone)); transaction.DateAdded = transactionLocalDate_Nigeria; await _context.Transactions.AddAsync(transaction); await _context.SaveChangesAsync(); //ThreadPool.QueueUserWorkItem(o => { string body = "Dear " + user.FirstName + ",<br/><br/>We have confirmed your payment of <b>" + transaction.AmountPaid + "</b>.<br/><br/>" + "For more information, check the transactions section of your online profile.<br/><br/>" + "Thanks,<br/>The RotatePay Team<br/>"; var message = new Message(new string[] { transaction.Email }, "[RotatePay] Payment Notification Confirmed", body, null); _emailSenderService.SendEmail(message); //}); //await _logService.Create(log); return(user); }
public async Task <User> UpdateUserInfo(int id, string userCookie) { var user = await _context.Users.FindAsync(id); if (user != null) { var userCookieFromDb = user.UserCookie; var userCookieFromDbCounter = 0; if (user.UserCookieChangeCounter != null) { userCookieFromDbCounter = Int32.Parse(user.UserCookieChangeCounter); } if ((userCookieFromDb == null) || (userCookieFromDb != userCookie)) { userCookieFromDbCounter++; user.UserCookieChangeCounter = userCookieFromDbCounter.ToString(); user.UserCookie = userCookie; } if (!String.IsNullOrEmpty(userCookie)) { var relatedAccounts = await _context.Users.Where(x => x.UserCookie == userCookie).Select(x => x.Email).ToListAsync(); if (!relatedAccounts.Contains(user.Email)) { relatedAccounts.Add(user.Email); } if (String.IsNullOrEmpty(user.RelatedAccounts)) { for (var i = 0; i < relatedAccounts.Count; i++) { user.RelatedAccounts = user.RelatedAccounts + "..." + relatedAccounts[i]; } user.UserNumberOfRelatedAccounts = CountSubstring(user.RelatedAccounts, "...").ToString(); } else { for (var i = 0; i < relatedAccounts.Count; i++) { if (user.RelatedAccounts.IndexOf(relatedAccounts[i], StringComparison.CurrentCultureIgnoreCase) == -1) { user.RelatedAccounts = user.RelatedAccounts + "..." + relatedAccounts[i]; } } user.UserNumberOfRelatedAccounts = CountSubstring(user.RelatedAccounts, "...").ToString(); } } DateTime userLocalDate_Nigeria = new DateTime(); string windowsTimeZone = GetWindowsFromOlson.GetWindowsFromOlsonFunc("Africa/Lagos"); userLocalDate_Nigeria = TimeZoneInfo.ConvertTime(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById(windowsTimeZone)); user.LastSeen = userLocalDate_Nigeria; _context.Users.Update(user); await _context.SaveChangesAsync(); } return(user); }
public async Task <Guarantor> Add(Guarantor guarantor) { var guarantorFromDb = await _context.Users.Where(x => x.Email == guarantor.GuarantorEmail) .FirstOrDefaultAsync(); var guaranteeFromDb = await _context.Users.Where(x => x.Email == guarantor.GuaranteeEmail) .FirstOrDefaultAsync(); if (guarantorFromDb == null || (!guaranteeFromDb.CanGuarantee) || ((guarantorFromDb != null) && (guarantorFromDb.Email == guarantor.GuaranteeEmail))) { throw new AppException("Guarantor is not found"); } if (guaranteeFromDb == null) { throw new AppException("User is not found"); } if (_context.Guarantors.Any(x => (x.GuaranteeEmail == guarantor.GuaranteeEmail) && x.GuarantorEmail == guarantor.GuarantorEmail)) { throw new AppException("Guarantor has already been added"); } guarantor.Status = "Awaiting approval"; DateTime guarantorLocalTime_Nigeria = new DateTime(); string windowsTimeZone = GetWindowsFromOlson.GetWindowsFromOlsonFunc("Africa/Lagos"); guarantorLocalTime_Nigeria = TimeZoneInfo.ConvertTime(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById(windowsTimeZone)); guarantor.DateAdded = guarantorLocalTime_Nigeria; await _context.Guarantors.AddAsync(guarantor); await _context.SaveChangesAsync(); string body = "Dear " + guaranteeFromDb.FirstName + ",<br/><br/>Your request for a guarantee has been sent to " + guarantorFromDb.Email + " .<br/><br/>" + "You will receive an email from us when your guarantor provides a guarantee for you.<br/><br/>" + "Thanks,<br/>The RotatePay Team<br/>"; var message = new Message(new string[] { guaranteeFromDb.Email }, "[RotatePay] Request for Guarantee", body, null); _emailSenderService.SendEmail(message); string body1 = "Dear " + guarantorFromDb.FirstName + ",<br/><br/> " + guaranteeFromDb.FirstName + "(" + guaranteeFromDb.Email + ")" + " has requested that you provide a guarantee for their RotatePay profile.<br/><br/>" + "You can either accept or decline to provide a guarantee.<br/><br/>" + "Before you accept to provide guarantee for anyone, please ensure that you know them very well and that they can easily afford to pay their proposed contribution amount monthly.<br/><br/>" + "To provide a guarantee, please login to your RotatePay profile and check the Gaurantor secction for more information.<br/><br/>" + "Thanks,<br/>The RotatePay Team<br/>"; var message1 = new Message(new string[] { guarantorFromDb.Email }, "[RotatePay] Request for Guarantee", body1, null); _emailSenderService.SendEmail(message1); //await _logService.Create(log); return(guarantor); }
public async Task <User> Add(PaymentNotification paymentNotification, IFormFile[] images) { var user = await _context.Users.Where(x => x.Email == paymentNotification.Email).FirstOrDefaultAsync(); 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("Uploaded file must not be more than 5MB!"); } } } } } } if (images != null) { for (int i = 0; i < images.Length; i++) { Bitmap originalFile = null; Bitmap resizedFile = null; int imgWidth = 0; int imgHeigth = 0; if ((i == 0) && (images[i] != null) && (images[i].Length > 0)) { var uploads = Path.GetFullPath(Path.Combine(GlobalVariables.ImagePath, @"images\payment")); var file = images[i]; if (file.Length > 0) { var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim(); string uniqueFileName = paymentNotification.FirstName.Substring(0, 5) + i + DateTime.Now + file.FileName; string uniqueFileNameTrimmed = uniqueFileName.Replace(":", "").Replace("-", "").Replace(" ", "").Replace("/", ""); using (var fileStream = new FileStream(Path.Combine(uploads, uniqueFileNameTrimmed), FileMode.Create)) { await file.CopyToAsync(fileStream); paymentNotification.ImageNames = uniqueFileNameTrimmed; if (file.ContentType.StartsWith("image")) { int width = 200; int height = 200; 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); } } } } } } DateTime paymentNotificationLocalDate_Nigeria = new DateTime(); string windowsTimeZone = GetWindowsFromOlson.GetWindowsFromOlsonFunc("Africa/Lagos"); paymentNotificationLocalDate_Nigeria = TimeZoneInfo.ConvertTime(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById(windowsTimeZone)); paymentNotification.DateAdded = paymentNotificationLocalDate_Nigeria; int length = GlobalVariables.RandomStringLengthShort(); var randomKey = ""; var keyIsAlreadyPresent = true; do { randomKey = GlobalVariables.RandomString(length); keyIsAlreadyPresent = _context.PaymentNotifications.Any(x => x.Reference == randomKey); } while (keyIsAlreadyPresent); paymentNotification.Reference = randomKey; paymentNotification.Confirmed = "No"; paymentNotification.UpdateAllowed = true; await _context.PaymentNotifications.AddAsync(paymentNotification); if (paymentNotification.TransactionType == "Activation") { user.ActivationRequested = true; _context.Users.Update(user); } await _context.SaveChangesAsync(); //ThreadPool.QueueUserWorkItem(o => { string body = "Dear " + paymentNotification.FirstName + ",<br/><br/>Thank you for submitting your payment notification.<br/><br/>" + "We will confirm your payment and update your online profile.<br/><br/>" + "You will also receive an email from us as soon as we have confirmed your payment<br/><br/>" + "Thanks,<br/>The RotatePay Team<br/>"; var message = new Message(new string[] { paymentNotification.Email }, "[RotatePay] Payment Notification Received", body, null); _emailSenderService.SendEmail(message); string body1 = paymentNotification.FirstName + "(" + paymentNotification.Email + ") has submitted the payment notification form.<br/><br/><br/>"; var message1 = new Message(new string[] { GlobalVariables.AdminEmail }, "[RotatePay] Payment receipt by " + paymentNotification.Email, body1, images); _emailSenderService.SendEmail(message1); //}); //await _logService.Create(log); return(user); }
public async Task <PaymentNotification> Update(PaymentNotification paymentNotificationParam, IFormFile[] images) { var paymentNotification = await _context.PaymentNotifications.Where(x => x.Reference == paymentNotificationParam.Reference).FirstOrDefaultAsync(); if (paymentNotification == null) { throw new AppException("Payment notification not found"); } if (!paymentNotification.UpdateAllowed) { throw new AppException("Invalid payment notification update attempted"); } 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("Uploaded file must not be more than 5MB!"); } } } } } } paymentNotification.AmountPaid = paymentNotificationParam.AmountPaid; paymentNotification.PaymentChannel = paymentNotificationParam.PaymentChannel; paymentNotification.PaymentDateAndTime = paymentNotificationParam.PaymentDateAndTime; paymentNotification.DepositorName = paymentNotificationParam.DepositorName; paymentNotification.AdditionalDetails = paymentNotificationParam.AdditionalDetails; if (images != null) { for (int i = 0; i < images.Length; i++) { Bitmap originalFile = null; Bitmap resizedFile = null; int imgWidth = 0; int imgHeigth = 0; if ((i == 0) && (images[i] != null) && (images[i].Length > 0)) { var uploads = Path.GetFullPath(Path.Combine(GlobalVariables.ImagePath, @"images\payment")); var file = images[i]; if (file.Length > 0) { var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim(); string uniqueFileName = paymentNotification.FirstName.Substring(0, 5) + i + DateTime.Now + file.FileName; string uniqueFileNameTrimmed = uniqueFileName.Replace(":", "").Replace("-", "").Replace(" ", "").Replace("/", ""); using (var fileStream = new FileStream(Path.Combine(uploads, uniqueFileNameTrimmed), FileMode.Create)) { await file.CopyToAsync(fileStream); paymentNotification.ImageNames = uniqueFileNameTrimmed; if (file.ContentType.StartsWith("image")) { int width = 200; int height = 200; 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); } } } } } } DateTime paymentNotificationLocalDate_Nigeria = new DateTime(); string windowsTimeZone = GetWindowsFromOlson.GetWindowsFromOlsonFunc("Africa/Lagos"); paymentNotificationLocalDate_Nigeria = TimeZoneInfo.ConvertTime(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById(windowsTimeZone)); paymentNotification.DateEdited = paymentNotificationLocalDate_Nigeria; _context.PaymentNotifications.Update(paymentNotification); await _context.SaveChangesAsync(); //ThreadPool.QueueUserWorkItem(o => { string body = "Dear " + paymentNotification.FirstName + ",<br/><br/>Thank you for updating your payment notification.<br/><br/>" + "We will check your updated payment notification and update your online profile.<br/><br/>" + "You will also receive an email from us as soon as we have taken any action on your updated payment notification<br/><br/>" + "Thanks,<br/>The RotatePay Team<br/>"; var message = new Message(new string[] { paymentNotification.Email }, "[RotatePay] Updated Payment Notification Received", body, null); _emailSenderService.SendEmail(message); string body1 = paymentNotification.FirstName + "(" + paymentNotification.Email + ") has updated their payment notification with reference " + paymentNotification.Reference + ".<br/><br/><br/>"; var message1 = new Message(new string[] { GlobalVariables.AdminEmail }, "[RotatePay] Updated Payment Notification by " + paymentNotification.Email, body1, images); _emailSenderService.SendEmail(message1); //}); //await _logService.Create(log); return(paymentNotification); }
public async Task <User> Create(User user, string password) { // validation if (string.IsNullOrWhiteSpace(password)) { throw new AppException("Password is required"); } if (_context.Users.Any(x => x.Email == user.Email)) { throw new AppException("Email '" + user.Email + "' is not available"); } if (user.FirstName.Length < 5) { throw new AppException("First name is too short"); } if (user.FirstName.Length > 15) { throw new AppException("First name is too long"); } if (user.Email.ToUpper().Contains("ROTATE") || user.FirstName.ToUpper().Contains("ROTATE") || user.Email.ToUpper().Contains("PAY") || user.FirstName.ToUpper().Contains("PAY")) { throw new AppException("Surname or Firstname is not available"); } byte[] passwordHash, passwordSalt; CreatePasswordHash(password, out passwordHash, out passwordSalt); user.PasswordHash = passwordHash; user.PasswordSalt = passwordSalt; user.Role = "User"; user.ImageNames = "......profilePictureRTPay......officialIDCardRTPay......utilityBillRTPay"; //......bankStatementRTPay......workIDCardRTPay"; DateTime userLocalDate_Nigeria = new DateTime(); string windowsTimeZone = GetWindowsFromOlson.GetWindowsFromOlsonFunc("Africa/Lagos"); userLocalDate_Nigeria = TimeZoneInfo.ConvertTime(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById(windowsTimeZone)); user.DateAdded = userLocalDate_Nigeria; user.DateEdited = userLocalDate_Nigeria; user.LastSeen = userLocalDate_Nigeria; int length = GlobalVariables.RandomStringLength(); var randomKey = ""; var keyIsAlreadyPresent = true; do { randomKey = GlobalVariables.RandomString(length); keyIsAlreadyPresent = _context.Users.Any(x => x.HiDee == randomKey); } while (keyIsAlreadyPresent); user.HiDee = randomKey; //ThreadPool.QueueUserWorkItem(o => { var url = GlobalVariables.URL + "/vaccount?em=" + user.Email + "&vc=" + user.EmailConfirmationCode; var link = $"<a href='{url}'>Click here</a>"; string body = "Dear " + user.FirstName + ",<br/><br/>Thank you for registering with RotatePay.<br/><br/>" + "Click on the link below to confirm your email address. <br/><br/>" + link + "<br/><br/>" + " If the link above can not be clicked, copy and paste the url below in your browser<br/>" + url + "<br/><br/><br/>" + "Thanks,<br/>The RotatePay Team<br/>"; var message = new Message(new string[] { user.Email }, "[RotatePay] Confirm your email address", body, null); _emailSenderService.SendEmail(message); //}); await _context.Users.AddAsync(user); await _context.SaveChangesAsync(); //await _logService.Create(log); return(user); }
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); }