Exemplo n.º 1
0
        public PaymentDetailModel VerifyPayment(PaymentDetailModel model)
        {
            var paymentDetailModel = new PaymentDetailModel();

            using (var dataModel = new MibarimEntities())
            {
                var amount = dataModel.PayReqs.FirstOrDefault(x => x.PayReqAuthority == model.Authority);
                if (amount != null)
                {
                    long refId;
                    int  status = _zarinPalService.VerifyTransaction(model.Authority, (int)amount.PayReqValue, out refId);
                    amount.PayReqStatus = status.ToString();
                    if (status == 100)
                    {
                        amount.PayReqRefID = refId.ToString();
                        var payRoute =
                            dataModel.vwPayRoutes.FirstOrDefault(
                                x => x.PayReqId == amount.PayReqId && x.DrIsDeleted == false);
                        var route =
                            dataModel.vwStationRoutes.FirstOrDefault(x => x.StationRouteId == payRoute.StationRouteId);
                        _transactionManager.ChargeAccount(amount.PayReqUserId, (int)route.PassPrice);
                        if (route.DriverPrice > route.PassPrice)
                        {
                            _transactionManager.GiftChargeAccount(amount.PayReqUserId,
                                                                  (int)(route.DriverPrice - route.PassPrice));
                        }
                        _transactionManager.PayMoney(amount.PayReqUserId, (int)payRoute.UserId, (int)route.DriverPrice);
                        NotifModel notifModel = new NotifModel();
                        notifModel.Title = getResource.getMessage("SeatReserved");
                        notifModel.Body  = string.Format(getResource.getMessage("SeatReservedFor"), route.SrcMainStName,
                                                         route.DstMainStName, payRoute.TStartTime.ToString("HH:mm"));
                        notifModel.RequestCode    = (int)payRoute.PayReqId;
                        notifModel.NotificationId = (int)payRoute.PayReqId;
                        //send passenger notif
                        _notifManager.SendNotifToUser(notifModel, payRoute.PayReqUserId);
                        //send driver notif
                        _notifManager.SendNotifToUser(notifModel, (int)payRoute.UserId);
                        _notifManager.SendNotifToAdmins(notifModel);
                        //send passenger sms
                        var    user        = dataModel.vwUserInfoes.FirstOrDefault(x => x.UserId == payRoute.PayReqUserId);
                        var    mobileBrief = user.UserName.Substring(1);
                        string smsBody     = string.Format(getResource.getMessage("SeatReservedFor"), route.SrcMainStName,
                                                           route.DstMainStName, payRoute.TStartTime.ToString("HH:mm"));
                        var smsService = new SmsService();
                        smsService.SendSmsMessages(mobileBrief, smsBody);
                        //send driver sms
                        var    driver            = dataModel.vwUserInfoes.FirstOrDefault(x => x.UserId == payRoute.UserId);
                        var    drivermobileBrief = driver.UserName.Substring(1);
                        string smsBodydriver     = string.Format(getResource.getMessage("SeatReservedFor"),
                                                                 route.SrcMainStName, route.DstMainStName, payRoute.TStartTime.ToString("HH:mm"));
                        smsService.SendSmsMessages(drivermobileBrief, smsBodydriver);
                        smsService.SendSmsMessages("9358695785", smsBody);
                        smsService.SendSmsMessages("9354205407", smsBody);
                    }
                    dataModel.SaveChanges();
                    paymentDetailModel.RefId = refId;
                }
            }
            return(paymentDetailModel);
        }