internal bool RemoveUser(string username)
 {
     Models.ApplicationDbContext context = new Models.ApplicationDbContext();
     var userMgr = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
     userMgr.Delete(userMgr.FindByName(username));
     return true;
 }
Example #2
0
 public void Delete(ApplicationUser user)
 {
     var userStore = new UserStore<ApplicationUser>(this.Context);
     var userManager = new UserManager<ApplicationUser>(userStore);
     userManager.Delete(user);
     var context = userStore.Context;
     context.SaveChanges();
 }
        protected void grvUsers_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            var id = grvUsers.DataKeys[e.RowIndex].Value.ToString();

            var userStore = new UserStore<IdentityUser>();
            var userManager = new UserManager<IdentityUser>(userStore);
            var user = userManager.FindById(id);

            if (user != null && user.UserName != "Admin")
            {
                userManager.Delete(user);
            }

            if (id == SharedClass.CurrentUser)
            {
                Response.Redirect("~/Login.aspx?Logout=true");
            }
        }
Example #4
0
 private void CleanUp(IdentityUser user, UserManager<IdentityUser, Guid> manager)
 {
     var result = manager.Delete(user);
     if (!result.Succeeded)
         throw new Exception("Failed to delete Identity");
 }
Example #5
0
        public bool DeleteUser(string id)
        {
            var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
            var user = manager.FindById(id);

            var success=manager.Delete(user);
            if(success.Succeeded)
                return true;

            return false;
        }
        public IHttpActionResult PostEmployee(Employee employee)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var userStore = new UserStore<IdentityUser>();
            var manager = new UserManager<IdentityUser>(userStore);

            var user = new IdentityUser() { UserName = employee.Email, Email = employee.Email, PhoneNumber = employee.PrimaryMobile.ToString() };

            // TODO Environment Varialbe

            IdentityResult result = manager.Create(user, WebConfigurationManager.AppSettings["DefaultPassword"]);

            // IdentityResult result = manager.Create(user, Environment.GetEnvironmentVariable("DefaultPassword"));

            string[] roles =  { "", "", "", "", "ClientEmployee", "ClientAdmin", "OrgEmployee", "OrgManager", "SecondLevelManager" };
            int roleIndex = employee.EmpStatus;
            if (result.Succeeded)
            {
                employee.AuthUserId = user.Id;
                employee.ProfilePic = "0";
                employee.EmpStatus = 1;
                db.Employees.Add(employee);

                if (db.SaveChanges() != 1)
                {
                     manager.Delete(user);
                }
                else
                {
                    //manager.AddToRole(employee.AuthUserId, "ClientEmployee");
                    manager.AddToRole(employee.AuthUserId, roles[roleIndex]);
                }
            }
            return CreatedAtRoute("DefaultApi", new { id = employee.EmpId }, employee);
        }
Example #7
0
        public ActionResult deleteUser(string userID)
        {
            ajaxReturnData data = new ajaxReturnData();

            try
            {
                using (ApplicationDbContext DB = new ApplicationDbContext())
                {
                    ApplicationUser user = new ApplicationUser();

                    var store = new UserStore<ApplicationUser>(DB);
                    UserManager<ApplicationUser> um = new UserManager<ApplicationUser>(store);
                    user = um.FindById(userID);
                    if (user.UserName == "[email protected]")
                    {
                        data.statusCode = (int)statusCodes.fail;
                        data.message = "I'm sorry Dave, I'm afraid I can't do that";
                    }
                    else {
                        DB.UserLanguages.RemoveRange(DB.UserLanguages.Where(x => x.userID == userID));
                        data.message = "User '" + user.UserName + "' has become one with the void";
                        um.Delete(user);
                        data.statusCode = (int)statusCodes.successRun;
                    }
                    
                }

            }
            catch (Exception ex)
            {

                data.statusCode = (int)statusCodes.fail;
                data.message = "Failed to delete user; Error is: " + ex.Message;
            }



            return Json(data);
        }
Example #8
0
 public ActionResult KullaniciSil(string id)
 {
     UserStore<HaberUser> userStore = new UserStore<HaberUser>(context);
     userManager = new UserManager<HaberUser>(userStore);
     if (id==null || id=="")
     {
         return RedirectToAction("KullaniciListesi");
     }
     else
     {
         var user = userManager.FindByName(id.Trim());
         if (user!=null)
         {
             userManager.Delete(user);
             context.SaveChanges();
             
         }
             return RedirectToAction("KullaniciListesi");
     }
 }
        public JsonResult TenantDelete(string TenantID)
        {

            var BID = db.Tenant.Where(c => c.ID == TenantID).FirstOrDefault().Apartment.Buildings.ID;
            var AID = db.Tenant.Where(c => c.ID == TenantID).FirstOrDefault().Apartment.ID;


            try {
              
                
                ApplicationDbContext context = new ApplicationDbContext();
                ApplicationUser AppUser = new ApplicationUser();
                var RoleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(context));
                var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
                // remove tenant from role
                userManager.RemoveFromRole(TenantID, "Tenant");
                //find tenant on the tenant table 
                 AspNetUsers aspnetuser = db.AspNetUsers.Find(TenantID);
                db.AspNetUsers.Remove(aspnetuser);
                var tn = db.Tenant.Find(TenantID);
                //remove tenant from the tenant table
                db.Tenant.Remove(tn);
                //save changes 
                db.SaveChanges();
                //load tenant applicationuser 
                AppUser = userManager.FindById(TenantID);
                //delete tenant applicationuser
                var result = userManager.Delete(AppUser);

              
               
            }
            catch (Exception e)
            {
                ViewBag.Message = e.Message;

            }

            var tenants = db.Tenant.Where(c => c.aptID == (int?)AID).Select(c => new
            {
                ID = c.ID,
                FirstName = c.FirstName,
                LastName = c.LastName,
                Phone = c.Phone,
                UserName = c.Username,
                CreatedDate = c.Created
            }).ToList();

            var mydata = Json(tenants);

            return new JsonResult { Data = mydata, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
               
        }
Example #10
0
    public void removeSSAEktronMember(string UserPIN)
    {
        try
        {
            UserManager Usermanager = new UserManager();
            UserCriteria criteria = new UserCriteria(UserProperty.UserName, EkEnumeration.OrderByDirection.Ascending);

            criteria.AddFilter(UserProperty.UserName, CriteriaFilterOperator.EqualTo, UserPIN);

            List<UserData> UserList = Usermanager.GetList(criteria);
            long EktronUserID = UserList[0].Id;

            if (Ektron.Cms.Framework.Context.UserContextService.Current.IsLoggedIn)
            {
                Usermanager.Delete(EktronUserID);
                // add user to group MSBA Members
                //UserGroupManager UserGroupmanager = new UserGroupManager();
                //Add a User  to a UserGroup
                // UserGroupmanager.DeleteUser(1, newUserdata.Id);
            }
        }
        catch { }
    }