当前位置: 首页>>代码示例>>C#>>正文


C# UserRepository.Delete方法代码示例

本文整理汇总了C#中UserRepository.Delete方法的典型用法代码示例。如果您正苦于以下问题:C# UserRepository.Delete方法的具体用法?C# UserRepository.Delete怎么用?C# UserRepository.Delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UserRepository的用法示例。


在下文中一共展示了UserRepository.Delete方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            var dbContext = new ApplicationDbContext();

            using (var uow = new UnitOfWork(dbContext))
            {
                // Creating user
                // var user1 = new User { Login = "Anna", Password = "123" };

                // var userRepo = new UserRepository(dbContext);
                //userRepo.Create(user1);
                //uow.Commit();
                var userRepo = new UserRepository(dbContext);

                var user1 = new User { Login = "Anna1", Password = "123" };
                var user2 = new User { Login = "Anna2", Password = "123" };

              //  userRepo.Create(user1);
                //userRepo.Create(user2);
               // uow.Commit();

                var users = userRepo.GetAll();

                Console.WriteLine("All users count: " + users.Count());

                var anna = userRepo.GetBy(user1.Login);
                userRepo.Delete(anna);
                uow.Commit();

                users = userRepo.GetAll();

                Console.WriteLine("All filtered users count: " + users.Count());
                Console.ReadLine();

                // Creating user article
                 var article1 = new Article { Title = "Article1", Body = "Article1 BodyText" };

                 var anna2 = userRepo.GetBy(user2.Login);

                 userRepo.Delete(anna2);
               // anna2.Articles.Add(article1);
                uow.Commit();

                /*var comment1 = new Comment { Body = "Article1 is my first arctile. (Anna)" };
                               var articleRepo = new ArticleRepository(dbContext);
                anna2.Comments.Add(comment1);
                article1.Comments.Add(comment1);
                uow.Commit();*/

            }
        }
开发者ID:annmasalskaya,项目名称:SyncFramework,代码行数:51,代码来源:SfTest.cs

示例2: Delete

        public ActionResult Delete(int id)
        {
            UserRepository userRep = new UserRepository();
            userRep.Delete(id);

            return RedirectToAction("List");
        }
开发者ID:AntonCholakov,项目名称:CHSystem,代码行数:7,代码来源:UsersController.cs

示例3: Execute

        public override bool Execute(string input)
        {
            if (String.IsNullOrEmpty(input)) return false;

            var repository = new UserRepository();
            int userId;
            if (!Int32.TryParse(input, out userId))
            {
                return false;
            }

            var user = repository.GetById(userId);
            if (user != null)
            {
                repository.Delete(user);
            }
            try
            {
                repository.SaveChanges();
                Success = true;
            }
            catch
            {
                Success = false;
            }
            return Success;
        }
开发者ID:Choulla-Naresh8264,项目名称:WebGridExample,代码行数:27,代码来源:DeleteUserCommand.cs

示例4: AddUser_should_save

        public void AddUser_should_save()
        {
            string username = "save" + Guid.NewGuid();

            var user = new User
            {
                 Email = "[email protected]",
                 FirstName = "john",
                 IsActive = true,
                 LastName = "haigh",
                 PasswordHash = "asdf",
                 Username = username
            };

            var svc = new UserService();
            svc.AddUser(user);

            var repo = new UserRepository();

            var repoUser = repo.Find(u => u.Username == username).FirstOrDefault();

            // Test
            repoUser.ShouldNotBeNull();

            // Cleanup user
            repo.Delete(repoUser);
            repo.Save();

            var results2 = repo.Find(u => u.Username == username);
            var userFound2 = results2.FirstOrDefault();

            Assert.IsNull(userFound2, "Tried to get user but the user was found");
        }
开发者ID:versosystems,项目名称:account-lib,代码行数:33,代码来源:UserServiceTests.cs

示例5: DeleteUser

        public bool DeleteUser(int id)
        {
            UserRepository repo = new UserRepository(entities);
            User user = repo.Get(id);

            try {
                repo.Delete(user);
                return true;
            }
            catch (Exception ex) {
                _errorMessage = ex.Message;
                return false;
            }
        }
开发者ID:adramalech,项目名称:KolabApp,代码行数:14,代码来源:UsersService.cs

示例6: Remove_Entity_Test

        public static void Remove_Entity_Test()
        {
            IUserRepository repository = new UserRepository(_session);
            ICollection<User> todosAntesDeDelete = repository.GetAll();

            foreach (User User in todosAntesDeDelete)
            {
                repository.Delete(User);
            }

            ICollection<User> todosDepoisDeDelete = repository.GetAll();

            Assert.IsTrue(todosDepoisDeDelete.Count == 0);
        }
开发者ID:icarocamelo,项目名称:iLunchWeb,代码行数:14,代码来源:RepositoryTests.cs

示例7: Delete

        public string Delete()
        {
            string result = "";
            int id = Numerics.GetInt(Request["id"]);
            try
            {
                var repo = new UserRepository();
                repo.Delete(id);
                result = JsonResult(true, Resources.Messages.Delete);

            }
            catch (Exception ex)
            {
                result = JsonResult(false, ex.Message);
            }
            return result;
        }
开发者ID:mujassir,项目名称:vehicle_git_ivan,代码行数:17,代码来源:ManageUsers.aspx.cs

