Esempio n. 1
0
        public async Task<IHttpActionResult> CreateMessage(MessagesDto message)
        {
            message.ModifiedBy = message.FromUser = message.CreatedBy = User.Identity.GetUserId();
            message.IsDeleted = false;
            message.IsReadByUser = true;
            message.CompanyId = message.ToUser;
            message.UserId = message.FromUser;

            message = this.youfferMessageService.CreateMessage(message);
            int unreadMsgCount = this.youfferMessageService.GetUnreadMsgCount(message.UserId, false);

            ContactModel fromUser = this.crmManagerService.GetContact(message.FromUser);
            OrganisationModel orgModel = this.crmManagerService.GetOrganisation(message.ToUser);

            if (!string.IsNullOrEmpty(orgModel.GCMId))
            {
                this.pushMessageService.SendMessageNotificationToAndroid(orgModel.GCMId, message.Id.ToString(), message.Message, fromUser.FirstName, Notification.usermsg.ToString());
            }

            if (!string.IsNullOrEmpty(orgModel.UDId))
            {
                this.pushMessageService.SendMessageNotificationToiOS(orgModel.UDId, message.Id.ToString(), message.Message, fromUser.FirstName, unreadMsgCount, Notification.usermsg.ToString());
            }

            SignalRHub hub = new SignalRHub();
            hub.SendMessage(message.CompanyId, message);

            return this.Ok(message);
        }
Esempio n. 2
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);
            }
        }