How to Update Employee and Identity User with one to one/zero relation

后端 未结 2 1364
陌清茗
陌清茗 2021-01-28 16:45

I am trying to update employee record and want to update identity user too.

If i update Identity User first separately For Example:

UserManager.Update(u         


        
2条回答
  •  情书的邮戳
    2021-01-28 17:27

    The User employee service should be

    public bool UpdateEmployee(Employee employee)
    {
        var existingEmployee = Context.Emplyoees.FirstOrDefault(s => s.Id == employee.Id);
        if (existingEmployee != null)
        {
            //do the update to the database 
            Context.Entry(existingEmployee).CurrentValues.SetValues(employee);
            Context.Entry(existingEmployee).State = System.Data.Entity.EntityState.Modified;
            return Context.SaveChanges() > 0;
        }
        else return false;
    }
    

提交回复
热议问题