예제 #1
0
        public ActionResult NewMessage(MessageListModel MessageContext)
        {
            List<NR.Models.NRMembership> Active = new List<NR.Models.NRMembership>();
            if (MessageContext.NewMessageTo == null || !MessageContext.NewMessageTo.Any())
            {
                ModelState.AddModelError("NewMessageTo", General.ErrorNoRecipients);

            }

            if (MessageContext.Short)
            {
                if (String.IsNullOrWhiteSpace(MessageContext.BodyShort)) ModelState.AddModelError("BodyShort", General.ErrorNoBody);
            }
            else
            {
                if (String.IsNullOrWhiteSpace(MessageContext.Head) & String.IsNullOrWhiteSpace(MessageContext.Body)) ModelState.AddModelError("", General.ErrorNoHeadOrBody);
            }

            if (ModelState.IsValid)
            {
                //An entity object cannot be referenced by multiple instances of IEntityChangeTracker

                Message Msg = new Message
                {
                    Recivers = new List<MessageReciver>(),
                    SenderID = CurrentProfile.PersonID
                };

                List<Guid> Recivers = new List<Guid>();

                Active = reposetory.GetAssociationActivePersons(CurrentProfile.AssociationID);



                foreach (Guid PersonID in MessageContext.NewMessageTo)
                {
                    if (PersonID == MistConversations.Int2Guid(0))
                    {
                        Recivers = Active.Select(m => m.Person.PersonID).ToList();
                    }
                    else if (PersonID == MistConversations.Int2Guid(1))
                    {
                        Recivers.AddRange(reposetory.GetAssociationTeamLeadersPersons(CurrentProfile.AssociationID).Select(m => m.PersonID).ToList());
                    }
                    else if (PersonID == MistConversations.Int2Guid(2))
                    {
                        Recivers.AddRange(reposetory.GetAssociationBoardPersons(CurrentProfile.AssociationID).Select(m => m.PersonID).ToList());
                    }
                    else if (PersonID == MistConversations.Int2Guid(3))
                    {
                        Recivers.AddRange(reposetory.GetAssociationActivePersons(CurrentProfile.AssociationID, Gender.Woman).Select(m => m.PersonID).ToList());
                    }
                    else if (PersonID == MistConversations.Int2Guid(4))
                    {
                        Recivers.AddRange(reposetory.GetAssociationActivePersons(CurrentProfile.AssociationID, Gender.Man).Select(m => m.PersonID).ToList());
                    }
                    else
                    {
                        Recivers.Add(PersonID);
                    }
                }

                //Recivers = Recivers.Distinct().ToList();

                Msg.Recivers = Recivers.Distinct().Select(Id => new MessageReciver { ReciverID = Id }).ToList();
                //.Add(
                //   new MessageReciver
                //   {
                //       ReciverID = Active.Where(p => p.PersonID == PersonID).FirstOrDefault().PersonID
                //   }
                //   );
                if (MessageContext.Short)
                {
                    Msg.Body = MessageContext.BodyShort;
                    Msg.Type = MessageType.shortMessage;
                }
                else
                {
                    Msg.Head = MessageContext.Head;
                    Msg.Body = MessageContext.Body;
                    Msg.Type = MessageType.LongMessage;
                }
                reposetory.MessageSend(Msg);
                ViewBag.FormSucces = true;

            }


            List<SelectListItem> AssItems = reposetory.GetAssociationActivePersons(CurrentProfile.AssociationID).Select(d => new SelectListItem { Value = d.Person.PersonID.ToString(), Text = d.Person.FullName }).ToList();
            AssItems.Insert(0, new SelectListItem { Text = General.GenderMale, Value = MistConversations.Int2Guid(4).ToString() });
            AssItems.Insert(0, new SelectListItem { Text = General.GenderFemale, Value = MistConversations.Int2Guid(3).ToString() });
            AssItems.Insert(0, new SelectListItem { Text = General.Board, Value = MistConversations.Int2Guid(2).ToString() });
            AssItems.Insert(0, new SelectListItem { Text = General.Teamleaders, Value = MistConversations.Int2Guid(1).ToString() });
            AssItems.Insert(0, new SelectListItem { Text = General.All, Value = MistConversations.Int2Guid(0).ToString() });

            MessageContext.List = AssItems;

            return View(MessageContext);
        }
