예제 #1
0
        public ObservableCollection <ClientFolder> GetFolders()
        {
            ObservableCollection <ClientFolder> cf = null;

            using (var entities = new ServiceBasedClientDBEntities())
            {
                cf = new ObservableCollection <ClientFolder>(entities.Clients.Select(
                                                                 (Client client) =>
                                                                 new ClientFolder()
                {
                    Name       = client.Name,
                    FamilyName = client.FamilyName,
                    Sex        = client.Sex,
                    Age        = client.Age.Value
                }
                                                                 ));
            }
            return(cf);
        }
예제 #2
0
 public bool DeleteClientFolder(ClientFolder folder)
 {
     try
     {
         using (var entities = new ServiceBasedClientDBEntities())
         {
             var folderModifier = entities.Clients.Where((client) =>
                                                         client.Name == folder.Name && client.FamilyName == folder.FamilyName &&
                                                         client.Age == folder.Age && client.Sex == folder.Sex).ToArray();
             if (folderModifier != null)
             {
                 entities.Clients.RemoveRange(folderModifier);
                 entities.SaveChanges();
             }
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }
예제 #3
0
 public bool AddClientFolder()
 {
     try
     {
         using (var entities = new ServiceBasedClientDBEntities())
         {
             entities.Clients.Add(new Client()
             {
                 Name       = "db default",
                 FamilyName = "db default",
                 Sex        = "db default",
                 Age        = 0
             });
             entities.SaveChanges();
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
예제 #4
0
 public bool ModifyClientFolder(ClientFolder origin, ClientFolder folder)
 {
     try
     {
         using (var entities = new ServiceBasedClientDBEntities())
         {
             var folderModifier = entities.Clients.FirstOrDefault(
                 (client) => client.Name == origin.Name && client.FamilyName == origin.FamilyName);
             if (folderModifier != null)
             {
                 folderModifier.Name       = folder.Name;
                 folderModifier.FamilyName = folder.FamilyName;
                 folderModifier.Sex        = folder.Sex;
                 folderModifier.Age        = folder.Age;
                 entities.SaveChanges();
             }
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }