Код: Выделить всё
public class Patent
{
public int Id {get; set;}
public string Number {get; set;}
public string Name {get; set;}
public ObservableCollection PatentAuthors {get; set;}
public string Description {get; set;}
public Patent()
{
}
}
Код: Выделить всё
public class Author
{
public int Id {get; set;}
public string FullName {get; set;}
public string Adres {get; set;}
public string PhoneNumber {get; set;}
public Author()
{
}
}
Код: Выделить всё
public static ObservableCollection
_DataBasePatent = new()
{
}
public static ObservableCollection GetPatents()
{
return _DataBasePatent;
}
public static void AddPatent(Patent patent)
{
_DataBasePatent.Add(patent);
}
Код: Выделить всё
public class AddPatentViewModel
{
public ICommand AddPatentCommand {get;set;}
public string AddNumber {get;set;}
public string AddName {get;set;}
public string AuthorFullName {get;set;}
public AddPatentViewModel()
{
AddPatentCommand = new RelayCommand(AddPatent, canAddPatent);
{
public bool canAddPatent(object obj)
{
return true;
}
public void AddPatent(object obj)
{
PatentManager.AddPatent(new()
{
Number = AddNumber,
Name = AddName,
PatentAuthors = new ()
{
FullName = AuthorFullName
}
});
}
}
Я попытался написать новый класс AddAuthorToOldPatent с помощью команды AddNewAuthorToOldPatentCommand
Код: Выделить всё
public class AddPatentViewModel : ViewModelBase
{
public ICommand AddNewAuthorToOldPatentCommand {get;set;}
public string AuthorFullName {get;set;}
public AddPatentViewModel()
{
AddNewAuthorToOldPatentCommand= new RelayCommand(AddNewAuthorToOldPatent, canAddNewAuthorToOldPatent);
{
public bool canAddNewAuthorToOldPatent(object obj)
{
return true;
}
public void AddNewAuthorToOldPatent(object obj)
{
Patent patent = new Patent();
var found = patent.FirstOrDefault(SelectedPatent);
found.PatentAuthors.Add(new(){FullName = AuthorFullName});
}
}
Подробнее здесь: https://stackoverflow.com/questions/792 ... -in-existi