sep24migrations.ViewModels.Repo_Subject.UpdateExisting C# (CSharp) Method

UpdateExisting() public method

Update existing
public UpdateExisting ( SubjectFull updatedSubject ) : SubjectFull
updatedSubject SubjectFull Replacement SubjectFull object
return SubjectFull
        public SubjectFull UpdateExisting(SubjectFull updatedSubject)
        {
            // Fetch the existing Subject object
            var s = ds.Subjects.Find(updatedSubject.Id);

            if (s == null)
            {
                return null;
            }
            else
            {
                // Fetch the object from the data store - ds.Entry(s)
                // Get its current values collection - .CurrentValues
                // Set those to the values provided - .SetValues(updatedSubject)
                ds.Entry(s).CurrentValues.SetValues(updatedSubject);
                // The SetValues method ignores missing properties, and navigation properties
                ds.SaveChanges();
                return Mapper.Map<ViewModels.SubjectFull>(s);
            }
        }