Beispiel #1
0
        /// <summary>
        /// FineToUser
        /// </summary>
        /// <param name="booking"></param>
        /// <returns></returns>
        public string FineToUser(BookingModel booking)
        {
            try
            {
                string host = ConfigurationManager.AppSettings["Host"];
                string from = ConfigurationManager.AppSettings["FromEmail"];

                string password = ConfigurationManager.AppSettings["Password"];
                int    port     = Convert.ToInt32(ConfigurationManager.AppSettings["Port"]);
                List <PushNotificationModel> pushList = new List <PushNotificationModel>();
                if (Convert.ToInt32(booking.FineToOwner) > 0)
                {
                    var ownerFine = _dbEntity.tblUsers.FirstOrDefault(x => x.Id == booking.OwnerId);
                    var OwnerId   = booking.OwnerId;
                    if (ownerFine.FineAmount != null)
                    {
                        ownerFine.FineAmount = ownerFine.FineAmount + Convert.ToInt32(booking.FineToOwner);
                    }
                    else
                    {
                        ownerFine.FineAmount = Convert.ToInt32(booking.FineToOwner);
                    }
                    var ownerDevice = _dbEntity.tblUserDeviceMappings.Where(x => x.UserId == OwnerId).ToList();
                    if (ownerDevice.Count > 0)
                    {
                        foreach (var item in ownerDevice)
                        {
                            PushNotificationModel pushModel = new PushNotificationModel();
                            pushModel.DeviceToken = item.DeviceToken;
                            pushModel.Message     = "You have been fined by amount £" + booking.FineToOwner + " for Dispute(" + booking.DisputeId + ") for booking " + booking.BookingId;
                            pushList.Add(pushModel);
                        }
                    }

                    var ownerEmail = _dbEntity.tblLogins.FirstOrDefault(x => x.Id == ownerFine.LoginId);
                }
                if (Convert.ToInt32(booking.FineToRenter) > 0)
                {
                    var renterFine = _dbEntity.tblUsers.FirstOrDefault(x => x.Id == booking.UserId);
                    var renterId   = booking.UserId;
                    if (renterFine.FineAmount != null)
                    {
                        renterFine.FineAmount = renterFine.FineAmount + Convert.ToInt32(booking.FineToRenter);
                    }
                    else
                    {
                        renterFine.FineAmount = Convert.ToInt32(booking.FineToRenter);
                    }
                    var renterDevice = _dbEntity.tblUserDeviceMappings.Where(x => x.UserId == renterId).ToList();
                    if (renterDevice.Count > 0)
                    {
                        foreach (var item in renterDevice)
                        {
                            PushNotificationModel pushmodel = new PushNotificationModel();
                            pushmodel.DeviceToken = item.DeviceToken;
                            pushmodel.Message     = "You have been fined by amount £" + booking.FineToRenter + " for Dispute(" + booking.DisputeId + ") for booking " + booking.BookingId;
                            pushList.Add(pushmodel);
                        }
                    }
                }
                PushNotifications.PushToIphone(pushList);
                _dbEntity.SaveChanges();
                return("FineSuccess");
            }
            catch (Exception ex)
            {
                Common.ExcepLog(ex);
                return(null);
            }
        }
Beispiel #2
0
        public string CaptureSecuirtyById(long id)
        {
            try
            {
                string     host           = ConfigurationManager.AppSettings["Host"];
                string     from           = ConfigurationManager.AppSettings["FromEmail"];
                string     insurerEmail   = ConfigurationManager.AppSettings["InsurerEmail"];
                string     password       = ConfigurationManager.AppSettings["Password"];
                int        port           = Convert.ToInt32(ConfigurationManager.AppSettings["Port"]);
                tblBooking bookingDetails = ((IQueryable <tblBooking>) this._dbEntity.tblBookings).FirstOrDefault <tblBooking>((Expression <Func <tblBooking, bool> >)(x => x.BookingId == id));
                if (bookingDetails == null)
                {
                    return(string.Empty);
                }


                string str1 = string.Empty;
                if (bookingDetails.IsSecurityByPaypal == true)
                {
                    if (!string.IsNullOrEmpty(bookingDetails.SecurityId))
                    {
                        try
                        {
                            bool captureId = PayPalImplement.CaptureAuthorization(bookingDetails.SecurityId);
                            str1 = "ok";
                            bookingDetails.IsSecurityCaptureOrRefund = new bool?(true);
                            this._dbEntity.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                            str1 = string.Empty;
                        }
                    }
                }
                else
                {
                    str1 = "ok";
                }

                bookingDetails.IsSecurityCaptureOrRefund = new bool?(true);
                this._dbEntity.SaveChanges();

                if (!string.IsNullOrEmpty(str1))
                {
                    List <tblUserDeviceMapping> list = ((IQueryable <tblUserDeviceMapping>) this._dbEntity.tblUserDeviceMappings).Where <tblUserDeviceMapping>((Expression <Func <tblUserDeviceMapping, bool> >)(x => x.UserId == bookingDetails.UserId)).ToList <tblUserDeviceMapping>();
                    if (list != null && list.Count > 0)
                    {
                        List <PushNotificationModel> devicelist = new List <PushNotificationModel>();
                        foreach (tblUserDeviceMapping userDeviceMapping in list)
                        {
                            devicelist.Add(new PushNotificationModel()
                            {
                                DeviceToken = userDeviceMapping.DeviceToken,
                                Message     = "Security amount has been captured by BiblioVélo for your booking with Booking Id: " + (object)bookingDetails.BookingId
                            });
                        }
                        PushNotifications.PushToIphone(devicelist);
                    }
                    tblUser     userDetails = ((IQueryable <tblUser>) this._dbEntity.tblUsers).FirstOrDefault <tblUser>((Expression <Func <tblUser, bool> >)(x => (long?)x.Id == bookingDetails.UserId));
                    tblLogin    tblLogin    = ((IQueryable <tblLogin>) this._dbEntity.tblLogins).FirstOrDefault <tblLogin>((Expression <Func <tblLogin, bool> >)(x => (long?)x.Id == userDetails.LoginId));
                    MailMessage message     = new MailMessage();
                    string      str2        = System.IO.File.ReadAllText(Path.Combine(HttpContext.Current.Server.MapPath("~/EmailTemplate"), "MailTemplate.html")).Replace("{UserName}", userDetails.FirstName + ",");
                    string      empty       = string.Empty;
                    string      newValue    = "Security amount has been captured/hold by BiblioVélo for your booking with Booking Id:" + (object)bookingDetails.BookingId;
                    string      str3        = str2.Replace("{Message}", newValue);
                    string      email       = tblLogin.Email;
                    string      str4        = "Security Amount Captured By BiblioVélo";

                    message.From = new MailAddress(from, "BiblioVélo Support");
                    message.To.Add(email);
                    message.Subject    = str4;
                    message.IsBodyHtml = true;
                    message.Body       = str3;
                    SmtpClient smtpClient = new SmtpClient(host, port);

                    smtpClient.EnableSsl   = true;
                    smtpClient.Credentials = new NetworkCredential(from, password);
                    try
                    {
                        smtpClient.Send(message);
                    }
                    catch (SmtpException ex1)
                    {
                        Common.ExcepLog(ex1);
                    }
                }
                return(str1);
            }

            catch (Exception ex)
            {
                Common.ExcepLog(ex);
                return(string.Empty);
            }
        }
