Ejemplo n.º 1
0
        public async Task <string> CreateNewUserAsync(EmployeeDTO ADUser)
        {
            try
            {
                Employee        user            = new Employee();
                EmployeeProfile employeeProfile = Context.EmployeeProfile.Where(x => x.Empcode == ADUser.Empcode).FirstOrDefault();
                DbPosition      dbPosition      = Context.DbPosition.Where(x => x.PositionName == ADUser.Position).FirstOrDefault();

                user.Empcode      = ADUser.Empcode;
                user.Username     = ADUser.Username;
                user.Passwordsalt = EncryptionService.GeneratePasswordSalt();
                user.Password     = EncryptionService.HashToMD5(ADUser.Password + user.Passwordsalt);

                user.Active = true;
                user.CrBy   = "LDAP";
                user.CrDate = DateTime.Now;

                Context.Employee.Add(user);
                Context.SaveChanges();

                if (employeeProfile == null)
                {
                    employeeProfile.Empcode     = ADUser.Empcode;
                    employeeProfile.FirstnameTh = ADUser.FirstnameEn;
                    employeeProfile.LastnameEn  = ADUser.LastnameEn;
                    employeeProfile.Tel         = ADUser.Tel;
                    employeeProfile.Email       = ADUser.Email;
                    employeeProfile.Position    = ADUser.Position;

                    if (dbPosition != null)
                    {
                        employeeProfile.PositionCode = dbPosition.PositonCode;
                    }

                    Context.EmployeeProfile.Add(employeeProfile);
                    Context.SaveChanges();
                }


                //TOKEN
                tokens.empCode      = ADUser.Empcode;
                tokens.Username     = ADUser.Username;
                tokens.Firstname    = ADUser.FirstnameEn;
                tokens.Lastname     = ADUser.LastnameEn;
                tokens.PositionCode = dbPosition.PositonCode;
                tokens.Token        = GenerateToken(user.Empcode);

                return(user.Empcode);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 2
0
 public void Mockdata()
 {
     foreach (var entity in Context.RunningType)
     {
         Context.RunningType.Remove(entity);
     }
     Context.SaveChanges();
     Context.RunningType.Add(new RunningType()
     {
         Code            = "01",
         Name            = "Username",
         RunningNoFormat = "{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}[RUNNING]",
         RunningNoDigit  = 8,
         Active          = true,
         CreatedBy       = "System",
         CreatedDate     = DateTime.Parse("5/1/2008 8:30:52 AM", System.Globalization.CultureInfo.InvariantCulture)
     });
     Context.SaveChanges();
 }
Ejemplo n.º 3
0
 public void MockDataToDB()
 {
     foreach (var entity in Context.Authentication)
     {
         Context.Authentication.Remove(entity);
     }
     Context.SaveChanges();
     Context.Authentication.Add(new Authentication()
     {
         Username           = "******",
         Password           = "******",//password = test
         PasswordSalt       = "test",
         Firstname          = "test",
         Lastname           = "test",
         Email              = "*****@*****.**",
         Active             = true,
         FailTime           = 0,
         PasswordExpiryDate = DateTime.Now.AddYears(1),
         SystemCode         = "US00000001",
         CreatedBy          = "System",
         CreatedDate        = DateTime.Parse("5/1/2008 8:30:52 AM", System.Globalization.CultureInfo.InvariantCulture)
     });
     Context.SaveChanges();
 }
Ejemplo n.º 4
0
 public string CreateRunningType(RuRunningType RunningType)
 {
     try
     {
         RuRunningType runningType = new RuRunningType();
         runningType.Code            = RunningType.Code;
         runningType.Name            = RunningType.Name;
         runningType.RunningNoFormat = "{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}[RUNNING]";
         runningType.RunningNoDigit  = RunningType.RunningNoDigit;
         runningType.Active          = true;
         runningType.CreatedBy       = "System";
         runningType.CreatedDate     = DateTime.Now;
         Context.RuRunningType.Add(runningType);
         Context.SaveChanges();
         return(runningType.Code);
     }
     catch (Exception ex) {
         throw ex;
     }
 }
Ejemplo n.º 5
0
        public RuRunningNo CreateRunningNo(RuRunningType runningType, params string[] parameter)
        {
            int         Count         = parameter.Length;
            RuRunningNo CreateRunning = new RuRunningNo();

            CreateRunning.RunningTypeCode = runningType.Code;
            if (Count > 0 && Count <= parameter.Length)
            {
                if (Count >= 1)
                {
                    if (!string.IsNullOrWhiteSpace(parameter[0]))
                    {
                        CreateRunning.Parameter1 = parameter[0];
                    }
                }
                if (Count >= 2)
                {
                    if (!string.IsNullOrWhiteSpace(parameter[1]))
                    {
                        CreateRunning.Parameter2 = parameter[1];
                    }
                }
                if (Count >= 3)
                {
                    if (!string.IsNullOrWhiteSpace(parameter[2]))
                    {
                        CreateRunning.Parameter3 = parameter[2];
                    }
                }
                if (Count >= 4)
                {
                    if (!string.IsNullOrWhiteSpace(parameter[3]))
                    {
                        CreateRunning.Parameter4 = parameter[3];
                    }
                }
                if (Count >= 5)
                {
                    if (!string.IsNullOrWhiteSpace(parameter[4]))
                    {
                        CreateRunning.Parameter5 = parameter[4];
                    }
                }
                if (Count >= 6)
                {
                    if (!string.IsNullOrWhiteSpace(parameter[5]))
                    {
                        CreateRunning.Parameter6 = parameter[5];
                    }
                }
                if (Count >= 7)
                {
                    if (!string.IsNullOrWhiteSpace(parameter[6]))
                    {
                        CreateRunning.Parameter7 = parameter[6];
                    }
                }
                if (Count >= 8)
                {
                    if (!string.IsNullOrWhiteSpace(parameter[7]))
                    {
                        CreateRunning.Parameter8 = parameter[7];
                    }
                }
                if (Count >= 9)
                {
                    if (!string.IsNullOrWhiteSpace(parameter[8]))
                    {
                        CreateRunning.Parameter9 = parameter[8];
                    }
                }
                if (Count >= 10)
                {
                    if (!string.IsNullOrWhiteSpace(parameter[9]))
                    {
                        CreateRunning.Parameter10 = parameter[9];
                    }
                }
            }
            CreateRunning.RunningNo   = 0;
            CreateRunning.Active      = true;
            CreateRunning.CreatedBy   = "Ru";
            CreateRunning.CreatedDate = DateTime.Now;
            Context.RuRunningNo.Add(CreateRunning);
            Context.SaveChanges();
            return(CreateRunning);
        }