Thursday, August 26, 2021

VUE JS drag modal popup

   VUE JS drag modal popup

Reference: https://dev.to/mandrewcito/vue-js-draggable-div-3mee


<template>
  <div ref="draggableContainer" id="draggable-container">
    <div id="draggable-header" @mousedown="dragMouseDown">
      <slot name="header"></slot>
    </div>
    <slot name="main"></slot>
    <slot name="footer"></slot>
  </div>
</template>

<script>
export default {
  name: 'DraggableDiv',
  data: function () {
    return {
      positions: {
        clientX: undefined,
        clientY: undefined,
        movementX: 0,
        movementY: 0
      }
    }
  },
  methods: {
    dragMouseDown: function (event) {
      event.preventDefault()
      // get the mouse cursor position at startup:
      this.positions.clientX = event.clientX
      this.positions.clientY = event.clientY
      document.onmousemove = this.elementDrag
      document.onmouseup = this.closeDragElement
    },
    elementDrag: function (event) {
      event.preventDefault()
      this.positions.movementX = this.positions.clientX - event.clientX
      this.positions.movementY = this.positions.clientY - event.clientY
      this.positions.clientX = event.clientX
      this.positions.clientY = event.clientY
      // set the element's new position:
      this.$refs.draggableContainer.style.top = (this.$refs.draggableContainer.offsetTop - this.positions.movementY) + 'px'
      this.$refs.draggableContainer.style.left = (this.$refs.draggableContainer.offsetLeft - this.positions.movementX) + 'px'
    },
    closeDragElement () {
      document.onmouseup = null
      document.onmousemove = null
    }
  }
}
</script>

<style>
#draggable-container {
  positionabsolute;
  z-index9;
}
#draggable-header {
  z-index10;
}
</style>
====== utilized in main page ==========
<!-- Start:popup code below -->
      <div v-show="msgDialog2class="web_dialog_overlay"></div>
      <DraggableDiv v-show="msgDialog2class="draggable">
    <template slot="header">
      <div class="col-lg-12 popupTitle">
          <div class="row">
            <div
              class="col-lg-11"
              @mousedown="dragMouseDown"
            >
              {{ mdlDialogTitle2 }}
            </div>
            <div class="col-lg-1 text-right">
              <a
                id="closeApproveX"
                v-on:click="showHideMessage2"
                style="cursor: pointer"
                >&#10006;</a
              >
            </div>
          </div>
        </div>
    </template>
    <template slot="main" >
This is main datat
</template>  
</DraggableDiv>

<template>
  <DraggableDiv class="col-11">
    <template slot="header">
      [[[ SOME CONTENT HERE]]]
    </template>
    <template slot="main" >
      [[[ SOME CONTENT HERE]]]
    </template>
    <template slot="footer">
      [[[ SOME CONTENT HERE]]]
    </template>
  </DraggableDiv>
</template>

<script>
import DraggableDiv from './DraggableDiv'
export default {
  components: {
    DraggableDiv
  }
}
</script>

Tuesday, July 27, 2021

CHECK USER IN ACTIVE DIRRECTORY GROUP C#

 CHECK USER IN ACTIVE DIRRECTORY GROUP C#

public static bool EnsureUserInADGroup(string groupName, string userName)

        {

            bool retValue = false;

            try

            {

                userName = userName.Replace(Constants.YZA+ "\\", "");

 

                PrincipalContext ctx = new PrincipalContext(ContextType.Domain, Constants.YZA);

                UserPrincipal user = UserPrincipal.FindByIdentity(ctx, userName);

                GroupPrincipal grp = GroupPrincipal.FindByIdentity(ctx, groupName);

                if (user != null && grp != null)

                    retValue = grp.GetMembers(true).Contains(user);

                grp.Dispose();

            }

            catch (Exception e1)

            { retValue = false; }

            return retValue;

        }


        public static UserPrincipal GetUserDetailsPrincipal(string userName)
        {
            using (var context = new PrincipalContext(ContextType.Domain))
            {
                var usr = UserPrincipal.FindByIdentity(context, userName);
                return usr;
            }
        }

in helper.cs

where you want emp id

UserPrincipal userPrincipal = Helper.GetUserDetailsPrincipal(User.Identity.Name);

userPrincipal.EmployeeId




