Exemple #1
0
        public static string ReplaceTagTeamStart(this string value, Team team)
        {
            if (string.IsNullOrWhiteSpace(value)) return value;
            string StartStr = team.Start.AddSeconds(-1).ToString("dddd, d. MMM") + team.Start.ToString(" H:mm").Replace("00:00", "24:00");   // Convert time 00:00 to 24:00 for better understanding
            string result = value.Replace(TeamStart, StartStr);

            return result;
        }
Exemple #2
0
        public static string ReplaceTagTeamMembers(this string value, Team team, Person currentPerson)
        {
            if (string.IsNullOrWhiteSpace(value)) return value;

            string result = "";

            foreach (Person P in team.Teammembers.ToList().Where(x => x.PersonID != currentPerson.PersonID).OrderBy(m => String.Concat(m.FirstName, " ", m.FamilyName)))
            {
                if (result != "") result += ", ";
                result += P.FirstName + " ( ";
                result += P.Mobile == "" ? "--" : P.Mobile;
                result += " )";
            }

            
           

            return value.Replace(TeamMembers, result);
        }
        public ActionResult AddTeams(AddTeamsModel result)
        {
            Folder Folder = reposetory.GetFolder(result.Folder.FolderID);
            Association assocoation = reposetory.GetAssociation(CurrentProfile.AssociationID);
            result.Folder = Folder;
            result.LocationsSelectList = reposetory.GetAssociation(CurrentProfile.AssociationID).Locations.Select(d => new SelectListItem { Value = d.LocationID.ToString(), Text = d.Name }).ToList();
            DateTime start = result.StartDate.Date.Add(result.StartTime.TimeOfDay);
            if (ModelState.ContainsKey("Folder.FoldereName")) ModelState["Folder.FoldereName"].Errors.Clear();
            if (start < Folder.Start | start > Folder.Finish) ModelState.AddModelError("", General.ErrorStartNotWithinFolderDate);
            if (result.Duration == new TimeSpan(0, 0, 0)) ModelState.AddModelError("", General.ErrorDurationZero);

            if (ModelState.IsValid)
            {
                Location Loc = reposetory.GetLocation(result.Location);
                for (int i = 0; (int)result.Repetition <= 0 ? i < 1 : start.AddDays(i) < Folder.Finish; i += (int)result.Repetition <= 0 ? 1 : (int)result.Repetition)
                {
                    Team team = new Team
                    {
                        Start = start.AddDays(i),
                        Duration = result.Duration,
                        Location = Loc,
                        Status = TeamStatus.Planned,
                        Association = assocoation
                    };
                    Folder.Teams.Add(team);
                }

                if (reposetory.SaveFolder(Folder)) return RedirectToAction("Folder", null, new { ID = Folder.FolderID });
            }
            return View(result);
        }
        public static Association ExtractAssociation(int id)
        {

            Dictionary<int, Guid> Assdictionary = new Dictionary<int, Guid>();
            Dictionary<string, string> UserNamedictionary = new Dictionary<string, string>();
            Dictionary<int, String> Locationdictionary = new Dictionary<int, String>();


            Random random = new Random();

            Association association = null;

            //Get Association
            using (SqlConnection cn = new SqlConnection(seedConnectionString))
            {
                SqlCommand cmd = new SqlCommand("SELECT * FROM [Foreninger] WHERE ForeningsID = " + id.ToString(), cn);
                cmd.CommandType = CommandType.Text;
                cn.Open();
                var reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);

                while ((reader.Read()))
                {
                    association = ConvertAssociation(reader);
                    association.UseSchedulePlanning = true;
                    association.PageSponsor = new NR.Models.Content { Title = DefaultForening.PageContentSponsorTitle, Body = DefaultForening.PageContentSponsor };
                    association.PageAbout = new NR.Models.Content { Title = DefaultForening.PageContentAboutTitle, Body = DefaultForening.PageContentAbout };
                    association.PagePress = new NR.Models.Content { Title = DefaultForening.PageContentPressTitle, Body = DefaultForening.PageContentPress };
                    association.PageLink = new NR.Models.Content { Title = DefaultForening.PageContentLinkTitle, Body = DefaultForening.PageContentLink };
                    Assdictionary.Add((int)reader["ForeningsID"], association.AssociationID);


                }
            }

            //Get persons
            association.Memberships = new List<NRMembership>();
            using (SqlConnection cn = new SqlConnection(seedConnectionString))
            {
                SqlCommand cmd = new SqlCommand(@"SELECT
                        [Ravnetur].[dbo].[aspnet_Users].[UserId]
                        ,[UserName]
                        ,[Email]
                        ,[Password]
	                    ,[PropertyNames]
                        ,[PropertyValuesString]
                        ,[LastActivityDate]
                        ,[CreateDate]
                        ,(SELECT CAST(1 AS BIT) AS Expr1
							FROM [Ravnetur].[dbo].[aspnet_UsersInRoles]
							WHERE ([Ravnetur].[dbo].[aspnet_UsersInRoles].UserId = [Ravnetur].[dbo].[aspnet_Users].UserId
									AND [Ravnetur].[dbo].[aspnet_UsersInRoles].RoleId = 'ED1CAE67-880D-4EC0-A00F-81DD0A191749')) as [Planner]	
                        FROM [Ravnetur].[dbo].[aspnet_Users]
                        LEFT JOIN [Ravnetur].[dbo].[aspnet_Profile]
                        ON [Ravnetur].[dbo].[aspnet_Users].UserId = [Ravnetur].[dbo].[aspnet_Profile].UserId
                        LEFT JOIN [Ravnetur].[dbo].[aspnet_Membership]
                        ON [Ravnetur].[dbo].[aspnet_Users].UserId = [Ravnetur].[dbo].[aspnet_Membership].UserId;", cn);
                cmd.CommandType = CommandType.Text;
                cn.Open();
                var reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);

                while ((reader.Read()))
                {
                    if (reader["PropertyValuesString"] != null & !Convert.IsDBNull(reader["PropertyValuesString"]))
                    {
                        string StrId = ReturnProperty("ForeningsID", (string)reader["PropertyNames"], (string)reader["PropertyValuesString"]);
                        if (StrId != String.Empty && Convert.ToInt32(StrId) == id)
                        {
                            Person person = ConvertPerson(reader, association.Country);

                            List<NRMembership> ms = association.Memberships.ToList();

                            var ExistUser = from UN in ms
                                            where UN.Person.UserName == person.UserName
                                            select UN;

                            if (ExistUser.Any())
                            {

                                char ch;
                                for (int i = 0; i < 2; i++)
                                {
                                    ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
                                    person.UserName = person.UserName + ch.ToString();
                                }
                            }

                            UserNamedictionary.Add((String)reader["UserName"], person.UserName);

                            NRMembership membership = new NRMembership();

                            if (ReturnProperty("Udmeldt", (string)reader["PropertyNames"], (string)reader["PropertyValuesString"]) == "True") membership.AbsentDate = DateTime.Now;
                            membership.Teamleader = ReturnProperty("TurLeder", (string)reader["PropertyNames"], (string)reader["PropertyValuesString"]) == "True" ? true : false;
                            membership.BoardFunction = BoardFunctionType.none;
                            membership.SignupDate = DateTime.Now;
                            membership.Type = PersonType.Active;
                            membership.SignupDate = person.Created;

                            membership.Person = person;

                            //membership.Association = association;

                            if (reader["Planner"] != null & !Convert.IsDBNull(reader["Planner"])) membership.Planner = true;


                            //person.Memberships.Add(membership);
                            association.Memberships.Add(membership);


                            //person.CurrentAssociation = association.AssociationID;
                            //association.People.Add(person);
                        }
                    }
                }
            }

            //Get locations
            association.Locations = new List<Location>();
            using (SqlConnection cn = new SqlConnection(seedConnectionString))
            {
                SqlCommand cmd = new SqlCommand("SELECT * FROM [Lokationer] WHERE ForeningsID = " + id.ToString(), cn);
                cmd.CommandType = CommandType.Text;
                cn.Open();
                var reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                while ((reader.Read()))
                {
                    Location location = ConvertLocation(reader);
                    if (!String.IsNullOrWhiteSpace(location.Name.Replace(".", "")))
                    {
                        association.Locations.Add(location);
                        Locationdictionary.Add((int)TjekDBNull(reader["LokID"]), location.ShortName);
                    }
                }
            }

            if (!association.Locations.Any())
            {
                Location location = new Location
                {
                    Name = association.Name,
                    ShortName = "STD",
                    Description = "Standard lokationen for forningen"
                };
                association.Locations.Add(location);
            }

            //Get Folders
            association.Folders = new List<Folder>();
            using (SqlConnection cn = new SqlConnection(seedConnectionString))
            {
                SqlCommand cmd = new SqlCommand("SELECT * FROM [TurMapper] WHERE ForeningsID = " + id.ToString(), cn);
                cmd.CommandType = CommandType.Text;
                cn.Open();
                var reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);

                while ((reader.Read()))
                {
                    Folder folder = ConvertFolder(reader);
                    folder.Start = folder.Start.Date;
                    folder.Finish = folder.Finish.Date.AddDays(1).AddSeconds(-1);

                    int TurmappeID = (int)TjekDBNull(reader["TurMappeID"]);
                    folder.Teams = new List<Team>();
                    using (SqlConnection cn1 = new SqlConnection(seedConnectionString))
                    {
                        SqlCommand cmd1 = new SqlCommand("SELECT * FROM [Turer] WHERE TurmappeID = " + TurmappeID.ToString(), cn1);
                        cmd1.CommandType = CommandType.Text;
                        cn1.Open();
                        var reader1 = cmd1.ExecuteReader(CommandBehavior.CloseConnection);

                        while ((reader1.Read()))
                        {
                            Team team = new Team
                            {
                                Start = (DateTime)reader1["Start"],
                                Note = (String)TjekDBNull(reader1["Note"]),
                                Created = (DateTime)reader1["Oprettet"],
                                Lastchanged = (DateTime)reader1["SidstRettet"],
                                Association = association,
                                Teammembers = new List<Person>()
                            };

                            if (String.IsNullOrWhiteSpace(team.Note)) team.Note = null;
                            string Dur = (String)reader1["Tid"];
                            TimeSpan DurT;
                            if (TimeSpan.TryParse(Dur, out DurT))
                            {
                                team.Duration = DurT;
                            }

                            switch ((String)reader1["Status"])
                            {
                                case "OK":
                                    team.Status = TeamStatus.OK;
                                    break;
                                case "Aflyst":
                                    team.Status = TeamStatus.Cancelled;
                                    break;
                                case "Nedlagt":
                                    team.Status = TeamStatus.Droped;
                                    break;
                                default:
                                    team.Status = TeamStatus.Planned;
                                    break;
                            }
                            //UserNamedictionary
                            String UserName;
                            if (UserNamedictionary.TryGetValue((String)reader1["TurlederID"], out UserName))
                            {
                                Person TL = association.Memberships.Where(m => m.Person.UserName == UserName).Select(m => m.Person).FirstOrDefault();
                                team.Teammembers.Add(TL);
                                team.TeamLeaderId = TL.PersonID;
                            }
                            if (UserNamedictionary.TryGetValue((String)reader1["Ravn1ID"], out UserName))
                            {
                                team.Teammembers.Add(association.Memberships.Where(m => m.Person.UserName == UserName).Select(m => m.Person).FirstOrDefault());
                            }
                            if (UserNamedictionary.TryGetValue((String)reader1["Ravn2ID"], out UserName))
                            {
                                team.Teammembers.Add(association.Memberships.Where(m => m.Person.UserName == UserName).Select(m => m.Person).FirstOrDefault());
                            }
                            else if ((String)reader1["Ravn2ID"] == "PRØVETUR")
                            {
                                team.Trial = true;
                            }
                            string Loc;
                            if (Locationdictionary.Any() && TjekDBNull(reader1["Lokation"]) != null && Locationdictionary.TryGetValue((int)reader1["Lokation"], out Loc))
                            {
                                team.Location = association.Locations.Where(l => l.ShortName == Loc).FirstOrDefault();
                            }
                            else
                            {
                                team.Location = association.Locations.Where(l => l.ShortName == "STD").FirstOrDefault();
                            }
                            folder.Teams.Add(team);
                        }
                    }

                    association.Folders.Add(folder);
                }
            }
            return association;
        }