예제 #1
0
        public Workspace Create(string name, User owner)
        {
            var ws = new Workspace {Name = name, Owner = owner};
            Database.Workspaces.Add(ws);
            Database.SaveChanges();

            return ws;
        }
        private void SeedTestData(NProjectEntities context)
        {
            var me = new User
                         {
                             Id = 1,
                             FirstName = "Ivan",
                             LastName = "Manzhos",
                             Email = "*****@*****.**",
                             PasswordHash = EncryptMD5("1234567890"),
                             HoursOffsetFromUtc = 2
                         };
            context.Users.Add(me);

            var otherUser = context.Users.Add(new User
                                                  {
                                                      Id = 2,
                                                      FirstName = "Mark",
                                                      LastName = "Johnson",
                                                      Email = "*****@*****.**",
                                                      PasswordHash = EncryptMD5("1234567890"),
                                                      HoursOffsetFromUtc = 2
                                                  });

            var ws = context.Workspaces.Add(new Workspace {Name = "WS-1", Owner = me});
            var proj1 = context.Projects.Add(new Project {Id = 1, Name = "test-Proj", Workspace = ws});
            var tm1 =
                context.TeamMates.Add(new TeamMate
                                          {
                                              UserId = me.Id,
                                              ProjectId = proj1.Id,
                                              AccessLevel = AccessLevel.ProjectManager
                                          });

            context.TeamMates.Add(new TeamMate {UserId = otherUser.Id, ProjectId = proj1.Id});

            context.Tasks.Add(new Task
                                  {ProjectId = 1, ResponsibleId = 2, Name = "Test task", Description = "bla bla bla"});

            context.SaveChanges();
        }
예제 #3
-1
        public void AddMeeting(Meeting meeting, string userParticipants, string otherParticipants)
        {
            var ms = new MessageService();
            if (!String.IsNullOrEmpty(userParticipants))
            {
                var users =
                    userParticipants.Trim().Split(' ').Select(int.Parse).Select(
                        id => Database.Users.FirstOrDefault(u => u.Id == id));
                users.ToList().ForEach((user) =>
                                           {
                                               meeting.Participants.Add(user);
                                               ms.SendMeetingInvitation(user.Email, meeting);
                                           });
            }
            if (!string.IsNullOrEmpty(otherParticipants))
            {
                var emails = otherParticipants.Trim().Split(' ').ToList();
                foreach (var email in emails)
                {
                    var trygetUser = Database.Users.FirstOrDefault(u => u.Email == email);
                    if (trygetUser == null)
                    {
                        trygetUser = new User
                                         {
                                             Email = email,
                                             AccountType = UserAccountType.MeetingParticipant,
                                             PasswordHash = MD5.EncryptMD5(email)
                                         };
                        Database.Users.Add(trygetUser);
                        ms.SendMeetingInvitation(trygetUser.Email, meeting, false);
                    }
                    else
                        ms.SendMeetingInvitation(trygetUser.Email, meeting);

                    meeting.Participants.Add(trygetUser);
                }
            }
            Database.Meetings.Add(meeting);
            Database.SaveChanges();
        }