Beispiel #1
0
        public static async Task <Sample> Update(IRequestContext context, Sample sample, SamplesEditViewModel model)
        {
            var test = await TestsDao.Read(context, model.TestId);

            if (test == null)
            {
                throw new Exception("Test does not exist.");
            }

            sample.Test        = test;
            sample.Description = model.Description;
            sample.AddedDate   = model.AddedDate;

            await context.DbContext.SaveChangesAsync();

            await context.LogAsync($"Edited sample ID {sample.SampleId}");

            return(sample);
        }
Beispiel #2
0
        public static async Task <Sample> Create(IRequestContext context, SamplesCreateViewModel model)
        {
            var test = await TestsDao.Read(context, model.TestId);

            if (test == null)
            {
                throw new Exception("Test does not exist.");
            }

            var sample = new Sample
            {
                TestId      = model.TestId,
                Description = model.Description,
                AddedDate   = model.AddedDate,
            };

            context.DbContext.Samples.Add(sample);
            await context.DbContext.SaveChangesAsync();

            await context.LogAsync($"Sample ID {sample.SampleId} created");

            return(sample);
        }