Esempio n. 1
0
        public async Task <ActionResult <InstructorLabViewModel> > GetInstructorLabById(int id)
        {
            InstructorLab fetchedLab = await LabService.GetById(id).ConfigureAwait(false);

            if (fetchedLab == null)
            {
                return(NotFound());
            }

            return(Ok(Mapper.Map <InstructorLabViewModel>(fetchedLab)));
        }
Esempio n. 2
0
        public async Task <InstructorLab> UpdateLab(InstructorLab lab)
        {
            if (lab == null)
            {
                throw new ArgumentNullException(nameof(lab));
            }

            DbContext.InstructorLabs.Update(lab);
            await DbContext.SaveChangesAsync().ConfigureAwait(false);

            return(lab);
        }
Esempio n. 3
0
        public async Task <ActionResult <InstructorLabViewModel> > AddInstructorLab(InstructorLabInputViewModel viewModel)
        {
            if (viewModel == null)
            {
                return(BadRequest());
            }

            InstructorLab createdLab = await LabService.AddLab(Mapper.Map <InstructorLab>(viewModel)).ConfigureAwait(false);

            //return CreatedAtAction(nameof(AddStudentLab), new { id = createdLab.Id }, Mapper.Map<InstructorLabViewModel>(createdLab));
            return(Ok(createdLab));
        }
Esempio n. 4
0
        public async Task <bool> DeleteLab(int labId)
        {
            InstructorLab labToDelete = await DbContext.InstructorLabs.FindAsync(labId).ConfigureAwait(false);

            if (labToDelete == null)
            {
                DbContext.InstructorLabs.Remove(labToDelete);
                DbContext.SaveChanges();

                return(true);
            }

            return(false);
        }
Esempio n. 5
0
        public async Task <ActionResult <InstructorLabViewModel> > UpdateInstructorLab(int id, InstructorLabInputViewModel viewModel)
        {
            if (viewModel == null)
            {
                return(BadRequest());
            }
            InstructorLab fetchedLab = await LabService.GetById(id).ConfigureAwait(false);

            if (fetchedLab == null)
            {
                return(NotFound());
            }

            Mapper.Map(viewModel, fetchedLab);
            await LabService.UpdateLab(fetchedLab).ConfigureAwait(false);

            return(NoContent());
        }
        public async Task UpdateInstructorLab_UpdatesExistingInstructorLab()
        {
            var lab = new InstructorLab
            {
                Title        = "Lab 1",
                InstructorId = 1
            };

            lab.Title = "Lab Updated";
            using (var context = new ApplicationDbContext(Options))
            {
                var           service = new InstructorLabService(context);
                InstructorLab updatedInstructorLab = await service.UpdateLab(lab);

                Assert.AreEqual(lab, updatedInstructorLab);
            }

            using (var context = new ApplicationDbContext(Options))
            {
                InstructorLab retrievedInstructorLab = context.InstructorLabs.Single();
                Assert.AreEqual(lab.Id, retrievedInstructorLab.Id);
                Assert.AreEqual(lab.Title, retrievedInstructorLab.Title);
            }
        }
        public async Task AddInstructorLab_PersistsInstructorLab()
        {
            var lab = new InstructorLab
            {
                Title        = "Lab 1",
                InstructorId = 1
            };

            using (var context = new ApplicationDbContext(Options))
            {
                var service = new InstructorLabService(context);

                InstructorLab addedInstructorLab = await service.AddLab(lab);

                Assert.AreEqual(addedInstructorLab, lab);
                Assert.AreNotEqual(0, addedInstructorLab.Id);
            }

            using (var context = new ApplicationDbContext(Options))
            {
                InstructorLab retrievedInstructorLab = context.InstructorLabs.Single();
                Assert.AreEqual(lab.Title, retrievedInstructorLab.Title);
            }
        }
Esempio n. 8
0
        public async Task <InstructorLab> GetById(int labId)
        {
            InstructorLab fetchedLab = await DbContext.InstructorLabs.SingleOrDefaultAsync(lab => lab.Id == labId).ConfigureAwait(false);

            return(fetchedLab);
        }