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> 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);
        }
示例#3
0
        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);
        }