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


C# UserRepository.SaveChanges方法代码示例

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


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

示例1: ChangeStatus

        public string ChangeStatus()
        {
            string result = "";
            try
            {
                int id = 0;
                int.TryParse(Request["id"], out id);
                byte status = 0;
                byte.TryParse(Request["status"], out status);
                var repo = new UserRepository();
                var v = repo.GetByID(id);
                if (v != null)
                {
                    v.RecordStatus = status;
                    repo.SaveChanges();
                }
                result = JsonResult(true, Resources.Messages.StatusChanged);
            }
            catch (Exception ex)
            {
                result = JsonResult(false, ex.Message);
            }

            return result;
        }
开发者ID:mujassir,项目名称:vehicle_git_ivan,代码行数:25,代码来源:ManageUsers.aspx.cs

示例2: 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

示例3: InsertUserCheckUnique

 public void InsertUserCheckUnique()
 {
     var unitOfWork = new UnitOfWork<GenericRepositoryTestContext>();
     var user = new User
     {
         Email = "[email protected]",
         Name = "Wim Pool"
     };
     var userRepo = new UserRepository(unitOfWork);
     userRepo.Add(user);
     try
     {
         userRepo.SaveChanges();
     }
     catch (DbEntityValidationException validationException)
     {
         foreach (var error in validationException.EntityValidationErrors)
         {
             Assert.IsTrue(error.ValidationErrors.Count == 1);
             Assert.AreEqual(error.ValidationErrors.First().ErrorMessage, "NotUnique");
             Assert.AreEqual(error.ValidationErrors.First().PropertyName, "Email");
         }
     }
     var users = userRepo.FindBy(u => u.Email == "[email protected]");
     Assert.IsTrue(users.Count() == 1);
 }
开发者ID:WimAtIHomer,项目名称:GenericRepository,代码行数:26,代码来源:UniqueTests.cs

示例4: RemoveCommentFromUserException

        public void RemoveCommentFromUserException()
        {
            var unitOfWork = new UnitOfWork<GenericRepositoryTestContext>();
            var userRepo = new UserRepository(unitOfWork);
            var user = userRepo.GetFirst(u => u.Email == "[email protected]");
            var comment = user.Comments.FirstOrDefault();
            user.Comments.Remove(comment);

            userRepo.SaveChanges();
        }
开发者ID:WimAtIHomer,项目名称:GenericRepository,代码行数:10,代码来源:ParentTests.cs

示例5: RemoveCommentFromPost

        public void RemoveCommentFromPost()
        {
            var unitOfWork = new UnitOfWork<GenericRepositoryTestContext>();

            Assert.IsTrue(unitOfWork.Entities.Comments.Count() == 2);

            var userRepo = new UserRepository(unitOfWork);
            var user = userRepo.GetFirst(u => u.Email == "[email protected]");
            var post = user.Posts.FirstOrDefault();
            Debug.Assert(post != null, "post != null");
            var comment = post.Comments.FirstOrDefault(c => c.User == user);
            post.Comments.Remove(comment);
            userRepo.SaveChanges();

            Assert.IsTrue(unitOfWork.Entities.Comments.Count() == 1);
        }
开发者ID:WimAtIHomer,项目名称:GenericRepository,代码行数:16,代码来源:ParentTests.cs

示例6: Main

 static void Main(string[] args)
 {
     using (var context = new CmsDBcontext())
     {
         UserRepository repository = new UserRepository(context);
         var userRoleRepository = new Repository<UserRole>(context);
         var role = userRoleRepository.GetById(2);
         repository.RegisterInsert(new User()
         {
             NickName = "xuyy",
             Sex = false,
             Password = "123456",
             Role = role
         });
         repository.RegisterInsert(new User()
         {
             NickName = "liuyin",
             Sex = false,
             Password = "123456",
             Role = role
         });
         repository.SaveChanges();
     }
 }
开发者ID:xiongkailing,项目名称:MyBlog,代码行数:24,代码来源:Program.cs

示例7: Save

        public string Save()
        {
            string result = "";
            try
            {
                var repo = new UserRepository();
                var userInput = JsonConvert.DeserializeObject<DAL.User>(Request["user"]);
                if (userInput != null)
                {
                    if (repo.IsExist(userInput.ID, userInput.UserName))
                        return JsonResult(false, "1");
                    else
                    {

                        if (userInput.ID == 0)
                            repo.Add(userInput);
                        else
                        {

                            var user = repo.GetByID(userInput.ID);
                            if (user != null)
                            {
                                user.UserName = userInput.UserName;
                                user.RoleID = userInput.RoleID;
                                user.RoleName = userInput.RoleName;
                                if (userInput.Password + "" != "")
                                    user.Password = userInput.Password;
                                repo.SaveChanges();

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


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