Exemplo n.º 1
0
        private void AddUserToActiveDirectory(NewUserRequests UserRequest)
        {
            try
            {
                string           AdminUserName          = "";
                string           AdminPwd               = "";
                string           NewUserNameOnDomain    = UserRequest.UserName;
                string           NewUserNamePwdOnDomain = UserRequest.UserPassword;
                string           DomainUrl              = "CN=Users,DC=ccasual,DC=loc";
                string           stringDomainName       = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName;
                PrincipalContext PrincipalContext4      = new PrincipalContext(ContextType.Domain,
                                                                               stringDomainName,
                                                                               DomainUrl,
                                                                               ContextOptions.SimpleBind,
                                                                               AdminUserName,
                                                                               AdminPwd);

                UserPrincipal UserPrincipal1 = new UserPrincipal(PrincipalContext4,
                                                                 NewUserNameOnDomain,
                                                                 NewUserNamePwdOnDomain, true);

                //UserPrincipal1.UserPrincipalName = textboxSamAccountName.Text;
                //UserPrincipal1.Name = textboxName.Text;
                //UserPrincipal1.GivenName = textboxGivenName.Text;
                //UserPrincipal1.Surname = textboxSurname.Text;
                //UserPrincipal1.DisplayName = textboxDisplayName.Text;
                //UserPrincipal1.Description = textboxDescription.Text;

                UserPrincipal1.Enabled = true;
                UserPrincipal1.Save();
            }
            catch { }
        }
Exemplo n.º 2
0
        public List <NewUserRequests> GetAllNewUsersRequest()
        {
            List <NewUserRequests> returnResult = new List <NewUserRequests>();

            using (var context = new WorkFlowManagerDBEntities())
            {
                List <TblAddUserRequest> Requests = context.TblAddUserRequests.Where(x => x.Approved == "0" && x.Rejected == "0").ToList();
                foreach (var item in Requests)
                {
                    try
                    {
                        NewUserRequests r = new NewUserRequests();

                        //User Create the Request
                        r.UserCreateRequestID = item.UserCreateRequestID;
                        int UserCreateRequestID = int.Parse(r.UserCreateRequestID);

                        r.UserCreateRequestName = context.TblAuthUsers.FirstOrDefault(x => x.Iserial == UserCreateRequestID).Ename.ToString();

                        //New User Data
                        r.NewUserID        = item.NewUserID;
                        r.UserName         = item.UserName;
                        r.NewUserCompanyID = item.NewUserCompanyID;
                        int _NewUserCompanyID = int.Parse(r.NewUserCompanyID);
                        r.NewUserCompanyName = context.TblCompanies.FirstOrDefault(x => x.Iserial == _NewUserCompanyID).Code;

                        //Like User Data
                        r.LikeUserID        = item.LikeUserID;
                        r.LikeUserName      = context.Employees.FirstOrDefault(x => x.EMPLID == r.LikeUserID).name;
                        r.LikeUserCompanyID = item.NewUserCompanyID;
                        int _LikeUserCompanyID = int.Parse(r.LikeUserCompanyID);
                        r.LikeUserCompanyName = context.TblCompanies.FirstOrDefault(x => x.Iserial == _LikeUserCompanyID).Code;
                        r.Comment             = item.Comment;
                        r.RequestDate         = item.RequestDate.Value;

                        r.IsSalesPerson = item.IsSalesPerson;
                        returnResult.Add(r);
                    }
                    catch (Exception e)
                    {
                        throw new Exception(e.Message);
                    }
                }
            }

            return(returnResult);
        }
