コード例 #1
0
        public ActionResult Delete(string roleName)
        {
            var thisRole = _context.Roles.FirstOrDefault(r => r.Name.Equals(roleName, StringComparison.CurrentCultureIgnoreCase));

            _context.Roles.Remove(thisRole);
            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #2
0
        public ActionResult Create([Bind(Include = "EmpNo,Title,EmpName,EmpSurname,ID_Pass,Gender,EmpTel,EmpEmail,EmpAddress,D_ID,HireDate,P_ID,Status,Role,Picture,BranchCode")] Staff staff, HttpPostedFileBase img_upload)
        {
            byte[] data = null;
            data = new byte[img_upload.ContentLength];
            img_upload.InputStream.Read(data, 0, img_upload.ContentLength);
            staff.Picture = data;

            if (ModelState.IsValid)
            {
                //ApplicationUser user = db.Users.Where(u => u.UserName.Equals(staff.EmpEmail, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();
                //var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(db));
                //userManager.AddToRole(user.Id, staff.EmpEmail);
                //ApplicationUser user = db.Users.Where(u => u.UserName.Equals(staff.EmpEmail, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();
                //var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(db));
                //userManager.AddToRole(user.Id, rolname);
                _db.Staffs.Add(staff);
                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.BranchCode = new SelectList(_db.Branchs, "BranchCode", "BranchName", staff.BranchCode);
            ViewBag.D_ID       = new SelectList(_db.Departments, "D_ID", "D_Name", staff.D_ID);
            return(View(staff));
        }