コード例 #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);
        }
コード例 #2
0
 public void ChargeAccount(int userId, int value, string desc, TransactionType transactionType)
 {
     using (var dataModel = new MibarimEntities())
     {
         var userInfo = dataModel.vwUserInfoes.FirstOrDefault(x => x.UserId == userId);
         //var desc = string.Format(getResource.getMessage("GiftPayDesc"), GetUserNameFamilyString(userInfo), value);
         var trans = new Tran();
         trans.TransCreateTime  = DateTime.Now;
         trans.TransType        = (short)transactionType;
         trans.TransUserId      = userId;
         trans.TransValue       = value;
         trans.TransDescription = desc;
         dataModel.Trans.Add(trans);
         dataModel.SaveChanges();
         try
         {
             NotifModel notifModel = new NotifModel();
             notifModel.Title          = getResource.getString("Transaction");
             notifModel.Body           = desc;
             notifModel.RequestCode    = (int)trans.TransId;
             notifModel.NotificationId = (int)trans.TransId;
             _notifManager.SendNotifToUser(notifModel, userId);
             var mobileBrief = userInfo.UserName.Substring(1);
             var smsService  = new SmsService();
             smsService.SendSmsMessages(mobileBrief, desc);
         }
         catch (Exception e)
         {
             _logmanager.Log(Tag, "ChargeAccount", e.Message);
         }
     }
 }
コード例 #3
0
ファイル: GroupManager.cs プロジェクト: Hamedlq/m_CoreApiPlus
 private async Task DelayedTask(NotifModel notifModel, long contactId, int senderUserId, int receiverUserId)
 {
     using (var dataModel = new MibarimEntities())
     {
         if (dataModel.Chats.Any(x => x.ContactId == contactId && x.ChatUserId == senderUserId && x.IsChatSeen == false))
         {
             _notifManager.SendNotifToUser(notifModel, receiverUserId);
             dataModel.Chats.Where(x => x.ContactId == contactId && x.ChatUserId == senderUserId).Each(x => x.IsChatSeen = true);
         }
     }
 }
コード例 #4
0
ファイル: GroupManager.cs プロジェクト: Hamedlq/m_CoreApiPlus
 public async Task DoStuff(NotifModel notifModel, long contactId, int senderUserId, int receiverUserId)
 {
     await Task.Run(() =>
     {
         var t = Task.Run(async delegate
         {
             await Task.Delay(15000);
             await DelayedTask(notifModel, contactId, senderUserId, receiverUserId);
         });
         t.Wait();
     });
 }
コード例 #5
0
 public void SendNotifToAdmins(NotifModel notif)
 {
     using (var dataModel = new MibarimEntities())
     {
         var gtoken =
             dataModel.GoogleTokens.Where(x => x.GtokenUserId == 27 || x.GtokenUserId == 1 || x.GtokenUserId == 181 || x.GtokenUserId == 12325)
             .OrderByDescending(x => x.GtokenCreateTime).ToList();
         if (gtoken.Count > 0)
         {
             _gService.SendNotification(gtoken.FirstOrDefault().GtokenKey, notif.EncodedTitle, notif.EncodedBody, notif.Action, notif.Tab.ToString(), notif.RequestCode, (int)notif.NotificationId, notif.Url);
         }
     }
 }
コード例 #6
0
 public void SendNotifToDriver(NotifModel notif, int userId)
 {
     using (var dataModel = new MibarimEntities())
     {
         var gtoken =
             dataModel.GoogleTokens.Where(x => x.GtokenUserId == userId && x.GtokenRole == (int)UserRoles.MobileDriver)
             .OrderByDescending(x => x.GtokenCreateTime).ToList();
         if (gtoken.Count > 0)
         {
             _gService.SendNotification(gtoken.FirstOrDefault().GtokenKey, notif.EncodedTitle, notif.EncodedBody, notif.Action, notif.Tab.ToString(), notif.RequestCode, (int)notif.NotificationId, notif.Url);
         }
     }
 }
コード例 #7
0
 public void SendGroupNotif(NotifModel notif, List <int> userIds)
 {
     string[] gTokens;
     using (var dataModel = new MibarimEntities())
     {
         var gtokens =
             dataModel.GoogleTokens.Where(x => userIds.Contains((int)x.GtokenUserId))
             .GroupBy(x => x.GtokenUserId, (key, g) => g.OrderByDescending(e => e.GtokenCreateTime).FirstOrDefault()).ToList();
         if (gtokens.Count > 0)
         {
             _gService.SendGroupNotification(gtokens.Select(x => x.GtokenKey).ToList(), notif.Title, notif.Body, notif.Action, notif.Tab.ToString(), notif.Url);
         }
     }
 }
