Esempio n. 1
0
        public ActionResult Edit(TitleEditView editView, string submitbutton)
        {
            //if (ModelState.IsValid)
            //{
            //    return ("Good");
            //}

            if (editView.Title.Name == null)
            {
                TempData["EmptyName"] = ViewData;
                return(RedirectToAction("Edit", editView.Title.Id));
            }
            Title title;

            if (submitbutton == "Save")
            {
                title = dbNew.Titles.Find(editView.Title.Id);
            }
            else
            {
                title = editView.Title;
            }
            if (title.Name != editView.Title.Name && dbNew.Titles.FirstOrDefault(co => co.Name == editView.Title.Name) != null)
            {
                TempData["NameExist"] = ViewData;
                return(RedirectToAction("Edit", title.Id));
                //return View("~/Views/Shared/Error.cshtml");
                //ModelState.AddModelError("", "Title Already Exist");
                //return View(editView);
            }

            else
            {
                title.JobAreas.Clear();
                title.Name       = editView.Title.Name;
                title.JobLevelId = editView.Title.JobLevelId;
                if (editView.selectedJobAreas != null)
                {
                    foreach (var c in dbNew.JobAreas.Where(area => editView.selectedJobAreas.Contains(area.Id)))
                    {
                        title.JobAreas.Add(c);
                    }
                }

                if (submitbutton == "Save")
                {
                    dbNew.Entry(title).State = EntityState.Modified;
                }
                else
                {
                    dbNew.Titles.Add(title);
                }
                dbNew.SaveChanges();
                return(RedirectToAction("Index"));
            }
        }
Esempio n. 2
0
        public ActionResult Edit(int?id)
        {
            Title title = null;

            //var temp = dbNew.JobAreas.ToList();
            if (id == null)
            {
                title = new Title();
            }
            else
            {
                title = dbNew.Titles.Include(t => t.JobLevel).Include(t => t.Contacts).FirstOrDefault(t => t.Id == id);
            }
            if (title == null)
            {
                return(HttpNotFound());
            }
            TitleEditView titleEditView = new TitleEditView(title, dbNew.JobAreas, dbNew.JobLevels.OrderBy(l => l.level));

            return(View(titleEditView));
        }