Beispiel #1
0
        public async Task <ActionResult> Create(SamplesCreateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            Sample sample;

            try
            {
                sample = await SamplesDao.Create(this, model);
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", e);
                return(View(model));
            }

            return(RedirectToAction("Details", new { sample = sample.SampleId }));
        }
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);
        }
Beispiel #3
0
 public async Task <IHttpActionResult> Create(SamplesCreateViewModel model)
 {
     return(JsonWithPermissions(await SamplesDao.Create(this, model)));
 }