用户

时间:2016-08-20 15:14:24

标签: c# asp.net webforms

我遇到了实体和保存的问题我想更新记录的值,所以我正在执行以下操作。

我在其他的oens中使用以下内容但是它在这里没有工作的某些原因来保存记录它说密钥已经存在。

_dal.portalEntities.Entry(_custInfo).State = System.Data.Entity.EntityState.Modified;
_dal.portalEntities.SaveChanges();
_dal.portalEntities.Entry(_custInfo).Reload();

这是我的主要例程

tblPortalUser _users; 
_users = _dal.GetUserRecordByEmail(_myuser.EmailAddress.ToLower());
//password is the same warn the user as current 
 if (PasswordHash.ValidatePassword(password.Text, _users.password) == true)
{    
    lblerror.Text = "Password choose a password you have not used before";
    }else
 lblerror.Text = "Current Password is invalid.";
            // if password is the same as the confirm password then proceed if not warn the user
 if (password.Text == confirmpass.Text)
 {
   _users.password = PasswordHash.HashPassword(password.Text);
  _dal.portalEntities.SaveChanges();
 //lets send out the verification codes for the email and sms
   _notifications.sendNotification(new Guid(portalbl.BLConstants.resetPasswordEmail), _custInfo.firstName + " " + _custInfo.lastName, "", _custInfo.email.ToLower(), "", "", portalbl.BLConstants.portalNotifications.Email, "");
 Response.Redirect(@"~\myaccount\logout.aspx", false);
 }

GetUserRecordByEmail

public tblPortalUser GetUserRecordByEmail(string Email)
    {
        try
        {
            tblPortalUser _user;

            _user = (from _users in _dal.portalEntities.tblPortalUsers
                     where _users.EmailAddress.ToLower() == Email
                     select _users).FirstOrDefault();


            return _user;
        }
        catch (Exception ex)

        {
            string inner = string.Empty;
            if (ex.InnerException != null)
            {
                inner = ex.InnerException.ToString();
            }
            return null;
        }
    }

修改1 例外情况在这里显示抱歉我不知道在得分低于10时如何包含没有链接的图像

https://snag.gy/QMSzaE.jpg

1 个答案:

答案 0 :(得分:0)

从屏幕截图中,异常是明确的,您首先需要分离用户并再次附加它,它将起作用

请看这篇文章:Attaching and Detaching Objects