Ejemplo n.º 1
0
        public ActionResult _TestText(string Mobile)
        {
            if (!string.IsNullOrWhiteSpace(Mobile))
            {
                Person person = new Person
                {
                    Mobile  = Mobile,
                    Country = Country.DK
                };

                ITextMessage SMSGateway = TextServiceProviderFactory.GetTextServiceProviderrInstance(null, null, null);
                SMSGateway.FromText  = General.SystemTextMessagesFrom;
                SMSGateway.Message   = "Test text";
                SMSGateway.Recipient = new List <Person> {
                    person
                };
                //reposetory.NewTextMessage(SMSGateway, association.AssociationID);

                //if (HandshakeUrl != null && HandshakeUrl.Contains("##")) SMSGateway.HandShakeUrl = HandshakeUrl.Replace("##", SMSGateway.TextId);

                try
                {
                    if (SMSGateway.Send())
                    {
                    }
                    ;
                }
                catch (Exception ex)
                {
                    return(Content(ex.ToString()));
                }
            }
            return(new HttpStatusCodeResult(HttpStatusCode.NoContent));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Send tem notifications and team notes
        /// </summary>
        public void SendTeamTexts()
        {
            //DateTime LookAhead = DateTime.Now.AddDays(7);  //Time to look ahead for teams reminder normal reminder is sent 2 days before so plenty of room
            //DateTime Deadline = DateTime.Now.AddHours(1); //If reminde is no sent 6 hours before no need to go head
            //List<Team> TeamsTest = reposetory.Teams.ToList();

            List <Team> Teams = reposetory.TeamsToProcess(DateTime.Now.AddDays(7), DateTime.Now.AddHours(1));

            LogFile.Write("Process : Teams Selected (" + Teams.Count() + ")");

            foreach (Team team in Teams)
            {
                string result = "Process : TeamID(" + team.TeamID + ")";
                //LogFile.Write("Process: (TeamID = " + team.TeamID + ", Team OK = " + team.OK + ",ReminderTextSend = " + team.ReminderTextSent + ")");
                if (team.Association == null)
                {
                    continue;
                }
                Association association = team.Association;

                //Team notification
                if (association.SendTeamText && team.OK && !team.ReminderTextSent && !(string.IsNullOrWhiteSpace(association.TeamMessageTeamLeader) & string.IsNullOrWhiteSpace(association.TeamMessage)))
                {
                    DateTime ReminderTextSendDeadline = DateTime.Now.Date.AddDays(association.SendTeamTextDays);
                    DateTime CountStart = team.Start.Hour < 5 ? team.Start.Date.AddDays(-1) : team.Start.Date;

                    //LogFile.Write("Process: OK to send (" + team.TeamID + ") - ( CountStart = " + CountStart.ToString() + ", ReminderTextSendDeadline = " + ReminderTextSendDeadline.ToString() + ", team.start = " + team.Start.AddMinutes(-10).ToString() + " / " + DateTime.Now.ToString() + ")");
                    result += "*Team notification-";
                    result += "CountStart/ReminderTextSendDeadline/team.start(" + CountStart.ToString() + "/" + ReminderTextSendDeadline.ToString() + "/" + team.Start.AddMinutes(-10).ToString() + ")";
                    if (CountStart <= ReminderTextSendDeadline && team.Start.AddMinutes(-10) >= DateTime.Now)
                    {
                        //LogFile.Write("Process: OK to Time " + team.TeamID + ")");
                        result += ">>READY<<";



                        foreach (Person P in team.Teammembers)
                        {
                            if (String.IsNullOrWhiteSpace(P.Mobile))
                            {
                                result += "/**NO MOBILE**";
                                continue;
                            }
                            result += "/" + P.Mobile;
#if DUMMYTEXT
                            ITextMessage SMSGateway = TextServiceProviderFactory.GetTextServiceProviderrInstance("NR.Infrastructure.DummyTextGateway", association.TextServiceProviderUserName, association.TextServiceProviderPassword);
#else
                            ITextMessage SMSGateway = TextServiceProviderFactory.GetTextServiceProviderrInstance(association.TextServiceProvider, association.TextServiceProviderUserName, association.TextServiceProviderPassword);
#endif
                            string Message;
                            if (team.TeamLeaderId == P.PersonID)
                            {
                                Message             = association.TeamMessageTeamLeader;
                                SMSGateway.FromText = General.SystemTextMessagesFrom;
                            }
                            else
                            {
                                Message = association.TeamMessage;
                                if (string.IsNullOrWhiteSpace(team.Teamleader.Mobile))
                                {
                                    SMSGateway.FromText = General.SystemTextMessagesFrom;
                                }
                                else
                                {
                                    SMSGateway.From = team.Teamleader;
                                }
                            }

                            if (team.Trial)
                            {
                                Message += "\n\r\n\r-----------\n\r\n\r" + DomainStrings.Trial;
                                if (!string.IsNullOrWhiteSpace(team.TrialInfo))
                                {
                                    Message += ": " + team.TrialInfo;
                                }
                            }


                            //SMSGateway.FromText = General.SystemTextMessagesFrom;
                            SMSGateway.Message   = Message.ReplaceTagTeamMembers(team, P).ReplaceTagTeamStart(team).ReplaceTagPerson(P);
                            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, association.AssociationID);

                            if (HandshakeUrl != null && HandshakeUrl.Contains("##"))
                            {
                                SMSGateway.HandShakeUrl = HandshakeUrl.Replace("##", SMSGateway.TextId);
                            }

                            if (SMSGateway.Send())
                            {
                                //team.ReminderTextSent = true;
                                //reposetory.SaveTeam(team);
                                reposetory.TeamReminderTextSent(team.TeamID);
                            }
                            ;
                        }
                    }
                    else
                    {
                        result += ">>NO<<";
                    }
                    LogFile.Write(result);
                }
                else
                {
                    result += "*Team notification-NO-";
                    if (!association.SendTeamText)
                    {
                        result += ", SendTeamText(" + association.SendTeamText + ")";
                    }
                    if (!team.OK)
                    {
                        result += ", TeamOK(" + team.OK + ")";
                    }
                    if (team.ReminderTextSent)
                    {
                        result += ", ReminderTextSent(" + team.ReminderTextSent + ")";
                    }
                    if (string.IsNullOrWhiteSpace(association.TeamMessageTeamLeader))
                    {
                        result += "TeamMessageTeamLeader(" + string.IsNullOrWhiteSpace(association.TeamMessageTeamLeader) + ")";
                    }
                    if (string.IsNullOrWhiteSpace(association.TeamMessage))
                    {
                        result += "TeamMessageTeamLeader(" + string.IsNullOrWhiteSpace(association.TeamMessage) + ")";
                    }
                    //LogFile.Write(result);
                }


                //Teamnotes
                result += "\r\n*Teamnotes-(" + (association.SendNoteTeamleader && team.OK && team.TeamLeaderId != Guid.Empty && !team.NoteTextSent &&
                                                (!string.IsNullOrWhiteSpace(team.Note) | (association.UseKeyBox && !string.IsNullOrWhiteSpace(association.KeyBoxcode)) | team.Trial)) + ")";


                if (association.SendNoteTeamleader && team.OK && team.TeamLeaderId != Guid.Empty && !team.NoteTextSent &&
                    (!string.IsNullOrWhiteSpace(team.Note) | (association.UseKeyBox && !string.IsNullOrWhiteSpace(association.KeyBoxcode)) | team.Trial))
                {
                    DateTime ReminderTextSendDeadline = DateTime.Now.Date.AddDays(12);
                    DateTime CountStart = team.Start.Hour < 5 ? team.Start.Date.AddDays(-1) : team.Start.Date;
                    result += "*Teamnotes-";
                    result += "team.Start.AddHours(-8)/team.Start.AddMinutes(-10)/team.start(" + team.Start.AddHours(-8) + "/" + team.Start.AddMinutes(+10) + "/" + team.Start.AddMinutes(+10).ToString() + ")";

                    if (team.Start.AddHours(-8) <= DateTime.Now && team.Start.AddMinutes(-30) >= DateTime.Now)
                    {
                        Person TeamLeader = team.Teammembers.Where(x => x.PersonID == team.TeamLeaderId).FirstOrDefault();
                        if (TeamLeader != null)
                        {
#if DUMMYTEXT
                            ITextMessage SMSGateway = TextServiceProviderFactory.GetTextServiceProviderrInstance("NR.Infrastructure.DummyTextGateway", association.TextServiceProviderUserName, association.TextServiceProviderPassword);
#else
                            ITextMessage SMSGateway = TextServiceProviderFactory.GetTextServiceProviderrInstance(association.TextServiceProvider, association.TextServiceProviderUserName, association.TextServiceProviderPassword);
#endif
                            string Message = "";
                            string KeyboxMessage;

                            if (association.SendNoteTeamleader & !string.IsNullOrWhiteSpace(team.Note))
                            {
                                Message = General.SystemTextMessagesTeamNote.ReplaceTagTeamStart(team).ReplaceTagPerson(TeamLeader) + "\n\r" + team.Note;
                            }
                            if (association.UseKeyBox & !string.IsNullOrWhiteSpace(association.KeyBoxcode))
                            {
                                KeyboxMessage = @General.KeyBoxHeadline + " " + association.KeyBoxcode;
                                Message      += (string.IsNullOrWhiteSpace(Message) ? KeyboxMessage : "\n\r\n\r----\n\r\n\r" + KeyboxMessage);
                            }
                            if (team.Trial)
                            {
                                String TrialMessage = DomainStrings.Trial;
                                if (!string.IsNullOrWhiteSpace(team.TrialInfo))
                                {
                                    TrialMessage += ": " + team.TrialInfo;
                                }
                                Message += (string.IsNullOrWhiteSpace(Message) ? TrialMessage : "\n\r\n\r----\n\r\n\r" + TrialMessage);
                            }

                            SMSGateway.FromText  = General.SystemTextMessagesFrom;
                            SMSGateway.Message   = Message;
                            SMSGateway.Recipient = new List <Person> {
                                TeamLeader
                            };
                            if (team.Start.AddHours(-association.NoteTextTime) < DateTime.Now)
                            {
                                SMSGateway.DeliveryTime = team.Start.AddHours(-association.NoteTextTime);
                            }
                            reposetory.NewTextMessage(SMSGateway, association.AssociationID);

                            if (HandshakeUrl != null && HandshakeUrl.Contains("##"))
                            {
                                SMSGateway.HandShakeUrl = HandshakeUrl.Replace("##", SMSGateway.TextId);
                            }

                            if (SMSGateway.Send())
                            {
                                //team.NoteTextSent = true;
                                //reposetory.SaveTeam(team);
                                reposetory.TeamNoteTextSent(team.TeamID);
                            }
                            ;
                        }
                    }
                    else
                    {
                        result += "*Teamnotes-NO-";
                        if (!association.SendNoteTeamleader)
                        {
                            result += ", SendNoteTeamleader(" + association.SendNoteTeamleader + ")";
                        }
                        if (!team.OK)
                        {
                            result += ", TeamOK(" + team.OK + ")";
                        }
                        if (team.TeamLeaderId == Guid.Empty)
                        {
                            result += ", TeamLeaderId(" + team.TeamLeaderId + ")";
                        }
                        if (team.NoteTextSent)
                        {
                            result += ", NoteTextSent(" + team.NoteTextSent + ")";
                        }
                        if (string.IsNullOrWhiteSpace(team.Note))
                        {
                            result += "TeamMessageTeamLeader(" + string.IsNullOrWhiteSpace(team.Note) + ")";
                        }
                        if (!association.UseKeyBox)
                        {
                            result += ", .UseKeyBox(" + association.UseKeyBox + ")";
                        }
                        if (string.IsNullOrWhiteSpace(association.KeyBoxcode))
                        {
                            result += "KeyBoxcode(" + string.IsNullOrWhiteSpace(association.KeyBoxcode) + ")";
                        }
                        if (!team.Trial)
                        {
                            result += ", Trial(" + team.Trial + ")";
                        }
                    }
                }
                LogFile.Write(result);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Sends notification for new messages in the system
        /// </summary>
        public void SendMessages()
        {
            List <MessageReciver> Recivers = reposetory.ProcessMessageNotification();

            foreach (MessageReciver R in Recivers)
            {
                if (R.Message.Type == MessageType.shortMessage && R.Reciver != null && !string.IsNullOrWhiteSpace(R.Reciver.Mobile))
                {
#if DUMMYTEXT
                    ITextMessage SMSGateway = TextServiceProviderFactory.GetTextServiceProviderrInstance("NR.Infrastructure.DummyTextGateway", null, null);
#else
                    ITextMessage SMSGateway = TextServiceProviderFactory.GetTextServiceProviderrInstance(null, null, null);
#endif
                    if (R.Message != null && R.Message.Sender != null && string.IsNullOrWhiteSpace(R.Message.Sender.Mobile))
                    {
                        SMSGateway.FromText = General.SystemTextMessagesFrom;
                    }
                    else
                    {
                        SMSGateway.From = R.Message.Sender;
                    }
                    SMSGateway.Message   = R.Message.Body + "\n\r---\n\r" + General.MessageNotificationFooter;
                    SMSGateway.Recipient = new List <Person> {
                        R.Reciver
                    };

                    if (HandshakeUrl != null && HandshakeUrl.Contains("##"))
                    {
                        SMSGateway.HandShakeUrl = HandshakeUrl.Replace("##", SMSGateway.TextId);
                    }

                    if (SMSGateway.Send())
                    {
                        reposetory.MarkSent(R);
                        LogFile.Write("Send Message >>> ShortSend  Mobile: (" + R.Reciver.Mobile + ")");
                    }
                    else
                    {
                        LogFile.Write("Send Message >>> ShortSend ERROR  Mobile: (" + R.Reciver.Mobile + ")");
                    }
                    ;
                }
                else if (R.Reciver != null && !string.IsNullOrWhiteSpace(R.Reciver.Email))
                {
                    MessagNotification email = new MessagNotification();
                    // set up the email ...
                    email.To         = R.Reciver.Email;
                    email.Subject    = R.Message.Head;
                    email.ReplyTo    = R.Message.Sender.Email;
                    email.Message    = R.Message.Body;
                    email.Link       = "http://eteelrande";
                    email.FromPerson = R.Message.Sender;
                    try
                    {
                        email.Send();
                        reposetory.MarkSent(R);
                        LogFile.Write("Send Message >>> LongSend  mail: (" + R.Reciver.Email + ")");
                    }
                    catch (Exception e)
                    {
                        LogFile.Write("Send Message Fejl >>> Messagetype " + R.Message.Type.ToString() + " Email: (" + R.Reciver.Email + ") + Mobile: (" + R.Reciver.Mobile + ")");
                    }
                }
                else if (R.Reciver == null)
                {
                    reposetory.MarkSent(R);
                    LogFile.Write("Send Message Fejl >>> Messagetype " + R.Message.Type.ToString() + " Reciever is null");
                }
                else
                {
                    reposetory.MarkSent(R);
                    LogFile.Write("Send Message Fejl >>> Messagetype " + R.Message.Type.ToString() + " Email: (" + R.Reciver.Email + ") + Mobile: (" + R.Reciver.Mobile + ")");
                }
            }
        }
Ejemplo n.º 4
0
        public override int SaveChanges()
        {
            bool saveFailed;

            do
            {
                saveFailed = false;

                try
                {
                    return(base.SaveChanges());
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    saveFailed = true;

                    // Update original values from the database
                    var entry = ex.Entries.Single();
                    entry.OriginalValues.SetValues(entry.GetDatabaseValues());
                }
                catch (DbEntityValidationException ex)
                {
                    // Retrieve the error messages as a list of strings.
                    var errorMessages = ex.EntityValidationErrors
                                        .SelectMany(x => x.ValidationErrors)
                                        .Select(x => x.ErrorMessage);

                    // Join the list to a single string.
                    var fullErrorMessage = string.Join("; ", errorMessages);

                    // Combine the original exception message with the new one.
                    var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);

                    LogFile.WriteError(exceptionMessage);

                    // Throw a new DbEntityValidationException with the improved exception message.
                    throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
                }
                catch (DbUpdateException ex)
                {
                    LogFile.Write(ex, "** DbUpdateException");
                    ITextMessage SMSGateway = TextServiceProviderFactory.GetTextServiceProviderrInstance(null, null, null);

                    SMSGateway.FromText  = "ERROR";
                    SMSGateway.Message   = "DbUpdateException : Fejl på Frivillig";
                    SMSGateway.Recipient = new List <Person> {
                        new Person
                        {
                            Mobile = "28351817"
                        }
                    };

                    if (SMSGateway.Send())
                    {
                    }
                    ;
                    throw;
                }
                catch (Exception ex)
                {
                    LogFile.Write(ex, "** Exception SaveChange");
                }
            } while (saveFailed);
            return(base.SaveChanges());
        }
Ejemplo n.º 5
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));
        }
