public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            var userManager = context.OwinContext.GetUserManager <ApplicationUserManager>();

            ApplicationUser user = await userManager.FindAsync(context.UserName, context.Password);

            if (user == null)
            {
                context.SetError("invalid_grant", "The Employee Id or password is incorrect.");
                return;
            }

            ClaimsIdentity oAuthIdentity = await user.GenerateUserIdentityAsync(userManager,
                                                                                OAuthDefaults.AuthenticationType);

            ClaimsIdentity cookiesIdentity = await user.GenerateUserIdentityAsync(userManager,
                                                                                  CookieAuthenticationDefaults.AuthenticationType);

            LogicActivity logic = new LogicActivity();

            AuditTrialReport.SaveAuditReport(user.UserName, "Login", null, null);

            AuthenticationProperties properties = CreateProperties(logic.getUserName(user.UserName), user.UserName);
            AuthenticationTicket     ticket     = new AuthenticationTicket(oAuthIdentity, properties);

            context.Validated(ticket);
            context.Request.Context.Authentication.SignIn(cookiesIdentity);
        }
        public async Task <IHttpActionResult> Register([FromBody] RegisterEmployee model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = new ApplicationUser()
            {
                UserName = model.EmployeeId, Email = model.Email
            };

            IdentityResult result = await UserManager.CreateAsync(user, "123456789");

            if (!result.Succeeded)
            {
                return(GetErrorResult(result));
            }

            try
            {
                SaveUpdateActivities activity = new SaveUpdateActivities();
                LogicActivity        logic    = new LogicActivity();
                DataBind             da       = activity.SaveUpdateEmployee(new Employee
                {
                    EmployeeId    = model.EmployeeId,
                    EmployeeName  = model.EmployeeName,
                    DesignationId = model.DesignationId,
                    SectionId     = model.SectionId,
                    Email         = model.Email,
                    JoiningDate   = model.JoiningDate,
                    ReportTo      = model.ReportTo,
                    Location      = model.Location,
                    GroupName     = model.GroupId,
                    RoleId        = model.RoleId
                });

                UserManager.AddToRoles(user.Id, model.AccessPermission.ToArray());

                var beforData = logic.getEmployee(model.EmployeeId, model.AccessPermission.ToArray());

                var dataAfter = new { Info = beforData, AccessList = model.AccessPermission };

                string data = JsonConvert.SerializeObject(dataAfter);


                AuditTrialReport.SaveAuditReport(User.Identity.Name, "Insert", null, data);
            }
            catch (Exception ev)
            {
                return(BadRequest(ev.ToString()));
            }

            return(Ok("Successfully added Employee with default password"));
        }