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


C# UserRepository.Update方法代码示例

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


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

示例1: ChangeInfo

 public ActionResult ChangeInfo(User user)
 {
     userRsy = new UserRepository();
     if(userRsy.Authentication(UserName,Ninesky.Common.Text.Sha256(user.Password))==0)
     {
         var _user = userRsy.Find(UserName);
         _user.Gender = user.Gender;
         _user.Email = user.Email;
         _user.QQ = user.QQ;
         _user.Tel = user.Tel;
         _user.Address = user.Address;
         _user.PostCode = user.PostCode;
         if (userRsy.Update(_user))
         {
             Notice _n = new Notice { Title = "修改资料成功", Details = "您已经成功修改资料!", DwellTime = 5, NavigationName = "用户首页", NavigationUrl = Url.Action("Default", "User") };
             return RedirectToAction("UserNotice", "Prompt", _n);
         }
         else
         {
             Error _e = new Error { Title = "修改资料失败", Details = "在修改用户资料时时,更新的资料未能保存到数据库", Cause = "系统错误", Solution = Server.UrlEncode("<li>返回<a href='" + Url.Action("ChangeInfo", "User") + "'>修改资料</a>页面,输入正确的信息后重新操作</li><li>联系网站管理员</li>") };
             return RedirectToAction("UserError", "Prompt", _e);
         }
     }
     else
     {
         ModelState.AddModelError("Password","密码错误!");
         return View();
     }
 }
开发者ID:Jopix,项目名称:dotnet,代码行数:29,代码来源:UserController.cs

示例2: Find_By_ForgotPassword

        public void Find_By_ForgotPassword()
        {
            IUserRepository userRepository = new UserRepository(this.Client, this.Database);

            User accountUser = new User("name", Guid.NewGuid().ToString(), "password");
            userRepository.Save(accountUser);

            accountUser.ForgotPasswordGuid = Guid.NewGuid();
            userRepository.Update(accountUser);

            User userFound = userRepository.FindByForgotPassword(accountUser.ForgotPasswordGuid);
            Assert.IsNotNull(userFound);
        }
开发者ID:Appacts,项目名称:mobile-analytics-server,代码行数:13,代码来源:UserRepositoryIntegration.cs

示例3: isCanOrder

        public OrderStatus isCanOrder(int pcid, DateTime startTime, int duration, int userId)
        {
            OrderStatus orderstatus = new OrderStatus();
            List<Order> orders = orderRepository.List.Cast<Order>().ToList();

            foreach (Order order in orders)
            {
                if (startTime < order.StartTime && startTime.AddHours(duration) > order.StartTime)
                {
                    orderstatus.status = OrderStatusCode.FAIL;
                    orderstatus.message = "Sorry, this PC have been ordered from " + order.StartTime + " to " + order.StartTime.AddHours(order.Duration);

                    return orderstatus;
                }
                if (startTime >= order.StartTime && startTime <= order.StartTime.AddHours(duration))
                {
                    orderstatus.status = OrderStatusCode.FAIL;
                    orderstatus.message = "Sorry, this PC have been ordered from " + order.StartTime + " to " + order.StartTime.AddHours(order.Duration);

                    return orderstatus;
                }
            }

            List<User> users = userRepository.List.Cast<User>().ToList();
            PC pc = pcRepository.findById(pcid);
            foreach (User user in users)
            {
                if (user.UserID == userId)
                {

                    if (user.Balance < (duration * pc.Price))
                    {
                        orderstatus.status = OrderStatusCode.FAIL;
                        orderstatus.message = "Sorry, your current balance is " + user.Balance + "; can not order " + pc.PCName + " PC";

                        return orderstatus;
                    }
                    else
                    {
                        user.Balance = user.Balance - (duration * pc.Price);
                        IRepository<User> userRepository = new UserRepository();
                        userRepository.Update(user);
                    }
                }
            }

            orderstatus.status = OrderStatusCode.OK;
            orderstatus.message = "True";
            return orderstatus;
        }
开发者ID:AnTTSE61258,项目名称:NetCafeWeb,代码行数:50,代码来源:OrderService.cs