Ejemplo n.º 6
0
        public ActionResult RetriveLogin(string email, string mobile, string returnUrl)
        {
            ViewBag.ReturnUrl = returnUrl;

            List <Person> Persons = reposetory.GetPeople(email, mobile);

            LogFile.Write(string.Format("Retrive login {0}/{1}", email, mobile));

            if (Persons != null)
            {
                foreach (Person P in Persons)
                {
                    if (!WebSecurity.Login(P.UserName, P.Password, persistCookie: false))
                    {
                        if (WebSecurity.ResetPassword(WebSecurity.GeneratePasswordResetToken(P.UserName), P.Password))
                        {
                        }
                    }
                    else
                    {
                        WebSecurity.Logout();
                    }

                    if (!String.IsNullOrWhiteSpace(P.Email))
                    {
                        var mail = new ForgotLoginEmail
                        {
                            To       = P.Email,
                            UserName = P.UserName,
                            Password = P.Password
                        };
                        try
                        {
                            mail.Send();
                        }
                        catch (Exception Ex)
                        {
                            LogFile.Write(Ex, "Send Mail Retrive Login");
                        }
                    }
                    if (!String.IsNullOrWhiteSpace(P.Mobile) && P.CurrentAssociation != Guid.Empty)
                    {
                        Association association = reposetory.GetAssociation(P.CurrentAssociation);

#if DUMMYTEXT
                        ITextMessage SMSGateway = TextServiceProviderFactory.GetTextServiceProviderrInstance("NR.Infrastructure.DummyTextGateway", association == null ? null : association.TextServiceProviderUserName, association == null ? null : association.TextServiceProviderPassword);
#else
                        ITextMessage SMSGateway = TextServiceProviderFactory.GetTextServiceProviderrInstance(association.TextServiceProvider, association == null ? null : association.TextServiceProviderUserName, association == null ? null : association.TextServiceProviderPassword);
#endif

                        SMSGateway.FromText  = General.SystemTextMessagesFrom;
                        SMSGateway.Message   = String.Format(General.SystemTextMessagesForgetLogin, P.UserName, P.Password);
                        SMSGateway.Recipient = new List <Person> {
                            P
                        };
                        reposetory.NewTextMessage(SMSGateway, association.AssociationID);
                        SMSGateway.HandShakeUrl = Url.Action("TextXStatus", "Account", new { ID = SMSGateway.TextId }, "http");

                        if (SMSGateway.Send())
                        {
                        }
                        ;
                    }
                }
            }

            ViewBag.LoginRetrived = true;

            return(View("Login"));
        }
