Beispiel #1
0
 //public void WriteDataToDatabase()
 //{
 //    using (SchoolEntityModelContainer context = new SchoolEntityModelContainer())
 //    {
 //        context.Groups.Load();
 //        context.Groups.Add(new Groups() { Id = 1, Name = "C#-15-01" });
 //        context.Users.Load();
 //        foreach (var it in _users)
 //        {
 //            Users user = new Users()
 //            {
 //                FirstName = it.FirstName,
 //                SecondName = it.SecondName,
 //                LastName = it.LastName,
 //                imageUri = it.Uri,
 //                Age = (short)it.Age,
 //                GroupsId = 1
 //            };
 //            var roles = context.Roles.Local.ToList();
 //            var currentRole = roles.FirstOrDefault(i => it.GetRoleType() == i.Role);
 //            if (currentRole == null)
 //            {
 //                currentRole = roles.LastOrDefault();
 //                int roleId = currentRole != null ? currentRole.Id + 1 : 1;
 //                context.Roles.Add(new Roles() { Role = it.GetRoleType(), Id = roleId });
 //                user.RolesId = roleId;
 //            }
 //            else
 //                user.RolesId = currentRole.Id;
 //            context.Users.Add(user);
 //        }
 //        context.SaveChanges();
 //    }
 //}
 public List<string> GetGroups()
 {
     using (SchoolEntities context = new SchoolEntities())
     {
         return (from currGroup in context.Groups
                 select currGroup.Name).ToList();
     }
 }
Beispiel #2
0
 public string GetUsers()
 {
     using (SchoolEntities context = new SchoolEntities())
     {
         var users = (from user in context.Users
          select user).ToList();
         string res = JsonConvert.SerializeObject(users);
         return res;
     }
 }