示例4: UpdateUser

        public static BaseActionResult UpdateUser(User obj4update)
        {
            string msg;
            if (obj4update == null)
            {
                msg = string.Format(XiaoluResources.MSG_UPDATE_SUCCESS, XiaoluResources.STR_USER) + string.Format(XiaoluResources.STR_FAIL_RESAON, XiaoluResources.MSG_OBJECT_IS_NULL);
                return new BaseActionResult(false, msg);
            }

            try
            {
                using (var context = new XiaoluEntities())
                {
                    var repository = new UserRepository(context);
                    repository.Update(obj4update);
                    context.SaveChanges();
                    msg = string.Format(XiaoluResources.MSG_UPDATE_SUCCESS, obj4update.Name);
                    return new BaseActionResult(true, msg);
                }
            }
            catch (Exception e)
            {
                msg = string.Format(XiaoluResources.MSG_UPDATE_FAIL, obj4update.Name) + string.Format(XiaoluResources.STR_FAIL_RESAON, ExceptionHelper.GetInnerExceptionInfo(e));
                return new BaseActionResult(false, msg);
            }
        }
开发者ID:neilchennan,项目名称:Xiaolu,代码行数:26,代码来源:BusinessService.User.cs

示例5: UpdateTest

        public void UpdateTest()
        {
            DbContextHelper.Init(typeof(CourseDbContext), GlobalSettings.DATABASE.ConnectionString, 8);

            UserRepository repo = new UserRepository();

            Assert.AreEqual(true, repo.Exists("[email protected]", 1));

            repo.Update(repo.CurrentUser, "d", "d", "d", "password");
        }
开发者ID:soxfmr,项目名称:CourseSystem,代码行数:10,代码来源:UserRepositoryTests.cs

示例6: InitUserProfile

        static string InitUserProfile(string username, string firstname, string lastname, string email, bool createToken)
        {
            var repo = new UserRepository();
            var token = string.Empty;
            var user = repo.GetUser(username);
            if (user != null)
            {
                user.UserProfile.FirstName = firstname;
                user.UserProfile.LastName = lastname;

                //create token for email confirmation
                if (createToken)
                {
                    token = GenerateToken();
                    user.ConfirmationToken = token;
                }
                //otherwise - confirmed
                else
                {
                    user.IsConfirmed = true;
                }

                repo.Update(user);
            }
            return token;
        }
开发者ID:vaadim,项目名称:yatdl,代码行数:26,代码来源:WebSecurity.cs

示例7: GeneratePasswordResetToken

        public static string GeneratePasswordResetToken(string userName)
        {
            if (string.IsNullOrEmpty(userName))
            {
                throw new ArgumentException("Username cannot be empty");
            }

            var repo = new UserRepository();
            var userId = VerifyUserNameHasConfirmedAccount(userName, false);

            var user = repo.GetUserById(userId);

            if (user == null)
                return null;

            if (user.PasswordVerificationTokenExpirationDate.HasValue &&
                user.PasswordVerificationTokenExpirationDate.Value > DateTime.UtcNow)
            {
                return user.PasswordVerificationToken;
            }

            var token = GenerateToken();
            user.PasswordVerificationToken = token;
            user.PasswordVerificationTokenExpirationDate =
                DateTime.UtcNow.AddMinutes(TokenExpirationInMinutesFromNow);

            repo.Update(user);

            return token;
        }
开发者ID:vaadim,项目名称:yatdl,代码行数:30,代码来源:WebSecurity.cs

示例8: AddOrUpdateTheUser

 private static void AddOrUpdateTheUser(User user, UserRepository userRepository)
 {
     var existingUser = userRepository.GetUserByGoogleId(user.GoogleId);
     if (existingUser == null)
     {
         user.CreateDate = DateTimeOffset.Now;
         userRepository.Add(user);
     }
     else
     {
         if (existingUser.DisplayName != user.DisplayName ||
             existingUser.GivenName != user.GivenName ||
             existingUser.FamilyName != user.FamilyName ||
             existingUser.Link != user.Link ||
             existingUser.Picture != user.Picture ||
             existingUser.Gender != user.Gender ||
             existingUser.Locale != user.Locale)
         {
             existingUser.DisplayName = user.DisplayName;
             existingUser.GivenName = user.GivenName;
             existingUser.FamilyName = user.FamilyName;
             existingUser.Link = user.Link;
             existingUser.Picture = user.Picture;
             existingUser.Gender = user.Gender;
             existingUser.Locale = user.Locale;
             existingUser.UpdateDate = DateTimeOffset.Now;
             userRepository.Update(existingUser);
         }
     }
 }
