protected void btnUpdate_Click(object sender, EventArgs e)
    {
        var idWindows = WindowsIdentity.GetCurrent();
        // The WindowsPrincipal object contains the current user's Group membership.
        var    prinWindows = new WindowsPrincipal(idWindows);
        var    domainUser  = idWindows.Name;
        string firstName   = Environment.UserName;
        string lastName    = string.Empty;//prinWindows.Identity.Name;//TODO
        string email       = string.Empty;

        GetDomainInfo(ref firstName, ref lastName, ref email);

        using (var db = new HRPaidTimeOffDataContext())
        {
            //Create a ENTUserAccount object and set the properties
            var userAccount = new ENTUserAccount
            {
                WindowsAccountName = @domainUser,
                FirstName          = firstName,
                LastName           = lastName,
                Email                  = email,
                IsActive               = false,
                UpdateDate             = DateTime.Now,
                UpdateENTUserAccountId = 1
            };
            userAccount.ENTUserAccountId = Convert.ToInt32(ViewState["ENTUserAccountId"]);
            userAccount.Version          = (Binary)ViewState["Version"];
            db.ENTUserAccounts.Attach(userAccount, true);
            db.SubmitChanges();
        }
    }
    protected void btnInsert_Click(object sender, EventArgs e)
    {
        //Create an instance of the data context
        using (var db = new HRPaidTimeOffDataContext())
        {
            var idWindows = WindowsIdentity.GetCurrent();
            // The WindowsPrincipal object contains the current user's Group membership.
            var    prinWindows = new WindowsPrincipal(idWindows);
            var    domainUser  = idWindows.Name;
            string firstName   = Environment.UserName;
            string lastName    = string.Empty;//prinWindows.Identity.Name;//TODO
            string email       = string.Empty;

            GetDomainInfo(ref firstName, ref lastName, ref email);

            //Create a new ENTUserAccount object and set the properties
            var userAccount = new ENTUserAccount
            {
                WindowsAccountName = domainUser,
                FirstName          = firstName,           //"FirstName",
                LastName           = lastName,            //"LastName",
                Email                  = email,
                IsActive               = true,
                InsertDate             = DateTime.Now,
                InsertENTUserAccountId = 1,
                UpdateDate             = DateTime.Now,
                UpdateENTUserAccountId = 1
            };

            //Signal the context to insert this record
            db.ENTUserAccounts.InsertOnSubmit(userAccount);
            //Save the changes to the database
            db.SubmitChanges();
        }
    }
Пример #3
0
 protected override void MapEntityToCustomProperties(IENTBaseEntity entity)
 {
     ENTUserAccount userAccount = (ENTUserAccount)entity;
     ID = userAccount.ENTUserAccountId;
     WindowAccountName = userAccount.WindowsAccountName;
     FirstName = userAccount.FirstName;
     LastName = userAccount.LastName;
     Email = userAccount.Email;
     IsActive = userAccount.IsActive;
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     using (var db = new HRPaidTimeOffDataContext())
     {
         ENTUserAccount userAccount = db.ENTUserAccounts.FirstOrDefault(ua => ua.WindowsAccountName == @"admin");//ENTUserAccounts.FirstOrDefault();
         ViewState["ENTUserAccountId"]       = userAccount.ENTUserAccountId;
         ViewState["InsertENTUserAccountId"] = userAccount.InsertENTUserAccountId;
         ViewState["InsertDate"]             = userAccount.InsertDate;
         ViewState["Version"] = userAccount.Version;
     }
 }
 protected void btnDelete_Click(object sender, EventArgs e)
 {
     using (var db = new HRPaidTimeOffDataContext())
     {
         //Create a ENTUserAccount object and set the properties
         var userAccount = new ENTUserAccount();
         userAccount.ENTUserAccountId = Convert.ToInt32(ViewState["ENTUserAccountId"]);
         userAccount.Version          = (Binary)ViewState["Version"];
         db.ENTUserAccounts.Attach(userAccount);
         db.ENTUserAccounts.DeleteOnSubmit(userAccount);
         db.SubmitChanges();
     }
 }