예제 #1
0
 public CreateOrUpdateViewModel(IRecord record, FormController formController, Action postSave, Action onCancel, bool explicitIsCreate = false)
     : base(formController)
 {
     _record    = record;
     RecordType = record.Type;
     OnSave     = () =>
     {
         LoadingViewModel.IsLoading = true;
         try
         {
             if (GetRecord().Id == null || explicitIsCreate)
             {
                 GetRecord().Id = RecordService.Create(GetRecord());
             }
             else
             {
                 RecordService.Update(GetRecord(), ChangedPersistentFields);
             }
             if (postSave != null)
             {
                 postSave();
             }
             LoadingViewModel.IsLoading = true;
         }
         finally
         {
             LoadingViewModel.IsLoading = false;
         }
     };
     OnCancel = onCancel;
 }
예제 #2
0
        public void AddModuleToCourse()
        {
            var options = new DbContextOptionsBuilder <OLP_Context>()
                          .UseInMemoryDatabase(databaseName: "CourseModuleTest")
                          .Options;

            // Run the test against one instance of the context
            using (var context = new OLP_Context(options))
            {
                Domain.Course course = new Domain.Course()
                {
                    CourseId    = 1,
                    Name        = "PSI",
                    Description = "make viko great again"
                };

                var courseService = new CourseService(context);
                courseService.Create(course);

                Domain.Course fecthedCourse = courseService.FindBy(x => x.Name == course.Name);
                Assert.AreEqual(fecthedCourse.Name, course.Name);
                Console.Write("|Group  : " + course.Name + " successfully added");
                //insert module
                Domain.Module module = new Domain.Module()
                {
                    Name     = "TestModule",
                    ModuleId = 1,
                    CourseId = 1
                };

                var moduleService = new ModuleService(context);
                moduleService.Create(module);

                Domain.Module fetchedModule = moduleService.FindBy(x => x.Name == module.Name);
                Assert.AreEqual(fetchedModule.Name, module.Name);
                Assert.AreEqual(course.Name, fetchedModule.Course.Name);


                //insert record
                Domain.Record record = new Domain.Record()
                {
                    Name     = "TestRecord",
                    ModuleId = 1,
                    RecordId = 1
                };

                var recordService = new RecordService(context);
                recordService.Create(record);

                Domain.Record fetchedRecord = recordService.FindBy(x => x.Name == record.Name);
                Assert.AreEqual(fetchedRecord.Name, record.Name);

                Assert.AreEqual(course.Name, fetchedRecord.Module.Course.Name);

                Console.Write("|Course Name  : " + course.Name + " Course name through record " + fetchedRecord.Module.Course.Name);
            }
        }
예제 #3
0
 protected CreateViewModel(FormController formController)
     : base(formController)
 {
     OnSave = () => RecordService.Create(GetRecord());
 }