Exemplo n.º 3
0
        public int UpdateNewUsersRequest(NewUserRequests UserRequest)
        {
            int    Result = 0;
            string dbName = "";

            TblAuthUser LikeUser = new TblAuthUser();

            using (var context = new WorkFlowManagerDBEntities())
            {
                var currentUserRequest = context.TblAddUserRequests.FirstOrDefault
                                             (x => x.UserCreateRequestID == UserRequest.UserCreateRequestID &&
                                             x.NewUserID == UserRequest.NewUserID & x.NewUserCompanyID == UserRequest.NewUserCompanyID);

                currentUserRequest.Approved    = UserRequest.Approved;
                currentUserRequest.Rejected    = UserRequest.Rejected;
                currentUserRequest.ApproveDate = DateTime.Now;

                /*************************************Approved User*********************************/
                if (currentUserRequest.Approved == "1")
                {
                    LikeUser = context.TblAuthUsers.FirstOrDefault(x => x.PayrollCode == UserRequest.LikeUserID);

                    int _NewUserCompanyID = int.Parse(UserRequest.NewUserCompanyID);
                    dbName = context.TblCompanies.FirstOrDefault(x => x.Iserial == _NewUserCompanyID).DbName;

                    //Create New User Login

                    TblAuthUser CreateNewUser = new TblAuthUser();
                    CreateNewUser.UserName     = currentUserRequest.UserName;
                    CreateNewUser.UserPassword = currentUserRequest.UserPassword;
                    CreateNewUser.Code         = string.Format(@"{0}{1}", currentUserRequest.NewUserID, currentUserRequest.NewUserCompanyID);
                    CreateNewUser.TblCompany   = int.Parse(currentUserRequest.NewUserCompanyID);
                    CreateNewUser.PayrollCode  = currentUserRequest.NewUserID;
                    CreateNewUser.Ename        = currentUserRequest.UserName;
                    CreateNewUser.Aname        = currentUserRequest.UserName;
                    CreateNewUser.TblJob       = LikeUser.TblJob;
                    CreateNewUser.CurrLang     = LikeUser.CurrLang;
                    context.TblAuthUsers.AddObject(CreateNewUser);
                }

                context.SaveChanges();
            }

            if (UserRequest.Approved == "1" && UserRequest.IsSalesPerson == "1")
            {
                Operations.GlOperations.GlService service = new Operations.GlOperations.GlService();
                using (var newContext = new ccnewEntities(service.GetSqlConnectionString(dbName)))
                {
                    TBLSalesPerson newRow = new TBLSalesPerson();

                    int NextSerial = newContext.TBLSalesPersons.Select(x => x.ISerial).Max();
                    newRow.ISerial = NextSerial + 1;
                    newRow.Ename   = UserRequest.UserName;
                    newRow.Aname   = UserRequest.UserName;
                    newRow.Code    = UserRequest.NewUserID;
                    newContext.TBLSalesPersons.AddObject(newRow);
                    if (UserRequest.IsRetailPerson == "1")
                    {
                        TblUser newUser = new TblUser();
                        TblUser oldUser = newContext.TblUsers.FirstOrDefault(x => x.Code == UserRequest.LikeUserID);

                        try
                        {
                            int NextUserSerial = newContext.TblUsers.Select(x => x.iserial).Max();
                            newUser.iserial         = NextUserSerial + 1;
                            newUser.Ename           = UserRequest.UserName;
                            newUser.Aname           = UserRequest.UserName;
                            newUser.Code            = UserRequest.NewUserID;
                            newUser.UserPassword    = UserRequest.UserPassword;
                            newUser.TblJob          = oldUser.TblJob;
                            newUser.Active          = oldUser.Active;
                            newUser.CurrLang        = oldUser.CurrLang;
                            newUser.ReportFont      = oldUser.ReportFont;
                            newUser.ActiveCashMach  = oldUser.ActiveCashMach;
                            newUser.ActiveStore     = oldUser.ActiveStore;
                            newUser.RegNo           = oldUser.RegNo;
                            newUser.AllowedStores   = oldUser.AllowedStores;
                            newUser.AllowedStoresTo = oldUser.AllowedStoresTo;
                            newContext.TblUsers.AddObject(newUser);
                        }
                        catch { }
                    }
                    newContext.SaveChanges();
                }

                AddUserToActiveDirectory(UserRequest);
            }

            return(Result);
        }