示例#1
0
        public ActionResult Create(Role role)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.Roles.Add(role);
                    db.SaveChanges();
                    //return RedirectToAction("Index");
                    Roles.AddUserToRole("海立美达", role.RoleName);

                    return View(role);
                }

                return View(role);
            }
            catch (Exception ex)
            {
                return Content(ex.Message);
            }
        }
示例#2
0
        public ActionResult Edit(Role role, string[] EmpListH = null, string btnEmp = "")
        {
            ViewData["emps"] = db.BEmplyees.ToList<BEmplyee>();
            try {

                if (ModelState.IsValid)
                {
                    if (EmpListH != null && EmpListH.Count() > 0)
                    {

                        int[] intEmps = new int[EmpListH.Count()];
                        for (int i = 0; i < EmpListH.Count(); i++)
                        {
                            intEmps[i] = int.Parse(EmpListH[i]);
                        }

                        var empts = from es in db.BEmplyees where intEmps.Contains(es.EmpID) select es.NumberEmp;

                        //foreach (BEmplyee bemp in empts)
                        //{
                        //    if (!role.Emplyees.Contains(bemp))
                        //    {
                        //        role.Emplyees.Add(bemp);
                        //    }
                        //}
                        //role.Emplyees = empts.ToList<BEmplyee>();
                        Roles.RemoveUsersFromRole(Roles.GetUsersInRole(role.RoleName), role.RoleName);
                        Roles.AddUsersToRole(empts.ToArray<string>(),role.RoleName);
                        //return View(role);

                    }
                    else
                    {
                        return Content("没取到");
                    }

                    db.Entry(role).State = EntityState.Modified;

                    db.SaveChanges();

                    return RedirectToAction("Index");
                }
                return View(role);
            }
            catch (Exception ex)
            {
                return Content(ex.Message);
            }
        }