Exemplo n.º 1
0
        public async Task <IHttpActionResult> Update(long labId, LabsEditViewModel model)
        {
            var(_, isLabManager) = await GetLab(labId);

            var lab = await LabsDao.Read(this, labId);

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

            var result = await LabsDao.Update(this, lab, model);

            return(JsonWithPermissions(result, User.IsPrivileged(), isLabManager, User.IsAdmin()));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Edit(Lab lab, LabsEditViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            try
            {
                await LabsDao.Update(this, lab, model);
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", e.ToString());
                return(View(model));
            }

            return(RedirectToAction("Details", new { lab = lab.LabId }));
        }
Exemplo n.º 3
0
        public static async Task <Lab> Update(IRequestContext context, Lab lab, LabsEditViewModel model)
        {
            var test = await context.DbContext.Tests.FirstOrDefaultAsync(t => t.TestId == model.TestId);

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

            lab.CollegeName = model.CollegeName;
            lab.CourseCode  = model.CourseCode;
            lab.WeekNumber  = model.WeekNumber;
            lab.Test        = test;
            lab.Location    = model.Location;

            await context.DbContext.SaveChangesAsync();

            await context.LogAsync($"Edited lab ID {lab.LabId}");

            return(lab);
        }