static public void FromADtoBD() { userdbContext db = new userdbContext(); try { string domain = "isea.ru"; DirectoryEntry adRoot = new DirectoryEntry("LDAP://" + domain, null, null, AuthenticationTypes.Secure); DirectorySearcher search = new DirectorySearcher(adRoot); search.Filter = "(&(objectClass=user)(objectCategory=person))"; search.PropertiesToLoad.Add("samaccountname"); search.PropertiesToLoad.Add("mail"); search.PropertiesToLoad.Add("memberOf"); search.PropertiesToLoad.Add("displayname");//first name SearchResult result; SearchResultCollection resultCol = search.FindAll(); if (resultCol != null) { for (int counter = 0; counter < resultCol.Count; counter++) { result = resultCol[counter]; if (result.Properties.Contains("samaccountname") && result.Properties.Contains("mail") && result.Properties.Contains("displayname") && result.Properties.Contains("memberOf")) { string groups = (String)result.Properties["memberOf"][0]; groups = groups.Replace("CN=", "").Replace("OU=БГУЭП","").Replace("DC=isea","").Replace("DC=ru","").Replace("OU=",""); db.Ad_users.Add(new Ad_users() { Email = (String)result.Properties["mail"][0], UserName = (String)result.Properties["samaccountname"][0], DisplayName = (String)result.Properties["displayname"][0], role = "", group = groups } ); } } db.SaveChanges(); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } }
/// <summary> /// для заведения Заявок вывод запросов из БД во время заведения /// </summary> public ActionResult WhomUserClaimFromAD(string term) { using (userdbContext db = new userdbContext()) { var DisplayName1 = db.Ad_users .Where(c => c.DisplayName.StartsWith(term)) .Select(c => c.DisplayName) .AsEnumerable() .Distinct() .Take(10) .ToList(); if (DisplayName1.Count > 0) { System.Diagnostics.Debug.WriteLine(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> " + DisplayName1.Count); return Json(DisplayName1, JsonRequestBehavior.AllowGet); } var userName1 = db.Ad_users .Where(c => c.UserName.StartsWith(term)) .Select(c => c.UserName) .AsEnumerable() .Distinct() .Take(10) .ToList(); if (userName1.Count > 0) { return Json(userName1, JsonRequestBehavior.AllowGet); } var groupName = db.Ad_users .Where(c => c.group.Contains(term)) .Select(c => c.group) .AsEnumerable() .Distinct() .Take(10) .ToList(); if (groupName.Count > 0) { return Json(groupName, JsonRequestBehavior.AllowGet); } } return Json("пользователь не найден", JsonRequestBehavior.AllowGet); }
//выборка названия заявок заявок и времени закрытия public ActionResult ClaimeName(string term) { //return Json("тип заявки не найден", JsonRequestBehavior.AllowGet); using (userdbContext db = new userdbContext()) { var ClaimName = db.ClaimeName .Where(c => c.claimName.Contains(term)) .Select(c => c.claimName) .AsEnumerable() .Distinct() .Take(10) .ToList(); if (ClaimName.Count > 0) { System.Diagnostics.Debug.WriteLine(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> " + ClaimName.Count); return Json(ClaimName, JsonRequestBehavior.AllowGet); } return Json("тип заявки не найден", JsonRequestBehavior.AllowGet); } }
/// <summary> /// фильтр логов кто куда ходил и когда /// </summary> /// <param name="filterContext"></param> public override void OnActionExecuting(ActionExecutingContext filterContext) { userdbContext db = new userdbContext(); var request = filterContext.HttpContext.Request; //logs log = new logs() //{ // dataTime = DateTime.Now, // events = "зашел на эту страницу", // UserName = "******", // pc_ip = PC.GetIPAddress(), // pc_name = System.Net.Dns.GetHostName(), // Url = request.RawUrl //}; //using (userdbContext db = new userdbContext()) //{ // db.logs.Add(log); // db.SaveChanges(); //} try { db.logs.Add(new logs() { dataTime = DateTime.Now, events = "зашел на эту страницу", UserName = (request.IsAuthenticated) ? filterContext.HttpContext.User.Identity.Name : "null", pc_ip = PC.GetIPAddress(), pc_name = System.Net.Dns.GetHostName(), Url = request.RawUrl }); db.SaveChanges(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } }
public ActionResult DataTimeEnd(string date_end) { // dataTimeEnd = "fffff"; System.Diagnostics.Debug.WriteLine("aaaaaaaaaa " + date_end); using (userdbContext db = new userdbContext()) { var dataTimeEn = db.ClaimeName .Where(c => c.claimName == date_end) .Select(c => c.dataEndClaim) .AsEnumerable() .Distinct() .Take(10) .ToList(); System.Diagnostics.Debug.WriteLine("rrrrrrrr " + " " + dataTimeEn + " " + dataTimeEn); return Json(dataTimeEn, JsonRequestBehavior.AllowGet); } // return Json("-------", JsonRequestBehavior.AllowGet); }