示例8: delete

        public Boolean delete()
        {
            //delete from user table
            String deleteUserID = Request.Params["id"];
            int id = int.Parse(deleteUserID);
            IRepository<User> repository = new UserRepository();
            User deletedUser = repository.findById(id);
            if (deletedUser == null)
            {
                return false;
            }
            repository.Delete(deletedUser);

            //delete from asp.netUser table
            var context = new NetCafeWeb.Models.ApplicationDbContext();
            var UserManager = new UserManager<NetCafeWeb.Models.ApplicationUser>(new UserStore<NetCafeWeb.Models.ApplicationUser>(context));
            ApplicationUser aspSelectedUser = context.Users.Where(u => u.UserName.Equals((deletedUser.UserName), StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();

            UserManager.DeleteAsync(aspSelectedUser);

            return true;
        }
开发者ID:AnTTSE61258,项目名称:NetCafeWeb,代码行数:22,代码来源:UserController.cs

示例9: DeleteUser

        public static BaseActionResult DeleteUser(User obj4delete)
        {
            using (var context = new XiaoluEntities())
            {
                string msg;
                var repository = new UserRepository(context);

                if (obj4delete == null)
                {
                    msg = string.Format(XiaoluResources.MSG_DELETE_SUCCESS, XiaoluResources.STR_USER) + string.Format(XiaoluResources.STR_FAIL_RESAON, XiaoluResources.MSG_OBJECT_IS_NULL);
                    return new BaseActionResult(false, msg);
                }
                repository.Delete(obj4delete);
                context.SaveChanges();
                msg = string.Format(XiaoluResources.MSG_UPDATE_SUCCESS, obj4delete.Name);
                return new BaseActionResult(true, msg);
            }
        }
开发者ID:neilchennan,项目名称:Xiaolu,代码行数:18,代码来源:BusinessService.User.cs

示例10: AddUser_should_save_with_user_properties

        public void AddUser_should_save_with_user_properties()
        {
            string username = "save_with_user_propertie" + Guid.NewGuid();

            var user = new User
            {
                Email = "[email protected]",
                FirstName = "john",
                IsActive = true,
                LastName = "haigh",
                PasswordHash = "asdf",
                Username = username
            };

            var svc = new UserService();
            svc.AddUser(user);

            var repo = new UserRepository();

            var repoUser = repo.Find(u => u.Username == username).FirstOrDefault();

            // Test
            repoUser.Email.ShouldEqual(user.Email);
            repoUser.FirstName.ShouldEqual(user.FirstName);
            repoUser.LastName.ShouldEqual(user.LastName);
            repoUser.IsActive.ShouldEqual(user.IsActive);
            repoUser.PasswordHash.ShouldEqual(user.PasswordHash);
            repoUser.Username.ShouldEqual(user.Username);

            // Cleanup user
            repo.Delete(repoUser);
            repo.Save();

            var results2 = repo.Find(u => u.Username == username);
            var userFound2 = results2.FirstOrDefault();

            userFound2.ShouldBeNull();
        }
开发者ID:versosystems,项目名称:account-lib,代码行数:38,代码来源:UserServiceTests.cs

示例11: GetUserByUsername_should_getuser

        public void GetUserByUsername_should_getuser()
        {
            string username = "getbyusername" + Guid.NewGuid();

            var user = new User
            {
                Email = "[email protected]",
                FirstName = "john",
                IsActive = true,
                LastName = "haigh",
                PasswordHash = "asdf",
                Username = username
            };

            var svc = new UserService();
            svc.AddUser(user);

            // main test
            var userAssert = svc.GetUserByUsername(username);

            userAssert.ShouldNotBeNull();

            // Assert
            var repo = new UserRepository();

            var repoUser = repo.Find(u => u.Username == username).FirstOrDefault();

            // Cleanup user
            repo.Delete(repoUser);
            repo.Save();

            var results2 = repo.Find(u => u.Username == username);
            var userFound2 = results2.FirstOrDefault();

            userFound2.ShouldBeNull();
        }
开发者ID:versosystems,项目名称:account-lib,代码行数:36,代码来源:UserServiceTests.cs

示例12: DELRow

 private void DELRow(int id)
 {
     try
     {
         using (var db = new CSBCDbContext())
         {
             var rep = new UserRepository(db);
             var user = new User();
             rep.Delete(rep.GetById(id));
         }
     }
     catch (Exception ex)
     {
         lblError.Text = "DELRow::" + ex.Message;
     }
 }
开发者ID:rsalit,项目名称:CSBC,代码行数:16,代码来源:Users.aspx.cs

示例13: DeleteUser

        public void DeleteUser()
        {
            using (var uow = new CapriconContext())
            {
                var userRep = new UserRepository(uow);
                var existingUser = userRep.Find(u => u.UserId == 2).FirstOrDefault();

                Assert.IsNotNull(existingUser);

                int userId;
                if (existingUser != null)
                {
                    userId = existingUser.UserId;

                    //Delete employee
                    userRep.Delete(existingUser);

                    try
                    {
                        uow.SaveChanges();
                    }
                    catch (DbEntityValidationException ex)
                    {
                        //Retrieve validation errors
                        ex.EntityValidationErrors.ToList().ForEach
                        (
                            v =>
                            {
                                v.ValidationErrors.ToList().ForEach
                                    (
                                        e =>
                                        {
                                            System.Diagnostics.Debug.WriteLine(e.ErrorMessage);
                                        }
                                    );
                            }
                        );
                        Assert.Fail("Test failed");
                    }

                    Assert.IsNull(userRep.Find(u => u.UserId == userId).FirstOrDefault());
                }
                else //no userss were selected
                    Assert.Fail("No user was selected");
            }
        }
开发者ID:shyakaster,项目名称:CARPRICONRELOADED,代码行数:46,代码来源:UserTests.cs


注:本文中的UserRepository.Delete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。