Esempio n. 1
0
        public ActionResult Edit(int id)
        {
            var service = CreateAlgorithmService();
            var detail  = service.GetAlgorithmById(id);
            var model   =
                new AlgorithmEdit
            {
                AlgorithmId       = detail.AlgorithmId,
                LearningAlgorithm = detail.LearningAlgorithm,
                MasteryLevel      = detail.MasteryLevel
            };

            return(View(model));
        }
Esempio n. 2
0
        public bool UpdateAlgorithm(AlgorithmEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Algorithms
                    .Single(e => e.AlgorithmId == model.AlgorithmId && e.OwnerId == _userId);

                entity.LearningAlgorithm = model.LearningAlgorithm;
                entity.MasteryLevel      = model.MasteryLevel;
                entity.ModifiedUtc       = DateTimeOffset.UtcNow;

                return(ctx.SaveChanges() == 1);
            }
        }
Esempio n. 3
0
        public ActionResult Edit(int id, AlgorithmEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.AlgorithmId != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }

            var service = CreateAlgorithmService();

            if (service.UpdateAlgorithm(model))
            {
                TempData["SaveResult"] = "Your algorithm was updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Your algorithm could not be updated.");
            return(View(model));
        }