Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

wpf mvvm crud example

public class StudentRecord : ViewModelBase
{
	private int _id;
	public int Id
	{
		get
		{
			return _id;
		}
		set
		{
			_id = value;
			OnPropertyChanged("Id");
		}
	}

	private string _name;
	public string Name
	{
		get
		{
			return _name;
		}
		set
		{
			_name = value;
			OnPropertyChanged("Name");
		}
	}

	private int _age;
	public int Age
	{
		get
		{
			return _age;
		}
		set
		{
			_age = value;
			OnPropertyChanged("Age");
		}
	}

	private string _address;
	public string Address
	{
		get
		{
			return _address;
		}
		set
		{
			_address = value;
			OnPropertyChanged("Address");
		}
	}

	private string _contact;
	public string Contact
	{
		get
		{
			return _contact;
		}
		set
		{
			_contact = value;
			OnPropertyChanged("Contact");
		}
	}

	private ObservableCollection<StudentRecord> _studentRecords;
	public ObservableCollection<StudentRecord> StudentRecords
	{
		get
		{
			return _studentRecords;
		}
		set
		{
			_studentRecords = value;
			OnPropertyChanged("StudentRecords");
		}
	}

	private void StudentModels_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
	{
		OnPropertyChanged("StudentRecords");
	}
}
Comment

wpf mvvm crud example

public class StudentRepository
{
	private StudentEntities studentContext = null;

	public StudentRepository()
	{
		studentContext = new StudentEntities();
	}

	public Student Get(int id)
	{
		return studentContext.Students.Find(id);
	}

	public List<Student> GetAll()
	{
		return studentContext.Students.ToList();
	}

	public void AddStudent(Student student)
	{
		if (student != null)
		{
			studentContext.Students.Add(student);
			studentContext.SaveChanges();
		}
	}

	public void UpdateStudent(Student student)
	{
		var studentFind = this.Get(student.ID);
		if (studentFind != null)
		{
			studentFind.Name = student.Name;
			studentFind.Contact = student.Contact;
			studentFind.Age = student.Age;
			studentFind.Address = student.Address;
			studentContext.SaveChanges();
		}
	}

	public void RemoveStudent(int id)
	{
		var studObj = studentContext.Students.Find(id);
		if (studObj != null)
		{
			studentContext.Students.Remove(studObj);
			studentContext.SaveChanges();
		}
	}
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: project camera view to texture 
Csharp :: messagebox error c# 
Csharp :: how to get point of collision in unity 
Csharp :: Task timed out after 10.02 seconds 
Csharp :: c# pull request 
Csharp :: c# multipthreading 
Csharp :: Set orientation of moving object towards it movement direction without using rigidbody 
Csharp :: set ByteArrayContent content type json 
Csharp :: unity time.fixeddeltatime 
Csharp :: c# datafield change cell background color 
Csharp :: office open xml check if row is empty 
Csharp :: is list sequential C# 
Csharp :: hierachical table to c# class 
Csharp :: unity mouse click 
Csharp :: you have the following c# code. sb is a a very long string. you need to identify whether a string stored in an object named stringtofind is within the stringbuilder sb object. which code should you use? 
Csharp :: cors denied error in asp.net core 
Csharp :: how to add onclick event dynamically in unity 
Csharp :: C# Move Camera Over Terrain Using Touch Input In Unity 3D 
Csharp :: c# order of initialization 
Csharp :: dispose await task c# 
Csharp :: Getting the ID of the element that fired an event 
Csharp :: Untiy particle system play 
Csharp :: c# catch multiple exceptions at once 
Csharp :: "; expected" error c#$ 
Csharp :: c# creat pen 
Csharp :: c# uint 
Csharp :: unity prefab button not working 
Csharp :: c# hardcode datetime quoting 
Csharp :: .net core not returning the sub list 
Csharp :: string to float c# 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =