コード例 #1
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,Email,UserName,UserRole,FirstName,LastName")] AspNetUser aspNetUser) //,[Bind(Include=("Id,Name"))] As aspNetRole )
        {
            if (ModelState.IsValid)
            {
                db.Entry(aspNetUser).State = EntityState.Modified;
                // await this.UserManager.AddToRoleAsync(aspNetUser.Id, aspNetUser.UserRole = aspNetUser.UserRole);
                var oldUser   = this.UserManager.FindById(aspNetUser.Id);
                var oldRoleId = oldUser.Roles.SingleOrDefault().RoleId;
                // var oldRoleIdFk = oldUser.UserRoleFK.SingleOrDefault();
                var oldRoleIdFk = oldUser.UserRoleFK.ToString();
                var oldRoleName = db.AspNetRoles.SingleOrDefault(r => r.Id == oldRoleId).Name;



                if (oldRoleName != aspNetUser.UserRole)
                {
                    this.UserManager.RemoveFromRole(aspNetUser.Id, oldRoleName);
                    this.UserManager.AddToRole(aspNetUser.Id, aspNetUser.UserRole);
                    var        NewRoleId = (from Role in db.AspNetRoles where Role.Name == aspNetUser.UserRole select Role.Id).SingleOrDefault();
                    AspNetUser User      = db.AspNetUsers.Single <AspNetUser>(u => u.Id == aspNetUser.Id);
                    User.UserRoleFK = NewRoleId;
                }

                await db.SaveChangesAsync();

                return(RedirectToAction("ManageAccounts"));
            }
            return(View(aspNetUser));
        }
コード例 #2
0
ファイル: InfoController.cs プロジェクト: chesser25/ERL_repo
 public ActionResult Edit([Bind(Include = "Id,FirstName,LastName,CompanyName,BirthDate,Gender,Position,Department,EmployedFrom,EmployedTo,LeaveReason,AddressLine1,AddressLine2,ZIP,Place,CountryCode")] UsersInfo userInfo)
 {
     if (ModelState.IsValid)
     {
         db.Entry(userInfo).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(userInfo));
 }
コード例 #3
0
 public ActionResult Edit([Bind(Include = "Id,ItemName,Price")] StoreItem storeItem)
 {
     if (ModelState.IsValid)
     {
         storeItem.StoreIDFk       = db.StoreItems.Where(d => d.Id == storeItem.Id).Select(d => d.StoreIDFk).SingleOrDefault();
         db.Entry(storeItem).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.StoreIDFk = new SelectList(db.Stores, "Id", "StoreName", storeItem.StoreIDFk);
     return(View(storeItem));
 }
コード例 #4
0
 public bool UpdateUser(int id, data user)
 {
     try
     {
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
コード例 #5
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,StoreName,Location,ManagerIDFk,PhoneNumber")] Store store)
        {
            if (ModelState.IsValid)
            {
                store.DateOpened      = db.Stores.Where(d => d.Id == store.Id).Select(d => d.DateOpened).SingleOrDefault();
                db.Entry(store).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.ManagerIDFk = new SelectList(db.AspNetUsers, "Id", "Email", store.ManagerIDFk);
            return(View(store));
        }
コード例 #6
0
        public ActionResult Edit(User userToEdit)
        {
            var originalUser = (from u in _db.Users
                                where u.Id == userToEdit.Id
                                select u).First();

            if (!ModelState.IsValid)
            {
                return(View(originalUser));
            }

            _db.Entry(originalUser).CurrentValues.SetValues(userToEdit);
            _db.SaveChanges();

            return(RedirectToAction("Index"));
        }