public ViewModelCrew() { if (Client.State == CommunicationState.Closed) { Client.Open(); } crew = new Crew(); AddEntityCommand = new RelayCommand(AddEntityCommand_Execute, AddEntityCommand_CanExecute); RemoveEntityCommand = new RelayCommand(RemoveEntityCommand_Execute, RemoveEntityCommand_CanExecute); AddToCrewCommand = new RelayCommand(AddToCrewCommand_Execute, AddToCrewCommand_CanExecute); RemoveFromCrewCommand = new RelayCommand(RemoveFromCrewCommand_Execute, RemoveFromCrewCommand_CanExecute); AddAllCommand = new RelayCommand(AddAllCommand_Execute, AddAllCommand_CanExecute); RemoveAllCommand = new RelayCommand(RemoveAllCommand_Execute, RemoveAllCommand_CanExecute); Crews = new ObservableCollection<Crew>(Client.GetEntityByType(EntityType.Crew).Cast<Crew>()); AllMembers = new ObservableCollection<CrewMember>(Client.GetEntityByType(EntityType.CrewMember).Cast<CrewMember>().Where(member => string.IsNullOrEmpty(member.Crew))); CrewMembers = new ObservableCollection<CrewMember>(); SelectedMembers = new ObservableCollection<CrewMember>(); SelectedMembersToRemove = new ObservableCollection<CrewMember>(); MakeProxy(this); try { proxy.Subscribe(EntityType.Crew.ToString()); proxy.Subscribe(EntityType.CrewMember.ToString()); } catch (Exception ex) { CrFSMLogger.CrFSMLogger.Instance.WriteToLog(ex); } }
private void AddEntityCommand_Execute(object parameter) { crew.Members.AddRange((from item in CrewMembers select item.GlobalId).ToList()); Client.AddEntity(crew); Crews.Add(crew); crew = new Crew(); CrewName = string.Empty; CrewMembers.Clear(); }
static void Main(string[] args) { DataRepositoryServiceClient client = new DataRepositoryServiceClient(); client.Open(); //bool retVal = false; // client.AddEntity(new User("admin", "admin")); //do //{ //} while (retVal); int counter = 0; string c = string.Empty; string id = string.Empty; do { Console.WriteLine("-----Menu-----"); Console.WriteLine("1) Add new crew member"); Console.WriteLine("2) Get all crew members"); Console.WriteLine("3) Add new crew"); Console.WriteLine("4) Get all crews"); Console.WriteLine("5) Get crew memeber by id"); Console.WriteLine("6) Get crew by id"); Console.WriteLine("7) Remove crew member by id"); Console.WriteLine("8) Remove crew by id"); Console.WriteLine("9) Get all users"); Console.WriteLine("10) Create days"); Console.WriteLine("11) Get day test"); Console.WriteLine("q) Exit"); c = Console.ReadLine(); if (c == "1") { CrewMember crm = new CrewMember("Pera" + (++counter), "Pap", "*****@*****.**", "332423"); client.AddEntity(crm); Console.WriteLine("\tEntity {0} added.", crm.ToString()); id = crm.GlobalId; } if (c == "2") { List<IdentifiedObject> lista = new List<IdentifiedObject>(1); lista = client.GetEntityByType(EntityType.CrewMember).ToList(); foreach (var item in lista) Console.WriteLine(item.ToString()); } if (c == "3") { Crew crm = new Crew("Ekipa" + (++counter)); client.AddEntity(crm); Console.WriteLine("\tEntity {0} added.", crm.ToString()); id = crm.GlobalId; } if (c == "4") { List<IdentifiedObject> lista = new List<IdentifiedObject>(1); lista = client.GetEntityByType(EntityType.Crew).ToList(); foreach (var item in lista) Console.WriteLine(item.ToString()); } if (c == "5") { Console.WriteLine(client.GetEntityById(EntityType.CrewMember, id).ToString()); } if (c == "6") { Console.WriteLine(client.GetEntityById(EntityType.Crew, id).ToString()); } if (c == "7") { IdentifiedObject a = client.GetEntityById(EntityType.CrewMember, id); client.RemoveEntity(a); Console.WriteLine("Removed: {0}", a.ToString()); List<IdentifiedObject> lista = new List<IdentifiedObject>(1); lista = client.GetEntityByType(EntityType.CrewMember).ToList(); foreach (var item in lista) Console.WriteLine(item.ToString()); } if (c == "8") { IdentifiedObject a = client.GetEntityById(EntityType.Crew, id); client.RemoveEntity(a); Console.WriteLine("Removed: {0}", a.ToString()); List<IdentifiedObject> lista = new List<IdentifiedObject>(1); lista = client.GetEntityByType(EntityType.Crew).ToList(); foreach (var item in lista) Console.WriteLine(item.ToString()); } if (c == "9") { List<IdentifiedObject> lista = new List<IdentifiedObject>(1); lista = client.GetEntityByType(EntityType.User).ToList(); foreach (var item in lista) Console.WriteLine(item.ToString()); } if (c == "10") { Console.WriteLine("Succesfully added {0} days", client.CreateWorkingDays()); } if (c == "11") { Console.WriteLine("Day:\n\t{0}", client.GetDayOfYear(new DateTime(2015,7,23))); } } while (c != "q"); client.Close(); }