Beispiel #1
0
        public static StudentParentContactModelDataCRUD GetCreateStudentParentModel(int studentId)
        {
            using (var context = DataContext.GetContext())
            {
                var student = (from s in context.Students.Include("StudentParents")
                               where s.StudentId == studentId
                               select s).Single();

                var result = new StudentParentContactModelDataCRUD
                {
                    ContactMade  = false,
                    ContactNotes = string.Empty,
                    StudentName  = student.FirstName + " " + student.LastName,
                    StudentId    = studentId
                };

                var parentList =
                    student.StudentParents.Select(
                        a =>
                        new SelectListItem
                {
                    Text  = a.FirstName + " " + a.LastName,
                    Value = a.StudentParentId.ToString(CultureInfo.InvariantCulture)
                }).ToList();

                parentList.Insert(0, new SelectListItem {
                    Text = "", Value = ""
                });
                result.StudentParents = parentList.AsEnumerable();

                return(result);
            }
        }
Beispiel #2
0
 public static void UpdateStudentParentContact(StudentParentContactModelDataCRUD model, int userId)
 {
     using (var context = DataContext.GetContext())
     {
         var existingItem = context.StudentParentContacts.Single(a => a.StudentParentContactId == model.StudentParentContactId);
         existingItem.LastModifiedOn = DateTime.Now;
         existingItem.LastModifiedBy = userId;
         existingItem.ContactMade    = model.ContactMade;
         existingItem.ContactNotes   = model.ContactNotes;
         Debug.Assert(model.DateOfContact != null, "model.DateOfContact != null");
         Debug.Assert(model.TimeOfContact != null, "model.TimeOfContact != null");
         existingItem.ContactTime = Misc.CombineDateAndTime(model.DateOfContact.Value, model.TimeOfContact.Value);
         context.SaveChanges();
     }
 }
Beispiel #3
0
 public static Entities.StudentParentContact CreateStudentParentContact(StudentParentContactModelDataCRUD model, int userId)
 {
     using (var context = DataContext.GetContext())
     {
         Debug.Assert(model.DateOfContact != null, "model.DateOfContact != null");
         Debug.Assert(model.TimeOfContact != null, "model.TimeOfContact != null");
         Debug.Assert(model.StudentParentId != null, "model.StudentParentId != null");
         var result = new Entities.StudentParentContact
         {
             CreatedBy       = userId,
             CreatedOn       = DateTime.Now,
             LastModifiedOn  = DateTime.Now,
             LastModifiedBy  = userId,
             ContactMade     = model.ContactMade,
             ContactNotes    = string.IsNullOrEmpty(model.ContactNotes) ? string.Empty : model.ContactNotes,
             ContactTime     = Misc.CombineDateAndTime(model.DateOfContact.Value, model.TimeOfContact.Value),
             StudentParentId = model.StudentParentId.Value
         };
         context.StudentParentContacts.AddObject(result);
         context.SaveChanges();
         return(result);
     }
 }