Ejemplo n.º 7
0
        public ActionResult Edit(NRMembership Membership, string RadioGender, string Action)
        {
            NRMembership CU = new NR.Models.NRMembership
            {
                AssociationID = CurrentProfile.AssociationID,
                SignupDate    = DateTime.Now,
                Type          = PersonType.Active
            };

            CU.Person = new Person();
            if (Membership.MembershipID != Guid.Empty)
            {
                CU = reposetory.GetMembership(Membership.MembershipID);
                if (CU == null)
                {
                    return(HttpNotFound());
                }
            }

            //Check for a uniq username against database
            if (Membership.Person.PersonID == Guid.Empty || (Membership.Person.UserName != CU.Person.UserName))
            {
                if (String.IsNullOrWhiteSpace(Membership.Person.UserName) | !reposetory.IsUserNameUniqe(Membership.Person.UserName))
                {
                    string SuggestedUserName = Membership.Person.UserName;
                    if (Membership.Person.PersonID == Guid.Empty)
                    {
                        reposetory.GenerateUniqueUserName(Membership.Person);
                        ModelState.SetModelValue("Person.UserName", new ValueProviderResult(Membership.Person.UserName, Membership.Person.UserName.ToString(), CultureInfo.InvariantCulture));
                        if (!String.IsNullOrWhiteSpace(SuggestedUserName))
                        {
                            ModelState.AddModelError("Person.UserName", string.Format(DomainStrings.UserNameNotUniqueSuggestion, SuggestedUserName));
                        }
                    }
                    else
                    {
                        Membership.Person.UserName = CU.Person.UserName;
                        //ModelState.Clear();
                        ModelState.SetModelValue("Person.UserName", new ValueProviderResult(Membership.Person.UserName, Membership.Person.UserName.ToString(), CultureInfo.InvariantCulture));
                        ModelState.AddModelError("Person.UserName", string.Format(DomainStrings.UserNameNotUnique, SuggestedUserName));
                    }
                }
            }

            if (RadioGender == "M")
            {
                Membership.Person.Gender = Gender.Man;
            }
            if (RadioGender == "F")
            {
                Membership.Person.Gender = Gender.Woman;
            }
            Membership.Person.Trim();
            if (CU.Person.MailUndeliverable && (
                    CU.Person.FirstName != Membership.Person.FirstName |
                    CU.Person.FamilyName != Membership.Person.FamilyName |
                    CU.Person.Address != Membership.Person.Address |
                    CU.Person.City != Membership.Person.City |
                    CU.Person.Zip != Membership.Person.Zip
                    ))
            {
                CU.Person.MailUndeliverable     = false;
                CU.Person.MailUndeliverableDate = null;
            }
            CU.Person.UserName          = Membership.Person.UserName;
            CU.Type                     = Membership.Type;
            CU.Person.FirstName         = Membership.Person.FirstName;
            CU.Person.FamilyName        = Membership.Person.FamilyName;
            CU.Person.Address           = Membership.Person.Address;
            CU.Person.City              = Membership.Person.City;
            CU.Person.Zip               = Membership.Person.Zip;
            CU.Person.Email             = Membership.Person.Email;
            CU.SignupDate               = Membership.SignupDate;
            CU.Person.Country           = Membership.Person.Country;
            CU.Person.Mobile            = Membership.Person.Mobile;
            CU.Person.Phone             = Membership.Person.Phone;
            CU.Person.BasicTrainingDate = Membership.Person.BasicTrainingDate;
            CU.Person.BirthDate         = Membership.Person.BirthDate;
            CU.Person.EmailNewsLetter   = Membership.Person.EmailNewsLetter;
            CU.Person.PrintNewslettet   = Membership.Person.PrintNewslettet;
            CU.Person.Gender            = Membership.Person.Gender;
            CU.Teamleader               = Membership.Teamleader;
            CU.Note                     = Membership.Note;

            if (String.IsNullOrWhiteSpace(CU.Person.Password))
            {
                CU.Person.Password = String.Empty.GeneratePassword();
            }

            if (ModelState.IsValid)
            {
                var refresh = Membership.Person.PersonID == Guid.Empty;
                reposetory.SavePerson(CU);

                //TODO: Remove Websecurity account if status is changed from Active

                if (refresh)
                {
                    //ensure that form i updated if resubmit of form i done
                    //ModelState.SetModelValue("MembershipID", new ValueProviderResult(CU.MembershipID, CU.MembershipID.ToString(), CultureInfo.InvariantCulture));
                    //ModelState.SetModelValue("Person.PersonID", new ValueProviderResult(CU.Person.PersonID, CU.Person.PersonID.ToString(), CultureInfo.InvariantCulture));

                    //Create Websecurity Memebership if account is active
                    if (CU.Type == PersonType.Active)
                    {
                        if (!WebSecurity.IsConfirmed(CU.Person.UserName))
                        {
                            WebSecurity.CreateAccount(CU.Person.UserName, CU.Person.Password);
                        }

                        //Send Welcome mail if user has an E-mail
                        if (!String.IsNullOrWhiteSpace(CU.Person.Email))
                        {
                            var mail = new WelcomeMailEmail
                            {
                                To       = CU.Person.Email,
                                UserName = CU.Person.UserName,
                                Password = CU.Person.Password
                            };
                            mail.Send();
                        }
                        else if (!String.IsNullOrWhiteSpace(CU.Person.Mobile))
                        {
                            Association association = reposetory.GetAssociation(CU.Person.CurrentAssociation);

#if DUMMYTEXT
                            ITextMessage SMSGateway = TextServiceProviderFactory.GetTextServiceProviderrInstance("NR.Infrastructure.DummyTextGateway", association == null ? null : association.TextServiceProviderUserName, association == null ? null : association.TextServiceProviderPassword);
#else
                            ITextMessage SMSGateway = TextServiceProviderFactory.GetTextServiceProviderrInstance(association.TextServiceProvider, association == null ? null : association.TextServiceProviderUserName, association == null ? null : association.TextServiceProviderPassword);
#endif


                            SMSGateway.FromText  = General.SystemTextMessagesFrom;
                            SMSGateway.Message   = String.Format(General.SystemTextMessagesWelcome, CU.Person.UserName, CU.Person.Password);
                            SMSGateway.Recipient = new List <Person> {
                                CU.Person
                            };
                            if (association != null)
                            {
                                reposetory.NewTextMessage(SMSGateway, association.AssociationID);
                                SMSGateway.HandShakeUrl = Url.Action("TextXStatus", "Account", new { ID = SMSGateway.TextId }, "http");
                            }

                            if (SMSGateway.Send())
                            {
                            }
                            ;
                        }

                        Notification not = reposetory.Notify(CU.Person, String.Format(Notifications.NewPerson, CU.Person.FullName));
                        reposetory.NotifyAddAdministration(not);
                        reposetory.NotifyAddAssociation(not, CU.AssociationID);

                        reposetory.NotifySave(not);
                    }
                }
                ModelState.Clear();
                ViewBag.FormSucces = true;
                return(View(CU));
            }
            return(View(Membership));
        }