Пример #1
0
        public static bool CreateNewMessageForGroup(ConversationModel con)
        {
            try
            {
                string conversationLink = ServerConfig.VIEW_MESSAGE_CONVERSATION;
                var dc = new ManagementContext();
                DataModels.Messages.Message m = new DataModels.Messages.Message();
                m.FromUser = dc.Members.Where(x => x.MemberId == con.MemberId).FirstOrDefault();
                m.MessageText = con.Message;
                dc.Message.Add(m);
                dc.SaveChanges();

                string ownerName = String.Empty;
                string messageId = String.Empty;

                if (m.FromUser != null)
                    ownerName = m.FromUser.DerbyName;

                DataModels.Messages.GroupMessage group = new DataModels.Messages.GroupMessage();
                group.Messages.Add(m);
                group.TitleOfMessage = con.Title;
                group.GroupOwnerId = con.FromId;
                group.LastModified = DateTime.UtcNow;
                var fed = dc.Federations.Where(x => x.FederationId == con.FromId).FirstOrDefault();
                if (fed != null)
                    ownerName = fed.Name;
                else
                {
                    var leag = dc.Leagues.Where(x => x.LeagueId == con.FromId).FirstOrDefault();
                    if (leag != null)
                        ownerName = leag.Name;
                }
                dc.GroupMessages.Add(group);
                dc.SaveChanges();
                messageId = group.GroupId.ToString();
                var tempGroups = MemberCache.GetLeagueGroupsOfMember(con.FromId);
                //add all members of the groups
                foreach (var g in con.GroupIds)
                {
                    var tempG = tempGroups.Where(x => x.Id == g).FirstOrDefault();
                    if (tempG != null)
                    {
                        foreach (var mTemp in tempG.GroupMembers)
                        {
                            if (con.Recipients.Where(x => x.MemberId == mTemp.MemberId).FirstOrDefault() == null)
                                con.Recipients.Add(new MemberDisplayMessage() { MemberId = mTemp.MemberId });
                        }
                    }
                }
                foreach (var mem in con.Recipients)
                {
                    try
                    {
                        DataModels.Messages.MessageInbox inbox = new DataModels.Messages.MessageInbox();
                        inbox.Message = m;
                        inbox.ToUser = dc.Members.Where(x => x.MemberId == mem.MemberId).FirstOrDefault();
                        inbox.MessageReadDateTime = DateTime.UtcNow;
                        inbox.NotifiedEmailDateTime = DateTime.UtcNow;
                        if (inbox.ToUser.MemberId == m.FromUser.MemberId)
                            inbox.IsRead = true;
                        else
                            MemberCache.AddMessageCountToCache(+1, mem.MemberId);

                        DataModels.Messages.MessageRecipient recipient = new DataModels.Messages.MessageRecipient();
                        recipient.Group = group;
                        recipient.Recipient = inbox.ToUser;
                        group.Recipients.Add(recipient);

                        if (con.SendEmailForMessage && inbox.ToUser.AspNetUserId != new Guid())
                        {

                            var emailData = new Dictionary<string, string>
                                        {
                                            { "derbyname", inbox.ToUser.DerbyName }, 
                                            { "FromUserName", ownerName }, 
                                            { "messageBody", HtmlSanitize.ReplaceCarriageReturnsWithBreaks( m.MessageText )},
                                            { "viewConversationLink", conversationLink +  messageId}
                                        };

                            var user = System.Web.Security.Membership.GetUser((object)inbox.ToUser.AspNetUserId);
                            if (user != null)
                            {
                                inbox.UserNotifiedViaEmail = true;
                                EmailServer.EmailServer.SendEmail(ServerConfig.DEFAULT_EMAIL_MESSAGES, ServerConfig.DEFAULT_EMAIL_FROM_NAME, user.UserName, EmailServer.EmailServer.DEFAULT_SUBJECT + " New Message From " + ownerName, emailData, EmailServer.EmailServerLayoutsEnum.SendMessageToUserFromOtherUser);
                            }

                        }
                        dc.MessageInbox.Add(inbox);
                    }
                    catch (Exception exception)
                    {
                        ErrorDatabaseManager.AddException(exception, exception.GetType());
                    }
                }

                int c = dc.SaveChanges();

                MobileNotificationFactory fact = new MobileNotificationFactory();
                fact.Initialize("New Message", m.MessageText, Mobile.Enums.NotificationTypeEnum.Message)
                    .AddId(group.GroupId)
                    .AddMembers(con.Recipients.Select(x => x.MemberId).ToList())
                    .SendNotifications();

                return c > 0;
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return false;
        }
Пример #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="invoice"></param>
        /// <param name="reportInformation"></param>
        /// <param name="customerId"></param>
        /// <returns></returns>
        public static bool HandleDuesPayments(DisplayInvoice invoice, string reportInformation, string customerId = null)
        {
            try
            {
                var duesItem = invoice.DuesItems.FirstOrDefault();
                bool success = Dues.DuesFactory.PayDuesAmount(duesItem.DuesItemId, duesItem.DuesId, (double)duesItem.BasePrice, duesItem.MemberPaidId, "Paid Via Paypal, Invoice:" + invoice.InvoiceId.ToString().Replace("-", ""));
                PaymentGateway pg = new PaymentGateway();
                pg.SetInvoiceStatus(invoice.InvoiceId, InvoiceStatus.Payment_Successful, customerId);
                if (success)
                {
                    //email people.
                    WebClient client = new WebClient();
                    WebClient client1 = new WebClient();
                    client.DownloadStringAsync(new Uri(ServerConfig.URL_TO_CLEAR_MEMBER_CACHE + duesItem.MemberPaidId));
                    client1.DownloadStringAsync(new Uri(ServerConfig.URL_TO_CLEAR_MEMBER_CACHE_API + duesItem.MemberPaidId));

                    EmailServer.EmailServer.SendEmail(ServerConfig.DEFAULT_EMAIL, ServerConfig.DEFAULT_EMAIL_FROM_NAME, ServerConfig.DEFAULT_ADMIN_EMAIL_ADMIN, "Dues Payment Made", reportInformation);
                    var member = MemberCache.GetMemberDisplay(duesItem.MemberPaidId);
                    var league = MemberCache.GetLeagueOfMember(duesItem.MemberPaidId);
                    var settings = Dues.DuesFactory.GetDuesSettings(duesItem.DuesId);
                    if (settings != null && member != null)
                    {
                        var emailData = new Dictionary<string, string>
                                        {
                                            { "memberName",  member.DerbyName },
                                            { "leagueName", settings.LeagueOwnerName   },
                                            { "invoiceId", invoice.InvoiceId.ToString().Replace("-","")},
                                            { "amountPaid", duesItem.PriceAfterFees.ToString("N2") },
                                            { "baseAmountPaid",duesItem.BasePrice.ToString("N2")  },
                                            { "monthOfDuesPayment",duesItem.PaidForDate.ToShortDateString()},
                                            { "emailForPaypal", settings.PayPalEmailAddress},
                                            { "statusOfPayment",RDN.Portable.Util.Enums.EnumExt.ToFreindlyName( InvoiceStatus.Pending_Payment_From_Paypal)}
                                          };

                        //sends email to user for their payment.
                        if (!String.IsNullOrEmpty(member.UserName))
                            EmailServer.EmailServer.SendEmail(ServerConfig.DEFAULT_EMAIL, ServerConfig.DEFAULT_EMAIL_FROM_NAME, member.UserName, EmailServer.EmailServer.DEFAULT_SUBJECT + " Dues Payment Receipt", emailData, EmailServer.EmailServerLayoutsEnum.DuesPaymentMadeForUser);
                        else if (!String.IsNullOrEmpty(member.Email))
                            EmailServer.EmailServer.SendEmail(ServerConfig.DEFAULT_EMAIL, ServerConfig.DEFAULT_EMAIL_FROM_NAME, member.Email, EmailServer.EmailServer.DEFAULT_SUBJECT + " Dues Payment Receipt", emailData, EmailServer.EmailServerLayoutsEnum.DuesPaymentMadeForUser);

                        if (league != null && !String.IsNullOrEmpty(league.Email))
                        {
                            //sends email to league for notification of their payment.
                            EmailServer.EmailServer.SendEmail(ServerConfig.DEFAULT_EMAIL, ServerConfig.DEFAULT_EMAIL_FROM_NAME, league.Email, EmailServer.EmailServer.DEFAULT_SUBJECT + " Dues Payment Made", emailData, EmailServer.EmailServerLayoutsEnum.DuesPaymentMadeForLeague);
                        }

                        MobileNotificationFactory mnf = new MobileNotificationFactory();
                        mnf.Initialize("Dues Payment Made", "Receipt For Payment", NotificationTypeEnum.DuesPaymentReceipt)
                            .AddId(invoice.InvoiceId)
                            .AddMember(duesItem.MemberPaidId)
                            .SendNotifications();
                    }
                    else
                    {
                        throw new Exception("Settings or Member was null.  Can't send Receipts." + invoice.InvoiceId);
                    }
                }
                else
                {
                    EmailServer.EmailServer.SendEmail(ServerConfig.DEFAULT_EMAIL, ServerConfig.DEFAULT_EMAIL_FROM_NAME, ServerConfig.DEFAULT_ADMIN_EMAIL_ADMIN, "Paypal: Dues Updates Were not successful", reportInformation);
                }
                return true;
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType(), additionalInformation: reportInformation);
            }
            return false;
        }