Beispiel #1
0
        public ActionResult Save(Personal personal)
        {
            if (!ModelState.IsValid)
            {
                var model = new PersonalFormViewModel()
                {
                    Departments = db.Department1.ToList(),
                    Personal    = personal
                };
                return(View("PersonalForm", model));
            }
            MessageViewModel modelMessage = new MessageViewModel();

            if (personal.Id == 0)
            {
                db.Personal.Add(personal);
                modelMessage.Message = personal.Name + " " + personal.Surname + " added. Press to return ";
            }
            else
            {
                db.Entry(personal).State = System.Data.Entity.EntityState.Modified;
                modelMessage.Message     = "Data of " + personal.Name + " " + personal.Surname + " updated. Press to return ";
            }
            db.SaveChanges();
            modelMessage.Status   = true;
            modelMessage.LinkText = "Personal List";
            modelMessage.Url      = "/Personal";
            return(View("_Message", modelMessage));
        }
        public ActionResult Save(Department1 department)
        {
            if (!ModelState.IsValid)
            {
                return(View("DepartmentForm"));
            }

            MessageViewModel model = new MessageViewModel();

            if (department.Id == 0)
            {
                db.Department1.Add(department);
                model.Message = department.Name + " added. Press to return ";
            }
            else
            {
                var deparmentToUpdate = db.Department1.Find(department.Id);
                if (deparmentToUpdate == null)
                {
                    return(HttpNotFound());
                }
                deparmentToUpdate.Name = department.Name;
                model.Message          = department.Name + " updated. Press to return ";
            }
            db.SaveChanges();
            model.Status   = true;
            model.LinkText = "Department List";
            model.Url      = "/Department";
            return(View("_Message", model));
        }
Beispiel #3
0
        public ActionResult Create([Bind(Include = "Id,Name,Password,Role")] User1 user1)
        {
            if (ModelState.IsValid)
            {
                db.User1.Add(user1);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(user1));
        }