Beispiel #3
0
        /// <summary>
        /// RefundToUser
        /// </summary>
        /// <param name="booking"></param>
        /// <returns></returns>
        public string RefundToUser(BookingModel booking)
        {
            string refundId = null;
            string host     = ConfigurationManager.AppSettings["Host"];
            string from     = ConfigurationManager.AppSettings["FromEmail"];
            string password = ConfigurationManager.AppSettings["Password"];
            int    port     = Convert.ToInt32(ConfigurationManager.AppSettings["Port"]);
            List <PushNotificationModel> pushlist = new List <PushNotificationModel>();

            if (booking.RefundType == "Full")
            {
                refundId = PaymentGateway.RefundToUser(booking.ChargeId, true, 0);
                if (refundId != null)
                {
                    var renterDevice = _dbEntity.tblUserDeviceMappings.Where(x => x.UserId == booking.UserId).ToList();
                    if (renterDevice != null && renterDevice.Count > 0)
                    {
                        foreach (var items in renterDevice)
                        {
                            PushNotificationModel pushModel = new PushNotificationModel();
                            pushModel.DeviceToken = items.DeviceToken;
                            pushModel.Message     = "Full Refund is initiated regarding your Dispute(" + booking.DisputeId + ") for booking " + booking.BookingId;
                            pushlist.Add(pushModel);
                        }
                    }
                }
            }
            else if (booking.RefundType == "Specific")
            {
                refundId = PaymentGateway.RefundToUser(booking.ChargeId, false, Convert.ToInt32(booking.SpecificAmount));
                if (refundId != null)
                {
                    var renterDevice = _dbEntity.tblUserDeviceMappings.Where(x => x.UserId == booking.UserId).ToList();
                    if (renterDevice != null && renterDevice.Count > 0)
                    {
                        foreach (var items in renterDevice)
                        {
                            PushNotificationModel pushModel = new PushNotificationModel();
                            pushModel.DeviceToken = items.DeviceToken;
                            pushModel.Message     = "Refund of Amount: £" + booking.SpecificAmount + " is initiated regarding your Dispute(" + booking.DisputeId + ") for booking " + booking.BookingId;
                            pushlist.Add(pushModel);
                        }
                    }
                }
            }
            else
            {
                var OwnerCredit = _dbEntity.tblUsers.FirstOrDefault(x => x.Id == booking.OwnerId);
                if (OwnerCredit != null)
                {
                    if (OwnerCredit.CreditAmount != null)
                    {
                        OwnerCredit.CreditAmount = OwnerCredit.CreditAmount + Convert.ToInt32(booking.AmountToOwner);
                    }
                    else
                    {
                        OwnerCredit.CreditAmount = Convert.ToInt32(booking.AmountToOwner);
                    }
                }

                PaymentGateway.TranferPayment(Convert.ToInt32(booking.AmountToOwner), "GBP", OwnerCredit.AccountId);

                var ownerDevice = _dbEntity.tblUserDeviceMappings.Where(x => x.UserId == booking.OwnerId).ToList();
                if (ownerDevice != null && ownerDevice.Count > 0)
                {
                    foreach (var item in ownerDevice)
                    {
                        PushNotificationModel pushModel = new PushNotificationModel();
                        pushModel.DeviceToken = item.DeviceToken;
                        pushModel.Message     = "You have been Credited by amount £" + booking.AmountToOwner + " is initiated regarding your Dispute(" + booking.DisputeId + ") for booking " + booking.BookingId;
                        pushlist.Add(pushModel);
                    }
                }
                refundId = string.Empty;
            }
            PushNotifications.PushToIphone(pushlist);
            if (!string.IsNullOrEmpty(refundId))
            {
                var bookingDetails = _dbEntity.tblBookings.FirstOrDefault(x => x.BookingId == booking.BookingId);
                if (bookingDetails != null)
                {
                    bookingDetails.IsRefund = true;
                    _dbEntity.SaveChanges();
                }
            }



            return(refundId);
        }