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);
        }
Beispiel #2
0
        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            var results = new List<ValidationResult>();
            var Distinct = new List<Guid>();

            Distinct.AddRange(this.BoardMembers.Where(b => b != Guid.Empty));
            Distinct.AddRange(this.Alternate.Where(b => b != Guid.Empty));
            Distinct.Add(Chairmann);
            Distinct.Add(Accountant);
            if (Auditor != Guid.Empty) Distinct.Add(Auditor);
            if (AuditorAlternate != Guid.Empty) Distinct.Add(AuditorAlternate);

            int BoardMembers = this.BoardMembers == null ? 0 : this.BoardMembers.Where(g => g != Guid.Empty).Count();
            int BoardAlternate = this.Alternate == null ? 0 : this.Alternate.Where(g => g != Guid.Empty).Count();

            if (Chairmann == Guid.Empty) results.Add(new ValidationResult(General.BoardCharimannMissing));
            if (Accountant == Guid.Empty) results.Add(new ValidationResult(General.BoardAccountantMissing));
            //if (Auditor == Guid.Empty) results.Add(new ValidationResult(General.BoardAuditorMissing));
            
            if (BoardMembers < minMember)
            {
                results.Add(new ValidationResult(string.Format(General.BoardMemeberMin, minMember)));
            }
            if (BoardMembers > maxMember)
            {
                results.Add(new ValidationResult(string.Format(General.BoardMemeberMax, maxMember)));
            }
            if (BoardAlternate < minAlternate)
            {
                results.Add(new ValidationResult(string.Format(General.BoardAlternateMin, minAlternate)));
            }
            if (BoardAlternate > maxAlternate)
            {
               results.Add(new ValidationResult(string.Format(General.BoardAlternateMax, maxAlternate)));
            }
            if (ConfigurationManager.AppSettings["BoardEvenOdd"].ToLower() == "odd" & BoardMembers % 2 == 0)
            {
                results.Add(new ValidationResult(General.BoardOdd));
            }
            if (ConfigurationManager.AppSettings["BoardEvenOdd"].ToLower() == "even" & BoardMembers % 2 != 0)
            {
                results.Add(new ValidationResult(General.BoardEven));
            }
            if (Distinct.Count() != Distinct.Distinct().Count())
            {
                results.Add(new ValidationResult(General.BoardSamePerson));
            }


            return results;
        }