예제 #2
0
        public ActionResult Communicate(MessageFolderModel MessageContext)
        {
            List<NR.Models.NRMembership> Active = new List<NR.Models.NRMembership>();
            if (MessageContext.NewMessageTo == null || !MessageContext.NewMessageTo.Any())
            {
                ModelState.AddModelError("NewMessageTo", General.ErrorNoRecipients);

            }

            if (MessageContext.Short)
            {
                if (String.IsNullOrWhiteSpace(MessageContext.BodyShort)) ModelState.AddModelError("BodyShort", General.ErrorNoBody);
            }
            else
            {
                if (String.IsNullOrWhiteSpace(MessageContext.Head) & String.IsNullOrWhiteSpace(MessageContext.Body)) ModelState.AddModelError("", General.ErrorNoHeadOrBody);
            }

            if (ModelState.ContainsKey("Folder.FoldereName"))
                ModelState["Folder.FoldereName"].Errors.Clear();

            MessageContext.Folder = reposetory.GetFolder(MessageContext.Folder.FolderID);
            MessageContext.LinkActive = MessageContext.Folder.Status != FolderStatus.Input;

            if (ModelState.IsValid)
            {

                List<Guid> Recivers = new List<Guid>();

                Active = reposetory.GetAssociationActivePersons(CurrentProfile.AssociationID);
                Person Sender = reposetory.GetPerson(CurrentProfile.PersonID);


                foreach (Guid PersonID in MessageContext.NewMessageTo)
                {
                    if (PersonID == MistConversations.Int2Guid(0))
                    {
                        Recivers = Active.Select(m => m.Person.PersonID).ToList();
                    }
                    else if (PersonID == MistConversations.Int2Guid(1))
                    {
                        Recivers.AddRange(reposetory.GetAssociationTeamLeadersPersons(CurrentProfile.AssociationID).Select(m => m.PersonID).ToList());
                    }
                    else if (PersonID == MistConversations.Int2Guid(2))
                    {
                        Recivers.AddRange(reposetory.GetAssociationPersonsNoFeedback(CurrentProfile.AssociationID, MessageContext.Folder.FolderID).Select(m => m.PersonID).ToList());
                    }
                    else
                    {
                        Recivers.Add(PersonID);
                    }
                }

                foreach (Guid PID in Recivers)
                {
                    Person P = reposetory.GetPerson(PID);
                    if (!string.IsNullOrWhiteSpace(P.Email))
                    {
                        FeedbackFolder email = new FeedbackFolder();
                        //// set up the email ...
                        email.To = P.Email;
                        email.ReplyTo = CurrentProfile.Email;
                        email.folder = MessageContext.Folder;
                        email.Person = P;
                        email.message = MessageContext.Body;
                        email.Link = MessageContext.Link;
                        try
                        {
                            email.Send();
                        }
                        catch (Exception e)
                        {
                            LogFile.Write(e, "Email:" + P.Email);
                        }
                    }
                    if (MessageContext.Short)
                    {
#if DUMMYTEXT
                        ITextMessage SMSGateway = TextServiceProviderFactory.GetTextServiceProviderrInstance("NR.Infrastructure.DummyTextGateway", CurrentProfile.TextServiceProviderUserName, CurrentProfile.TextServiceProviderPassword);
#else
                        ITextMessage SMSGateway = TextServiceProviderFactory.GetTextServiceProviderrInstance(CurrentProfile.TextServiceProvider, CurrentProfile.TextServiceProviderUserName, CurrentProfile.TextServiceProviderPassword);
#endif

                        if (CurrentProfile.PersonID == Guid.Empty)
                        {
                            SMSGateway.FromText = General.SystemTextMessagesFrom;
                        }
                        else
                        {
                            SMSGateway.From = Sender;
                        }
                        
                        //SMSGateway.FromText = CurrentProfile.PersonID == Guid.Empty ? General.SystemTextMessagesFrom : string.IsNullOrWhiteSpace(CurrentProfile.Mobile) ? General.SystemTextMessagesFrom : CurrentProfile.Mobile;
                        SMSGateway.Message = MessageContext.BodyShort.ReplaceTagPerson(P);

                        //if (MessageContext.Link) SMSGateway.Message += "\r\n" + string.Format(General.FeedbackTextLink, Url.Action("FeedBack", "Planning", new { P = PID, F = MessageContext.Folder.FolderID }, "http"));
                        SMSGateway.Recipient = new List<Person> { P };
                        if (DateTime.Now.AddMinutes(1).Hour < 11) SMSGateway.DeliveryTime = DateTime.Now.AddMinutes(1).Date.AddHours(11);
                        reposetory.NewTextMessage(SMSGateway, CurrentProfile.AssociationID);

                        SMSGateway.HandShakeUrl = Url.Action("TextXStatus", "Account", new { ID = SMSGateway.TextId }, "http");

                        if (SMSGateway.Send())
                        {

                        };
                    }

                }

                ViewBag.FormSucces = true;

            }


            List<SelectListItem> AssItems = reposetory.GetAssociationActivePersons(CurrentProfile.AssociationID).Select(d => new SelectListItem { Value = d.Person.PersonID.ToString(), Text = d.Person.FullName }).ToList();
            AssItems.Insert(0, new SelectListItem { Text = General.MissingFeedback, Value = MistConversations.Int2Guid(2).ToString() });
            AssItems.Insert(0, new SelectListItem { Text = General.Teamleaders, Value = MistConversations.Int2Guid(1).ToString() });
            AssItems.Insert(0, new SelectListItem { Text = General.All, Value = MistConversations.Int2Guid(0).ToString() });

            MessageContext.List = AssItems;

            return View(MessageContext);
        }