Beispiel #1
0
        /// <summary>
        /// Updates the credit balance.
        /// </summary>
        private void UpdateCreditBalance()
        {
            try
            {
                using (MySqlContext dbContext = new MySqlContext())
                {
                    IRepository<vtiger_contactdetails> tmp = new Repository<vtiger_contactdetails>(dbContext);
                    var lst = tmp.SqlQuery<SendUpdateCreditBalanceMessageDto>("CALL SendUpdateCreditBalanceMsgAndNotification();").ToList();

                    foreach (var item in lst)
                    {
                        string orgId = string.Empty;
                        string crmUserId;

                        crmUserId = AppSettings.Get<string>(ConfigConstants.OrganisationId) + item.OrgId;
                        var user = this.userService.GetContactByCrmId(crmUserId);
                        if (user != null && !string.IsNullOrWhiteSpace(user.UserName))
                        {
                            orgId = user.Id;
                        }

                        ////Update Organisation's credit balance
                        OrganisationModel org = this.crmManagerService.GetOrganisation(orgId);
                        org.CreditBalance += item.CreditBalance;
                        this.crmManagerService.UpdateOrganisation(orgId, org);

                        string currency = org.BillCountry.ToLower() == "india" ? "₹" : "$";
                        string amount = currency + item.CreditBalance.ToString("#");

                        ////Send email to the organisation
                        this.authRepository.SendCreditBalanceEmail(orgId, org.AccountName, amount);

                        ////Send message and notification to organisation
                        MessagesDto message = new MessagesDto();
                        message.ModifiedBy = message.FromUser = message.CreatedBy = "YoufferAdmin";
                        message.IsDeleted = false;
                        message.CompanyId = AppSettings.Get<string>(ConfigConstants.SuperUserId);
                        message.UserId = message.ToUser = orgId;
                        message.Name = "Youffer Admin";
                        message.MediaId = 0;

                        MessageTemplatesDto msgTemplate = this.commonService.GetMessageTemplate(MessageTemplateType.UpdateCreditBalanceMsg);
                        msgTemplate.TemplateText = msgTemplate.TemplateText.Replace("{{Amount}}", amount);
                        message.Message = msgTemplate.TemplateText;
                        message = this.youfferMessageService.CreateMessage(message);

                        ////Notifications
                        SignalRHub hub = new SignalRHub();
                        UserBalanceModelDto balance = new UserBalanceModelDto { CashBalance = org.CashBalance, CreditBalance = org.CreditBalance };
                        hub.SendMessage(message.UserId, message);
                        hub.SendCreditUpdateMessage(message.UserId, balance);

                        string gcmId = item.GCMId;
                        string udId = item.UDId;

                        if (!string.IsNullOrEmpty(gcmId))
                        {
                            this.pushMessageService.SendMessageNotificationToAndroid(gcmId, message.Id.ToString(), message.Message, "Youffer", Notification.usermsg.ToString());
                            this.pushMessageService.SendCreditNotificationToAndroid(gcmId, message.Id.ToString(), amount, "Youffer", Notification.updatecreditbal.ToString());
                        }

                        if (!string.IsNullOrEmpty(udId))
                        {
                            int unreadMsgCount = this.youfferMessageService.GetUnreadMsgCount(message.UserId, false);
                            this.pushMessageService.SendMessageNotificationToiOS(udId, message.Id.ToString(), message.Message, "Youffer", unreadMsgCount, Notification.usermsg.ToString());
                            this.pushMessageService.SendCreditNotificationToiOS(udId, message.Id.ToString(), amount, "Youffer", unreadMsgCount, Notification.updatecreditbal.ToString());
                        }

                        var res = tmp.SqlQuery<int>("CALL UpdateCreditBalanceStatus({0});", item.Id).ToList();
                    }
                }
            }
            catch (Exception ex)
            {
                this.loggerservice.LogException("UpdateCreditBalance:- " + ex.Message);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Sends the credit update message.
 /// </summary>
 /// <param name="clientId">The client identifier.</param>
 /// <param name="balance">The balance.</param>
 public void SendCreditUpdateMessage(string clientId, UserBalanceModelDto balance)
 {
     var context = GlobalHost.ConnectionManager.GetHubContext<SignalRHub>();
     context.Clients.Group(clientId).addCreditUpdateMessage(balance);
 }