Exemple #1
0
        public ActionResult Add(Employee employee)
        {
            if (ModelState.IsValid)
            {
                // if employee already exists, use the employee in database to update data
                int count = storeDB.Employee.Count(s => s.LDAP == employee.LDAP);
                if (count == 0)
                {
                    // add LDAP information
                    if (updateLDAPInfo(employee))
                    {
                        // save to database
                        storeDB.AddToEmployee(employee);
                        storeDB.SaveChanges();
                        ViewData["message"] = employee.LDAP + " has been added!";
                    }
                    else
                    {
                        ViewData["message"] = "Alias Not Found!";
                    }
                }
                else
                {
                    ViewData["message"] = "Alias already exist in DOSB system.";
                }

                RedirectToAction("index", "Employee");
            }

            var viewModel = new EmployeeManagerViewModel
            {
                Employee = employee,
                SubSegments = storeDB.Segment.Where(s => s.ParentId == 4).ToList()
            };
            return View(viewModel);
        }
Exemple #2
0
 /// <summary>
 /// Create a new Employee object.
 /// </summary>
 /// <param name="employeeId">Initial value of the EmployeeId property.</param>
 public static Employee CreateEmployee(global::System.Int32 employeeId)
 {
     Employee employee = new Employee();
     employee.EmployeeId = employeeId;
     return employee;
 }
Exemple #3
0
        //
        // update
        private bool updateLDAPInfo(Employee employee)
        {
            try
            {
                DirectoryEntry entry = new DirectoryEntry();
                entry.Path = "LDAP://ldap.slb.com/o=slb,c=an";
                entry.AuthenticationType = AuthenticationTypes.SecureSocketsLayer;
                DirectorySearcher searcher = new DirectorySearcher(entry);
                searcher.Filter = "(alias=" + employee.LDAP + ")";
                searcher.SearchScope = SearchScope.Subtree;
                SearchResult result = searcher.FindOne();
                if (result == null) return false;
                DirectoryEntry employeeEntry = result.GetDirectoryEntry();
                employee.Avatar = (byte[])employeeEntry.Properties["jpegPhoto"][0];
                employee.SurName = (string)employeeEntry.Properties["surname"][0];
                employee.GivenName = (string)employeeEntry.Properties["givenName"][0];
                employee.GIN = (string)employeeEntry.Properties["employeeNumber"][0];
                if (String.IsNullOrEmpty(employee.Status))
                {
                    employee.Status = "Base";
                }
                if (employeeEntry.Properties.Contains("mobile"))
                {
                    employee.Mobile = (string)employeeEntry.Properties["mobile"][0];
                }
                if (employeeEntry.Properties.Contains("personalMobile"))
                {
                    employee.PersonalMobile = (string)employeeEntry.Properties["personalMobile"][0];
                }
                string businessCategory = (string)employeeEntry.Properties["businessCategory"][0];
                try
                {
                    Segment subSegment = storeDB.Segment.Single(s => s.BusinessCategory == businessCategory);
                    if (subSegment != null)
                    {
                        employee.Segment = subSegment;
                    }
                }
                catch (Exception e)
                {
                    ViewData["ldap_message"] = "This LDAP is not RMC, CC or SMS";
                    return false;
                }

                //string fileName = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "\\" + employee.LDAP + ".jpg";
                //if (System.IO.File.Exists(fileName))
                //{
                //    FileStream fileStream = new FileStream(fileName, FileMode.Open);
                //    byte[] buff = new byte[2048];
                //    fileStream.Read(buff, 0, (int)fileStream.Length);
                //    employee.Avatar = buff;
                //    fileStream.Close();
                //}
                //else
                //{
                //    return false;
                //}
            }
            catch (System.Runtime.InteropServices.COMException ne)
            {
                ViewData["ldap_message"] = "LDAP ERROR: " + ne.Message + " [" + ne.ErrorCode + "]";
            }

            return true;
        }
Exemple #4
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Employee EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToEmployee(Employee employee)
 {
     base.AddObject("Employee", employee);
 }