public void InsertOrUpdate(Competency competency)
 {
     if (competency.CompetencyId == 0) //new
     {
         context.Competencies.Add(competency);
     }
     else //edit
     {
         context.Entry(competency).State = EntityState.Modified;
     }
 }
Пример #2
0
 public ActionResult Create(Competency competency)
 {
     //save to db.
     if (ModelState.IsValid)
     {
         competenciesRepository.InsertOrUpdate(competency);
         return RedirectToAction("Index");
     }
     else
     {
         return View();
     }
 }
Пример #3
0
 public ActionResult Delete(Competency competency)
 {
     //save to db.
     if (ModelState.IsValid)
     {
         int id = competency.CompetencyId;
         competenciesRepository.Delete(id);
         return RedirectToAction("Index");
     }
     else
     {
         return View(competency);
     }
 }
        public void InsertOrUpdate(Competency competency)
        {
            if (competency.CompetencyId == 0)
            {
                db.Competencies.Add(competency);

            }
            else
            {
                db.Entry(competency).State = EntityState.Modified;

            }
            Save();
        }
        public JsonResult Create(string name, string competencyHeaderName)
        {
            var header = _competencyHeadersRepository.All.First(x => x.Name == competencyHeaderName);
            Competency competency = new Competency()
            {
                CompetencyId = 0,
                Name = name,
                CompetencyHeaderId = header.CompetencyHeaderId
            };

            _competenciesRepository.InsertOrUpdate(competency);
            _competenciesRepository.Save();

            //return Json(new { success = true });
            return Json("ok");
        }
        public JsonResult Create(string name, string competencyHeaderName)
        {
            //https://msdn.microsoft.com/en-us/data/jj573936.aspx
            var competencyHeaders = headerRepo.All;
            int count = competencyHeaders.Count();
            CompetencyHeader header = competencyHeaders.First(x => x.Name == competencyHeaderName);
            //var result = competencyHeaders.Where(x => x.Name.Equals(name)).First();

                //headerRepo.Find(result.CompetencyHeaderId);
                var competency = new Competency
                {
                    Name = name, CompetencyHeader = header, CompetencyHeaderId = header.CompetencyHeaderId
                };
            repo.InsertOrUpdate(competency);

            return Json(competency.Name);
        }
 public ActionResult Edit(Competency competency)
 {
     repo.InsertOrUpdate(competency);
     return View("Index", repo.ToList());
 }