WINDOWS ACTIVE DIRRECTORY PROPERTIES.


    [HttpPost]

    [Route("GetUserDetails")]

    public ADAttributes GetUserDetails(string empID)

    {

        //string username = User.Identity.Name;

        //username = empID;


        //// Create a PrincipalContext for the domain

        //using (var context = new PrincipalContext(ContextType.Domain, "XYZ.com"))

        //{

        //    // Find the user principal by their identity

        //    var user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, username.Split('\\')[1]);


        //    if (user != null)

        //    {

        //        // Retrieve desired properties


        //        return new AdUserDetails

        //        {

        //            SamAccountName = user.SamAccountName,

        //            DisplayName = user.DisplayName,

        //            EmailAddress = user.EmailAddress

        //        };

        //    }

        //    else

        //        return new AdUserDetails();

        //}

        //---------------

       empID = User.Identity.Name;

        using (var context = new PrincipalContext(ContextType.Domain, "XYZ"))

        {

            var user = UserPrincipal.FindByIdentity(context, empID);


            if (user != null)

            {

                //userProperties.EmpName = user.Name;


                DirectoryEntry sresult = user.GetUnderlyingObject() as DirectoryEntry;


                ADAttributes objAd = new ADAttributes

                {

                    employeeId = sresult.Properties["employeeid"].Count > 0 ? sresult.Properties["employeeid"][0].ToString() : string.Empty,

                    employeeType = sresult.Properties["employeeType"].Count > 0 ? sresult.Properties["employeeType"][0].ToString() : string.Empty,

                    sAMAccountName = sresult.Properties["sAMAccountName"].Count > 0 ? sresult.Properties["sAMAccountName"][0].ToString() : string.Empty,

                    department = sresult.Properties["department"].Count > 0 ? sresult.Properties["department"][0].ToString() : string.Empty,

                    departmentNumber = sresult.Properties["departmentNumber"].Count > 0 ? sresult.Properties["departmentNumber"][0].ToString() : string.Empty,

                    division = sresult.Properties["division"].Count > 0 ? sresult.Properties["division"][0].ToString() : string.Empty,

                    manager = sresult.Properties["manager"].Count > 0 ? sresult.Properties["manager"][0].ToString() : string.Empty,

                    managerSamAcnt = (sresult.Properties.Contains("manager") == true) ? Convert.ToString(sresult.Properties["manager"][0]).Split(',')[0].Split('=')[1] : string.Empty, // Splitting manger name

                    displayName = sresult.Properties["displayName"].Count > 0 ? sresult.Properties["displayName"][0].ToString() : string.Empty,

                    PhysicalDeliveryOfficeName = sresult.Properties["physicalDeliveryOfficeName"].Count > 0 ? sresult.Properties["physicalDeliveryOfficeName"][0].ToString() : string.Empty,

                    mail = sresult.Properties["mail"].Count > 0 ? sresult.Properties["mail"][0].ToString() : string.Empty,

                    memberOf = sresult.Properties["memberOf"].Count > 0 ? sresult.Properties["memberOf"][0].ToString() : string.Empty,

                    userAccountControl = sresult.Properties["userAccountControl"].Count > 0 ? sresult.Properties["userAccountControl"][0].ToString() : string.Empty,

                    givenName = sresult.Properties["givenName"].Count > 0 ? sresult.Properties["givenName"][0].ToString() : string.Empty,

                    objectClass = sresult.Properties["objectClass"].Count > 0 ? sresult.Properties["objectClass"][0].ToString() : string.Empty,

                    postOfficeBox = sresult.Properties["postOfficeBox"].Count > 0 ? sresult.Properties["postOfficeBox"][0].ToString() : string.Empty,

                    telephoneNumber = sresult.Properties["telephoneNumber"].Count > 0 ? sresult.Properties["telephoneNumber"][0].ToString() : string.Empty,

                    uId = sresult.Properties["uId"].Count > 0 ? sresult.Properties["uId"][0].ToString() : string.Empty,

                    Location = sresult.Properties["L"].Count > 0 ? sresult.Properties["L"][0].ToString() : string.Empty,

                    Company = sresult.Properties["Company"].Count > 0 ? sresult.Properties["Company"][0].ToString() : string.Empty,

                    FirstName = sresult.Properties["givenName"].Count > 0 ? sresult.Properties["givenName"][0].ToString() : string.Empty,

                    LastName = sresult.Properties["sn"].Count > 0 ? sresult.Properties["sn"][0].ToString() : string.Empty,

                    co = sresult.Properties["co"].Count > 0 ? sresult.Properties["co"][0].ToString() : string.Empty

                };

                return objAd;

            }

            else

                return new ADAttributes();

        }

    }

}

public class ADAttributes

{

    public string employeeId { get; set; }

    public string employeeType { get; set; }

    public string mail { get; set; }

    public string sAMAccountName { get; set; }

    public string displayName { get; set; }

    public string givenName { get; set; }

    public string manager { get; set; }

    public string memberOf { get; set; }

    public string department { get; set; }

    public string departmentNumber { get; set; }

    public string division { get; set; }

    public string userAccountControl { get; set; }

    public string telephoneNumber { get; set; }

    public string postOfficeBox { get; set; }

    public string PhysicalDeliveryOfficeName { get; set; }

    public string objectClass { get; set; }

    public string uId { get; set; }

    public string domain { get; set; }

    public string Location { get; set; }

    public string Company { get; set; }

    public string FirstName { get; set; }

    public string LastName { get; set; }

    public string managerSamAcnt { get; set; }

    public string ManagerEmail { get; set; }

    public string ManagerLoginName { get; set; }

    public string ManagerDisplayName { get; set; }

    public string ManagerDomain { get; set; }

    public string co { get; set; }

    public string ManagerEmployeeID { get; set; }

    public string ManagerPhoneNumber { get; set; }

}