コード例 #8
0
ファイル: GroupManager.cs プロジェクト: Hamedlq/m_CoreApiPlus
        public string SubmitChat(int userId, string mobile, string comment)
        {
            using (var dataModel = new MibarimEntities())
            {
                var validation =
                    dataModel.Contacts.Where(x => (x.ContactDriverUserId == 1 && x.ContactPassengerUserId == userId) && !x.ContactIsDeleted).ToList();
                if (validation.Count > 0)
                {
                    var contact      = validation.FirstOrDefault();
                    var commentModel = new Chat();
                    commentModel.ContactId      = contact.ContactId;
                    commentModel.ChatCreateTime = DateTime.Now;
                    commentModel.ChatIsDeleted  = false;
                    commentModel.ChatUserId     = 1;
                    commentModel.IsChatSeen     = false;
                    commentModel.ChatTxt        = comment;
                    dataModel.Chats.Add(commentModel);
                    dataModel.SaveChanges();
                    var otherUsers = validation.FirstOrDefault();
                    otherUsers.ContactLastMsg     = Truncate(comment, 28);
                    otherUsers.ContactLastMsgTime = DateTime.Now;
                    var        user       = dataModel.vwUserInfoes.FirstOrDefault(x => x.UserId == userId);
                    NotifModel notifModel = new NotifModel();
                    notifModel.Title          = user.Name + " " + user.Family;
                    notifModel.Body           = Truncate(comment, 28);
                    notifModel.Tab            = (int)MainTabs.Message;
                    notifModel.RequestCode    = (int)NotificationType.NewMessage;
                    notifModel.NotificationId = (int)NotificationType.NewMessage;

                    DoStuff(notifModel, contact.ContactId, 1, userId);

                    /*foreach (var vwRouteGroup in otherUsers)
                     * {
                     *
                     * }*/
                    dataModel.SaveChanges();
                }
                else
                {
                    _responseProvider.SetBusinessMessage(new MessageResponse()
                    {
                        Type = ResponseTypes.Warning, Message = getResource.getMessage("UnknownGroup")
                    });
                    return(string.Empty);
                }
            }
            return(string.Empty);
        }
コード例 #9
0
 public void PayMoney(int sourceUserId, int destinationUserId, int value)
 {
     using (var dataModel = new MibarimEntities())
     {
         using (var dbContextTransaction = dataModel.Database.BeginTransaction())
         {
             try
             {
                 var sourceUserInfo = dataModel.vwUserInfoes.FirstOrDefault(x => x.UserId == sourceUserId);
                 var desUserInfo    = dataModel.vwUserInfoes.FirstOrDefault(x => x.UserId == destinationUserId);
                 var desc           = string.Format(getResource.getMessage("PayMoneyDesc"), value, GetUserNameFamilyString(sourceUserInfo), GetUserNameFamilyString(desUserInfo));
                 var trans          = new Tran();
                 trans.TransCreateTime  = DateTime.Now;
                 trans.TransType        = (int)TransactionType.PayMoney;
                 trans.TransUserId      = sourceUserId;
                 trans.TransValue       = (-1) * value;
                 trans.TransDescription = desc;
                 dataModel.Trans.Add(trans);
                 dataModel.SaveChanges();
                 var recTrans = new Tran();
                 recTrans.TransCreateTime = DateTime.Now;
                 recTrans.TransType       = (int)TransactionType.ReceivePay;
                 recTrans.TransUserId     = destinationUserId;
                 //ServiceWage.Fee = value;
                 recTrans.TransValue       = value;//- ServiceWage.Wage;
                 recTrans.TransDescription = desc;
                 recTrans.TransPair        = trans.TransId;
                 dataModel.Trans.Add(recTrans);
                 dataModel.SaveChanges();
                 dbContextTransaction.Commit();
                 NotifModel notifModel = new NotifModel();
                 notifModel.Title          = getResource.getString("Transaction");
                 notifModel.Body           = desc;
                 notifModel.Tab            = (int)MainTabs.Profile;
                 notifModel.RequestCode    = (int)NotificationType.MoneyTransaction;
                 notifModel.NotificationId = (int)NotificationType.MoneyTransaction;
                 _notifManager.SendNotifToUser(notifModel, sourceUserId);
                 _notifManager.SendNotifToUser(notifModel, destinationUserId);
             }
             catch (Exception)
             {
                 dbContextTransaction.Rollback();
             }
         }
     }
 }
コード例 #10
0
        public List <NotifModel> GetUserNotification(int userId, NotificationType notificationType)
        {
            var res = new List <NotifModel>();

            using (var dataModel = new MibarimEntities())
            {
                var now    = DateTime.Now;
                var notifs =
                    dataModel.Notifications.Where(x => x.NotifUserId == userId && x.NotifExpireTime > now && !x.IsNotificationSent && x.NotifType == (short)notificationType);
                foreach (var notification in notifs)
                {
                    var notifModel = new NotifModel();
                    notifModel.Body                 = notification.NotifBody;
                    notifModel.Title                = notification.NotifTitle;
                    notifModel.NotificationId       = notification.NotificationId;
                    notification.IsNotificationSent = true;
                    res.Add(notifModel);
                }
                dataModel.SaveChanges();
            }
            return(res);
        }