开发者ID:JimGorman17,项目名称:Scouting.RestService,代码行数:30,代码来源:UserService.cs

示例9: UserRepository_Update_ShouldReturnUpdatedEntity

        public void UserRepository_Update_ShouldReturnUpdatedEntity()
        {
            var userToChange = new User()
            {
                Id = 1,
                Email = "mail1",
                Lists = new List<Order>(),
                Name = "name1",
                Password = "password1",
                PhotoPath = "photo1",
            };
            var dbData = new List<User>()
            {
                userToChange,
                new User()
                {
                    Id = 1,
                    Email = "mail1",
                    Lists = new List<Order>(),
                    Name = "name1",
                    Password = "password1",
                    PhotoPath = "photo1",
                },
                new User()
                {
                    Id = 3,
                    Email = "mail3",
                    Lists = new List<Order>(),
                    Name = "name3",
                    Password = "password3",
                    PhotoPath = "photo3",
                }
            }.AsQueryable();

            var newUser = new User()
            {
                Id = 1,
                Email = "mail2",
                Lists = new List<Order>(),
                Name = "name2",
                Password = "password2",
                PhotoPath = "photo2",
            };
            var dbSetMock = new Mock<DbSet<User>>();
            dbSetMock.As<IQueryable<User>>().Setup(x => x.Provider).Returns(dbData.Provider);
            dbSetMock.As<IQueryable<User>>().Setup(x => x.Expression).Returns(dbData.Expression);
            dbSetMock.As<IQueryable<User>>().Setup(x => x.ElementType).Returns(dbData.ElementType);
            dbSetMock.As<IQueryable<User>>().Setup(x => x.GetEnumerator()).Returns(dbData.GetEnumerator());

            var dbContextMock = new Mock<ApplicationDbContext>();
            dbContextMock.Setup(x => x.Set<User>()).Returns(dbSetMock.Object);

            var repo = new UserRepository(dbContextMock.Object);
            var result = repo.Update(newUser);

            Assert.AreEqual(newUser.Name, result.Name);
            Assert.AreEqual(newUser.PhotoPath, result.PhotoPath);
        }
开发者ID:kosinovdaniil,项目名称:kosinov-klimchuk-task,代码行数:58,代码来源:RepositoryTests.cs

示例10: ChangePassword

        public async Task<dynamic> ChangePassword([FromBody] JToken jsonbody)
        {
            if (jsonbody == null || jsonbody.Type != JTokenType.Object)
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid data."));

            //check data
            var userId = jsonbody.SelectToken("id");
            if (userId == null || string.IsNullOrWhiteSpace(userId.ToString()))
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "id is missed."));

            var newPassword = jsonbody.SelectToken("newpassword");
            if (newPassword == null || string.IsNullOrWhiteSpace(newPassword.ToString()))
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "new password is missed."));

            var userRepo = new UserRepository();
            var userEntity = await userRepo.GetByID(userId.ToString());
            if(userEntity == null)
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid id."));

            userEntity.Password = Encryptor.GetInstance().Encrypt(newPassword.ToString());
            userRepo.Update(userEntity);

            return Ok();
        }
开发者ID:pdlg-spotlight,项目名称:lambda-architecture,代码行数:24,代码来源:AccountController.cs

