コード例 #1
0
        public ActionResult Edit(int id)
        {
            var service = CreateQualificationService();
            var detail  = service.GetQualificationById(id);
            var model   =
                new QualificationEdit
            {
                QualificationId     = detail.QualificationId,
                OwnerId             = detail.OwnerId,
                EmployeeId          = detail.EmployeeId,
                NameOfSkill         = detail.NameOfSkill,
                LevelOfSkill        = detail.LevelOfSkill,
                YrsOfExperience     = detail.YrsOfExperience,
                NameOfCertification = detail.NameOfCertification
            };

            return(View(model));
        }
コード例 #2
0
        public bool UpdateQualification(QualificationEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Qualifications
                    .Single(e => e.QualificationId == model.QualificationId && e.OwnerId == _userId);

                entity.QualificationId     = model.QualificationId;
                entity.EmployeeId          = model.EmployeeId;
                entity.NameOfSkill         = model.NameOfSkill;
                entity.LevelOfSkill        = model.LevelOfSkill;
                entity.YrsOfExperience     = model.YrsOfExperience;
                entity.NameOfCertification = model.NameOfCertification;
                entity.ModifiedUtc         = DateTimeOffset.UtcNow;

                return(ctx.SaveChanges() == 1);
            }
        }
コード例 #3
0
        public ActionResult Edit(int id, QualificationEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

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

            var service = CreateQualificationService();

            if (service.UpdateQualification(model))
            {
                TempData["SaveResult"] = "Your qualifications have been updated.";
                return(RedirectToAction("Index"));
            }

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