Beispiel #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));
        }
Beispiel #2
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());
        }
Beispiel #3
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"));
        }
Beispiel #4
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));
        }
Beispiel #5
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));
        }