/// <summary> /// Проверяю есть ли в базе запросы по данному тикету /// </summary> /// <param name="secret"></param> /// <returns></returns> public static bool SecretExists(string secret) { using (OfficeMapper.Models.PhonesDataContext model = new Models.PhonesDataContext()) { return(model.RequestTickets.Count(x => x.secret == secret) > 0); } }
/// <summary> /// Процесс согласования в режиме предоставления доступа /// </summary> /// <param name="secret"></param> /// <returns></returns> StageEnum PushNextStageAccessMode(string secret, Models.DecisionData data) { StageEnum ret = StageEnum.NewRequest; using (Models.PhonesDataContext model = new Models.PhonesDataContext()) { StageEnum stage = GetCurrentStage(secret); switch (stage) { case StageEnum.NewRequest: ///----Отправляем согласование Айтишникам ret = StageEnum.SendITRequest; break; case StageEnum.SendITRequest: ///---Ждем подтверждения ret = StageEnum.WaitITAccept; break; case StageEnum.WaitITAccept: break; } } return(ret); }
private string GetGetFullPostDruzhba(string userCode) { using (Models.PhonesDataContext model = new Models.PhonesDataContext()) { string currDepId = ""; string fullPost = ""; foreach (var depId in userCode.Split('.').ToList()) { if (currDepId.Split('.').Count() > 1) { currDepId += depId; if (model.PhonesDruzhbas.Count(x => x.Dep != null && x.Code == currDepId) > 0) { fullPost += model.PhonesDruzhbas.First(x => x.Dep != null && x.Code == currDepId).Dep + "<br/> "; } currDepId += "."; } else { currDepId += depId; currDepId += "."; } } ///---Add function to POST string functionName = model.Phones.First(x => x.Code == userCode.Split('.')[0]).Dep; if (model.PhonesDruzhbas.Count(x => x.PIB != null && x.Code == userCode) > 0) { fullPost += model.PhonesDruzhbas.First(x => x.PIB != null && x.Code == userCode).Post; } return(functionName + "<br/>" + fullPost); } }
public Models.StructureUnit GetUser(string id, string filialCode) { Models.StructureUnit ret = new Models.StructureUnit(); using (Models.PhonesDataContext model = new Models.PhonesDataContext()) { ret = model.Phones.Where(x => x.Code == id.Replace("-", ".") && x.Dep == null) .ToList() .Select(x => new Models.StructureUnit() { Code = x.Code.Replace(".", "-"), Level = id.Trim().Split('.').Count() + 1, Current = false, Name = x.PIB, Type = "user", FunctionDescription = x.Function, BirthDate = x.Birthday, Email = x.Email, Mobile = x.Mobile, Phones = x.Phone1, Post = GetFullPost(x.Code), //Photo = Photo(x.Email), PhotoFileName = PhotoName(x.Email) }).ToList().First(); } return(ret); }
public List <Models.Data.DomainData> UsersByDomain() { string[] domains = { "DRUZHBA", "DRUZHBA_AD", "UKRTRANSNAFTA", "KREMEN", "ODESSA" }; List <Models.Data.DomainData> ret = new List <Models.Data.DomainData>(); using (Models.PhonesDataContext model = new Models.PhonesDataContext()) { foreach (var d in domains) { ret.Add(new Models.Data.DomainData() { count = model.Logins .Where(x => x.Date >= DateTime.Today) .Select(x => new Models.OnlineUser() { Login = x.sAMAccountName, FIO = x.FIO, Email = x.Email }).Distinct() .Count(x => x.Login.StartsWith(d)), domain = d }); } } return(ret); }
/// <summary> /// Возвращаю перечень UIDs прочитанных сообщений /// </summary> /// <param name="secret"></param> /// <returns></returns> public static List <string> GetSeenUIDs() { using (OfficeMapper.Models.PhonesDataContext model = new Models.PhonesDataContext()) { return(model.ReadedMailMessages.Select(x => x.uid).ToList()); } }
/// <summary> /// Save row in database /// </summary> /// <param name="rowNum"></param> /// <param name="code"></param> private void SaveEntry(Models.LevelRange entry, string FileName) { using (Models.PhonesDataContext model = new Models.PhonesDataContext()) { Models.PhonesDruzhba phone = new Models.PhonesDruzhba(); phone.Code = entry.code; phone.FromFile = FileName; if (entry.entry.isDep) { phone.Dep = entry.entry.DepName; } else { phone.PIB = entry.entry.FIO; phone.Birthday = entry.entry.Birthday; phone.Post = entry.entry.post; phone.ObjectName = entry.ObjectName; phone.Phone = entry.entry.phone; phone.Email = entry.entry.email; phone.Mobile = entry.entry.mobile; } model.PhonesDruzhbas.InsertOnSubmit(phone); model.SubmitChanges(); } }
public List <Models.LogonServers> GetLogonServers(string login, DateTime date) { using (Models.PhonesDataContext model = new Models.PhonesDataContext()) { List <Models.LogonServers> ret = new List <Models.LogonServers>(); List <Models.LogonServers> r1 = new List <Models.LogonServers>(); ret = model.Logins .Where(x => x.sAMAccountName == login && x.Date.Value != null && x.Date.Value >= date) .Select(x => new Models.LogonServers() { LogonDate = x.Date.Value, ServerIP = x.IPAddress, OSVersion = x.OsVersion, osarch = x.osarch }) .OrderByDescending(x => x.LogonDate) .ToList(); foreach (var x in ret) { r1.Add(x); } //r1.RemoveAll(x => x.ServerIP.StartsWith("10.111.")); //r1.AddRange(ret.Where(x => x.ServerIP.StartsWith("10.111.")).ToList()); return(r1); } }
/// <summary> /// Отправляет заявку на подтверждение группе, которая должна на данном этапе подтвердить заявку /// </summary> /// <param name="secret"></param> public static void SendServiceDeskRequest(string secret) { using (OfficeMapper.Models.PhonesDataContext model = new Models.PhonesDataContext()) { string serviceDeskEmail = System.Configuration.ConfigurationManager.AppSettings["serviceDeskEmail"].ToString(); string sendMessageFrom = System.Configuration.ConfigurationManager.AppSettings["sendMessageFrom"].ToString(); var service = model.RequestTickets.First(x => x.secret == secret).UserService; var user = model.RequestTickets.First(x => x.secret == secret).User; string smtpServer = System.Configuration.ConfigurationManager.AppSettings["smtpServer"].ToString(); SmtpClient client = new SmtpClient(smtpServer); MailMessage message = new MailMessage(); message.From = new MailAddress(sendMessageFrom); message.To.Add(new MailAddress(serviceDeskEmail)); string filePath = HttpContext.Current.Server.MapPath("~/Lib/ServiceDeskRequestTemplate.html"); message.Body = File.ReadAllText(filePath); message.Body = message.Body .Replace("%%username%%", user.UTNLogin) .Replace("%%FIO%%", user.FIO) .Replace("%%post%%", user.Post) .Replace("%%email%%", user.Email) .Replace("%%username%% %%FIO%% %%post%% %%email%%", "") .Replace("%%username%% %%FIO%% %%post%% %%email%%", "") .Replace("%%username%% %%FIO%% %%post%% %%email%%", "") .Replace("%%username%% %%FIO%% %%post%% %%email%%", "") .Replace("%%username%% %%FIO%% %%post%% %%email%%", ""); message.IsBodyHtml = true; //client.Send(message); } }
public void importphones() { using (Models.PhonesDataContext model = new Models.PhonesDataContext()) { model.ImportPhones(); } }
/// <summary> /// Возвращает перечень шар компании /// </summary> /// <returns></returns> public static List <Models.FileShareEntry> GetAllShares(string username) { List <Models.FileShareEntry> shares = new List <Models.FileShareEntry>(); //bool LearningM using (Models.PhonesDataContext model = new Models.PhonesDataContext()) { foreach (var fs in model.FileShares.ToList()) { Models.FileShareEntry entry = new Models.FileShareEntry() { Path = fs.Name, Owners = fs.FileShareOwners.Select(x => x.samAccountName).ToList(), Rights = fs.FileShareAccesses.Select(x => new Lib.FileShareAccessEntry() { AccountName = x.samAccountName, AllowRead = x.AllowRead != null ? x.AllowRead.Value : false, AllowWrite = x.AllowWrite != null ? x.AllowWrite.Value : false }).ToList(), CurrentUserAccountName = username, AllowRead = fs.FileShareAccesses.Count(x => x.samAccountName == username && x.AllowRead == true) > 0, AllowWrite = fs.FileShareAccesses.Count(x => x.samAccountName == username && x.AllowWrite == true) > 0 }; shares.Add(entry); } } return(shares); }
private List <Models.StructureUnit> BuilAUTree(Models.StructureUnit item) { List <Models.StructureUnit> ret = new List <Models.StructureUnit>(); using (Models.PhonesDataContext model = new Models.PhonesDataContext()) { if (model.Phones.ToList().Count(x => x.Code != null && x.Code.StartsWith(item.Code + ".") && x.Code.Split('.').Count() == (item.Code.Split('.').Count() + 1) && x.Dep != null ) > 0) { foreach (var subItem in model.Phones.ToList().Where(x => x.Code != null && x.Code.StartsWith(item.Code + ".") && x.Code.Split('.').Count() == (item.Code.Split('.').Count() + 1) && x.Dep != null)) { Models.StructureUnit su = new Models.StructureUnit(); su.Code = subItem.Code; su.Name = subItem.Dep; su.Children = BuilAUTree(su); ret.Add(su); } } } return(ret); }
public Models.StructureUnit GetUserInfo(string CodeId) { Models.StructureUnit user = new Models.StructureUnit(); string Id = CodeId.Replace("-", ".").Trim(); using (Models.PhonesDataContext model = new Models.PhonesDataContext()) { if (model.Phones.Count(x => x.Code == Id && x.PIB != null) > 0) { var u = model.Phones.First(x => x.Code == Id); user.Code = u.Code; user.Name = u.PIB; user.Post = u.Post; user.Email = u.Email; user.Phones = u.Phone1; user.Mobile = u.Mobile; user.PhotoFileName = DepController.PhotoName(u.Email); string currDepId = ""; user.FullPost = ""; foreach (var depId in u.Code.Split('.').ToList()) { currDepId += depId; if (model.Phones.Count(x => x.Dep != null && x.Code == currDepId) > 0) { user.FullPost += model.Phones.First(x => x.Dep != null && x.Code == currDepId).Dep + " "; } currDepId += "."; } } } return(user); }
/// <summary> /// delete all record imported from file /// </summary> /// <param name="FileName"></param> private void DeleteRecords(string FileName) { using (Models.PhonesDataContext model = new Models.PhonesDataContext()) { model.PhonesDruzhbas.DeleteAllOnSubmit(model.PhonesDruzhbas.Where(x => x.FromFile == FileName)); model.SubmitChanges(); } }
/// <summary> /// Возвращает пользователя, который запросил сервис /// </summary> /// <param name="secret"></param> /// <returns></returns> public static Models.User GetRequesterUser(string secret) { using (Models.PhonesDataContext model = new Models.PhonesDataContext()) { string UTNLogin = model.RequestTickets.First(x => x.secret == secret).UTNLogin; Models.User user = model.Users.First(x => x.UTNLogin == UTNLogin); return(user); } }
/// <summary> /// Возвращает текущую стадию согласования сервиса /// </summary> /// <param name="secret"></param> /// <returns></returns> StageEnum GetCurrentStage(string secret) { StageEnum ret = StageEnum.NewRequest; using (Models.PhonesDataContext model = new Models.PhonesDataContext()) { ret = (StageEnum)Enum.Parse(typeof(StageEnum), model.RequestTickets.First(x => x.secret == secret).RequestStage); } return(ret); }
/// <summary> /// Помечаю сообщение как прочитанное /// </summary> /// <param name="secret"></param> /// <returns></returns> public static void MarkMessageAsReaded(string uid) { using (OfficeMapper.Models.PhonesDataContext model = new Models.PhonesDataContext()) { model.ReadedMailMessages.InsertOnSubmit(new Models.ReadedMailMessage() { uid = uid }); model.SubmitChanges(); } }
/// <summary> /// Подтверждает перечень сервисов как ОТКЛОНЕННЫЕ для ИНВЕНТАРИЗАЦИИ /// </summary> /// <param name="secret"></param> /// <param name="data"></param> void DeclineServicesInvent(string secret, Models.DecisionData data) { using (Models.PhonesDataContext model = new Models.PhonesDataContext()) { foreach (var service in model.RequestTickets.Where(x => x.secret == secret)) { service.RequestStage = StageEnum.Declined.ToString(); model.SubmitChanges(); } } }
/// <summary> /// Update CompanyObject name in Database /// </summary> private void UpdateObjects(string FileName) { using (Models.PhonesDataContext model = new Models.PhonesDataContext()) { foreach (var o in model.PhonesDruzhbas) { o.ObjectName = GetCompanyObject(o.Code, FileName); } model.SubmitChanges(); } }
/// <summary> /// Сохраняет в базе загрузку сайта /// </summary> void LogUserAccess(string URI, string IPAddress) { using (Models.PhonesDataContext model = new Models.PhonesDataContext()) { model.LogSiteAccesses.InsertOnSubmit(new Models.LogSiteAccess() { Date = DateTime.Now, IP = IPAddress, URI = URI }); model.SubmitChanges(); } }
public void BuildFS(string rootPath) { using (Models.PhonesDataContext model = new Models.PhonesDataContext()) { foreach (var dep in model.Phones.ToList().Where(x => x.Code != null && x.Code.Split('.').Length == 2 && x.Dep != null)) { string upperLetter = ""; foreach (string letter in dep.Dep.Split(' ')) { upperLetter += letter[0].ToString().ToUpper(); } string dirName = dep.Code + " " + upperLetter; if (!Directory.Exists(Path.Combine(rootPath, dirName).Replace(":", ""))) { Directory.CreateDirectory(Path.Combine(rootPath, dirName).Replace(":", "")); ManifestDirectory md = new ManifestDirectory(); md.DirectoryPath = Path.Combine(rootPath, dirName); md.Description = "Initial creating directory"; md.Owners = new List <string>(); md.Owners.Add("*****@*****.**"); md.Owners.Add("*****@*****.**"); md.Save(); ///---Создаем дочерние каталоги //foreach (var subDep in model.Phones.ToList().Where(x => x.Code != null // && x.Code.Split('.').Length == 2 // && x.Code.StartsWith(dep.Code + ".") // && x.Dep != null)) //{ // string subDirName = subDep.Code + " " + subDep.Dep; // if (!Directory.Exists(Path.Combine(rootPath, dirName, subDirName).Replace(":", ""))) // { // Directory.CreateDirectory(Path.Combine(rootPath, dirName, subDirName).Replace(":", "")); // ManifestDirectory md1 = new ManifestDirectory(); // md1.DirectoryPath = Path.Combine(rootPath, dirName, subDirName).Replace(":", ""); // md1.Description = "Initial creating directory"; // md1.Owners = new List<string>(); // md1.Owners.Add("*****@*****.**"); // md1.Owners.Add("*****@*****.**"); // md1.Save(); // } //} } } } }
/// <summary> /// Определяю есть ли для данной роли эпруверы /// </summary> /// <param name="roleName"></param> /// <returns></returns> public static bool ExistsApproval(string roleName, string serviceId) { using (OfficeMapper.Models.PhonesDataContext model = new Models.PhonesDataContext()) { if (model.Acceptors.Count(x => x.acceptSequense == roleName && x.serviceId == serviceId) > 0) { return(true); } else { return(false); } } }
/// <summary> /// ИНВЕНТАРИЗАЦИЯ Отправляет заявку на подтверждение группе технически ответственных /// </summary> /// <param name="secret"></param> public static void SendClaimRequestToGroup(List <IBaseUserService> services, List <Models.AuthUser> approvers, Models.User whom) { using (OfficeMapper.Models.PhonesDataContext model = new Models.PhonesDataContext()) { var userEmail = System.Configuration.ConfigurationManager.AppSettings["sendMessageFrom"].ToString(); string smtpServer = System.Configuration.ConfigurationManager.AppSettings["smtpServer"].ToString(); SmtpClient client = new SmtpClient(smtpServer); MailMessage message = new MailMessage(); message.From = new MailAddress(userEmail); if (approvers.Count > 0) { foreach (var toEmail in approvers) { message.To.Add(new MailAddress(toEmail.email)); } string applications = ""; ///---Формирую перечень приложений foreach (var app in services) { applications += string.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td></tr>" , app.Id , app.ServiceName , app.Description , app.DeprecationText); } string filePath = HttpContext.Current.Server.MapPath("~/Lib/TechApproveMessageTemplate.html"); message.Body = File.ReadAllText(filePath); message.Subject = "Підтвердження інвентаризації програмно-апаратних засобів"; message.Body = message.Body .Replace("%%username%%", whom.UTNLogin) .Replace("%%FIO%%", whom.FIO) .Replace("%%post%%", whom.Post) .Replace("%%email%%", whom.Email) .Replace("%%applications%%", applications) .Replace("%%AccessKey%%", whom.AccessKey) .Replace("%%secret%%", services.First().secret); message.Headers.Add("XSecret", services.First().secret); message.IsBodyHtml = true; client.Send(message); } } }
/// <summary> /// Возвращает последние данные компа по его имени /// </summary> /// <returns></returns> Models.Login GetLogonServerByName(string compName) { Models.Login ret = new Models.Login(); using (Models.PhonesDataContext model = new Models.PhonesDataContext()) { if (compName != null) { ret = model.Logins .Where(x => x.CompName == compName) .OrderByDescending(x => x.Date) .First(); } } return(ret); }
/// <summary> /// Отправляю заявку дальше по маршруту /// </summary> /// <param name="secret"></param> /// <returns></returns> public StageEnum PushNextStage(string secret, Models.DecisionData data = null) { StageEnum nextStage = service.PushNextStage(secret, data); ///---Обновляю статус заявки в базе using (Models.PhonesDataContext model = new Models.PhonesDataContext()) { foreach (var rt in model.RequestTickets.Where(x => x.secret == secret)) { rt.RequestStage = nextStage.ToString(); } model.SubmitChanges(); } return(nextStage); }
public List <Models.AuthUser> findUsers(string startFrom) { List <Models.AuthUser> users = new List <Models.AuthUser>(); using (Models.PhonesDataContext model = new Models.PhonesDataContext()) { users = model.Users.Where(x => x.UTNLogin.StartsWith(startFrom) || x.FIO.StartsWith(startFrom)).ToList().Select(x => new Models.AuthUser() { FIO = x.FIO, UTNLogin = x.UTNLogin, email = x.Email, AccessKey = x.AccessKey }).ToList(); } return(users); }
public void Test() { string FileSharesCode = System.Configuration.ConfigurationManager.AppSettings["FileSharesCode"].ToString().Trim(); using (Models.PhonesDataContext model = new Models.PhonesDataContext()) { var FileServices = model.UserServices .Where(x => x.Id.Trim().StartsWith(FileSharesCode + ".") || x.Id.Trim() == FileSharesCode) .ToList(); foreach (string path in FileServices.Where(x => x.ServiceName != null).Select(x => x.ServiceName)) { Lib.FileShares fs = new Lib.FileShares(path); fs.Build(path); } } }
/// <summary> /// Сохранение заявки на новый сервис /// </summary> /// <param name="ar"></param> public void Save(AcceptRequest ar) { using (Models.PhonesDataContext model = new Models.PhonesDataContext()) { model.RequestTickets.InsertOnSubmit(new Models.RequestTicket() { RequestDate = DateTime.Now, RequestStage = StageEnum.NewRequest.ToString(), ServiceType = ServiceTypeEnum.UserService.ToString(), UTNLogin = ar.UTNLogin, serviceId = ar.ServiceId, secret = ar.Secret, }); model.SubmitChanges(); } }
/// <summary> /// Отправляет заявку на подтверждение группе, которая должна на данном этапе подтвердить заявку /// </summary> /// <param name="secret"></param> public static void SendClaimRequest(string secret) { using (OfficeMapper.Models.PhonesDataContext model = new Models.PhonesDataContext()) { var service = model.RequestTickets.First(x => x.secret == secret).UserService; var user = model.RequestTickets.First(x => x.secret == secret).User; var userEmail = user.Email != null && user.Email != "" && user.Email.Contains("@") ? user.Email : System.Configuration.ConfigurationManager.AppSettings["sendMessageFrom"].ToString(); string smtpServer = System.Configuration.ConfigurationManager.AppSettings["smtpServer"].ToString(); SmtpClient client = new SmtpClient(smtpServer); MailMessage message = new MailMessage(); message.From = new MailAddress(userEmail); ///---Получение списка согласователей, согласно workflow List <string> approvers = GetApproversEmail(secret); if (approvers.Count > 0) { foreach (var toEmail in approvers) { message.To.Add(new MailAddress(toEmail)); } string filePath = HttpContext.Current.Server.MapPath("~/Lib/ApproveMessageTemplate.html"); message.Body = File.ReadAllText(filePath); message.Subject = System.Configuration.ConfigurationManager.AppSettings["RequestMessageSubject"] + " №" + service.Id + service.ServiceName; message.Body = message.Body .Replace("%%username%%", user.UTNLogin) .Replace("%%FIO%%", user.FIO) .Replace("%%post%%", user.Post) .Replace("%%email%%", user.Email) .Replace("%%applicationName%%", service.ServiceName) .Replace("%%applicationId%%", service.Id) .Replace("%%applicationDescription%%", service.Description) .Replace("%%applicationDeprecationText%%", service.DeprecationText) .Replace("%%secret%%", secret) .Replace("%%username%% %%FIO%% %%post%% %%email%%", "") .Replace("%%username%% %%FIO%% %%post%% %%email%%", ""); message.Headers.Add("XSecret", secret); message.IsBodyHtml = true; client.Send(message); } } }
public static void SaveUser(Models.AuthUser user) { using (OfficeMapper.Models.PhonesDataContext model = new Models.PhonesDataContext()) { if (model.Users.Count(x => x.UTNLogin == user.UTNLogin) == 0) { model.Users.InsertOnSubmit(new Models.User() { UTNLogin = user.UTNLogin, Domain = user.domain, FIO = user.FIO, Email = user.email }); model.SubmitChanges(); } } }