示例11: UpdateUserProfile

        public async Task<dynamic> UpdateUserProfile([FromBody] JToken jsonbody)
        {
            if (jsonbody == null || jsonbody.Type != JTokenType.Object)
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid data."));

            var userId = jsonbody.SelectToken("id");
            if (userId == null || string.IsNullOrWhiteSpace(userId.ToString()))
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Id is missed."));

            //check if user exists or not
            var userRepo = new UserRepository();
            var userEntity = await userRepo.GetByID(userId.ToString());
            if (userEntity == null)
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "User does not exist."));

            //save to db
            var displayName = jsonbody.SelectToken("displayname");
            if (displayName != null)
            {
                userEntity.DisplayName = displayName.ToString();
            }

            var options = (JObject)jsonbody.SelectToken("options");
            if (options != null)
            {
                if(userEntity.Options == null)
                    userEntity.Options = new Dictionary<string, string>();

                foreach (var jProperty in options.Properties())
                {
                    if (userEntity.Options.ContainsKey(jProperty.Name))
                    {
                        userEntity.Options.Remove(jProperty.Name);
                    }
                    userEntity.Options.Add(jProperty.Name, jProperty.Value.ToString());
                }
            }

            userRepo.Update(userEntity);

            return Ok();
        }
开发者ID:pdlg-spotlight,项目名称:lambda-architecture,代码行数:42,代码来源:AccountController.cs

示例12: ApproveUser

 /// <summary>
 /// 审核通过一个用户
 /// </summary>
 /// <param name="userId"></param>
 /// <param name="replyContent"></param>
 public void ApproveUser(string userId,string replyContent)
 {
     using (UserRepository userRepository = new UserRepository())
     {
         User user=userRepository.FindByID(userId);
         if (user == null)
             throw new Exception("用户不存在");
         user.ApproveStatus = EnumUserApproveStatus.Approved;
         user.ReplyContent = replyContent;
         userRepository.Update(user);
     }
 }
开发者ID:hiyouth,项目名称:R2.RRDL,代码行数:17,代码来源:Register.cs

示例13: SetUserGroup

 /// <summary>
 /// 为一个用户分配分组
 /// </summary>
 /// <param name="userId"></param>
 /// <param name="groupId"></param>
 public void SetUserGroup(string userId, int groupId)
 {
     using (UserGroupRepository groupRepository = new UserGroupRepository())
     {
         UserGroup group = groupRepository.ExecuteConditions(g => g.Id == groupId).
             FirstOrDefault();
         if (group == null)
             throw new Exception("指定分组不存在");
     }
     using (UserRepository userRepository = new UserRepository())
     {
         User user = userRepository.FindByID(userId);
         if (user == null)
             throw new Exception("用户不存在");
         if (user.ApproveStatus == EnumUserApproveStatus.Approved)
         {
             user.ContentGroupId = groupId;
             userRepository.Update(user);
         }
         else
         {
             throw new Exception("当前用户还未通过审核,无法为其分配分组");
         }
     }
 }
开发者ID:hiyouth,项目名称:R2.RRDL,代码行数:30,代码来源:Register.cs

示例14: UpdRow

        private void UpdRow(long RowID)
        {
            using (var db = new CSBCDbContext())
            {
                try
                {
                    var rep = new UserRepository(db);
                    var user = new User();

                    user.HouseID = Convert.ToInt32(lblHouseID.Text);
                    user.Name = txtName.Text;
                    user.UserName = txtUserName.Text;
                    user.UserType = (Convert.ToInt32(radioUserType.SelectedValue));
                    user.PWord = txtPWord.Text;
                    user.CreatedUser = Master.UserName;
                    //user.Roles = GetRoles();
                    rep.Update(user);
                }
                catch (Exception ex)
                {
                    Session["ErrorMSG"] = "UpdRow::" + ex.Message;
                }
            }
        }
开发者ID:rsalit,项目名称:CSBC,代码行数:24,代码来源:Users.aspx.cs

示例15: Update_Entity_Test

        public static void Update_Entity_Test()
        {
            const string operadorNameAtualizado = "Operador Teste Update";
            IUserRepository repository = new UserRepository(_session);
            User operador = new User
            {
                Login = "Operador Teste",
                Name = "Operador Teste",
                Password = "Password",
            };

            repository.Insert(operador);

            User operadorBd = repository.GetAll().First();
            operadorBd.Name = operadorNameAtualizado;

            repository.Update(operadorBd);

            operadorBd = repository.GetAll().First();

            Assert.AreEqual(operadorNameAtualizado, operadorBd.Name);
        }
开发者ID:icarocamelo,项目名称:iLunchWeb,代码行数:22,代码来源:RepositoryTests.cs


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