public static async Task <bool> CheckUserName(string name) { using (var context = new DatabaseContainer()) { return((await context.Users.Where(u => u.Login.ToLower() == name.ToLower()).CountAsync()) == 1); } }
public Candidate GetCandidateById(long id) { Candidate candidate = null; try { using (var db = new DatabaseContainer()) { candidate = db.Candidates .Include("Person") .Include("Document") .Include("Decision") .Include("RecruitmentStage") .Include("RecruitmentStage.Stage") .Include("Evaluation") .Include("Evaluation.SkillsEvaluation") .Include("Evaluation.SkillsEvaluation.Skill") .Include("Evaluation.SoftSkillsEvaluation") .Include("Evaluation.SoftSkillsEvaluation.SoftSkill") .Where(x => x.Id == id).SingleOrDefault(); } } catch (Exception e) { } return(candidate); }
public UserAccess Login(string login, string password) { bool successful = false; User u = null; try { using (var db = new DatabaseContainer()) { u = db.Users.Where(x => x.Login == login).First(); if (Encryption.Match(password, u.Password)) { successful = true; } } } catch (Exception e) { } if (successful && u != null) { return((UserAccess)u.Role); } else { throw new Exception("There is no user!"); } }
public void Delete(long personId) { try { using (var db = new DatabaseContainer()) { Person p = db.Persons .Include("User") .Include("Candidate") .Include("Candidate.Evaluation") .Include("Candidate.Decision") .Where(x => x.Id == personId).First(); db.Entry(p.Candidate.Evaluation).State = System.Data.Entity.EntityState.Deleted; db.Entry(p.Candidate.Decision).State = System.Data.Entity.EntityState.Deleted; db.Entry(p.Candidate).State = System.Data.Entity.EntityState.Deleted; db.Entry(p.User).State = System.Data.Entity.EntityState.Deleted; db.Entry(p).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); } } catch (Exception e) { } }
private async void loadFromDatabaseToolStripMenuItem_Click(object sender, EventArgs e) { FormConnectToDatabase connectToDatabase = new FormConnectToDatabase(); connectToDatabase.LoadForm(); connectToDatabase.ShowDialog(); if (connectToDatabase.Saved) { this._userControlDBForgeEditor.displayUserMessageSuccess("Loading database schema..."); this._userControlDBForgeEditor.showSpinner(); IDatabaseInterface sqlInterface = DatabaseInterfaceFactory.Factory(connectToDatabase.Provider); sqlInterface.SetConnectionString(connectToDatabase.ConnectionString); DatabaseContainer databaseContainer = null; await Task.Run(() => { databaseContainer = sqlInterface.GetDatabaseStructure(); }); this._userControlDBForgeEditor.LoadProject(databaseContainer); this.ConnectionString = connectToDatabase.ConnectionString; this._userControlDBForgeEditor.displayUserMessageSuccess("Database schema loaded..."); this._userControlDBForgeEditor.hideSpinner(); } }
public Candidate GetCandidateByLogin(string login) { Candidate candidate = null; try { using (var db = new DatabaseContainer()) { int id = db.Users .Include("Person") .Where(u => u.Login == login) .First() .Person.Id; candidate = this.GetCandidateById( db.Candidates .Include("Person") .Where(x => x.Person.Id == id) .First().Id); } } catch (Exception e) { } return(candidate); }
public async Task CreateContainerAsync_PostgreSql_HelloWorld() { DatabaseContainer container = null; try { container = await DatabaseBuilder.CreateContainerAsync(DatabaseType.PostgreSql); var connection = await container.CreateConnectionAsync <Npgsql.NpgsqlConnection>(); using (var cmd = connection.CreateCommand()) { cmd.CommandText = "select 'Hello World!'"; var msg = await cmd.ExecuteScalarAsync(); Assert.That(msg, Is.EqualTo("Hello World!")); } } finally { if (container != null) { await container.StopAsync(); } } }
public List <Stage> GetStagesByPage(int pageNumber) { List <Stage> returnList = new List <Stage>(); if (pageNumber <= 0) { return(returnList); } if ((pageNumber - 1) * 10 > this.GetAmountOfSoftSkills()) { return(returnList); } try { using (var db = new DatabaseContainer()) { var tmp = db.Stage.OrderBy(x => x.Id).Skip((pageNumber - 1) * 10); returnList = tmp.Take(tmp.Count() >= 10 ? 10 : tmp.Count()).ToList(); } } catch (Exception e) { } return(returnList); }
public List <Person> GetPersonByPage(int pageNumber) { var returnList = new List <Person>(); if (pageNumber <= 0) { return(returnList); } try { using (DatabaseContainer db = new DatabaseContainer()) { if ((pageNumber - 1) * 10 > db.Persons.Count()) { return(returnList); } var tmp = db.Persons.Include("User") .Include("Candidate") .OrderBy(x => x.Id).Skip((pageNumber - 1) * 10); tmp = tmp.Take(tmp.Count() >= 10 ? 10 : tmp.Count()); return(tmp.ToList()); } } catch (Exception e) { return(returnList); } }
public void GenerateInsertStatmentsForDatabase(DatabaseContainer database) { ISQLGenerator generator = SqlGeneratorFactory.Factory(database.DatabaseType); this._database = database; textBoxOutput.Text = generator.GenerateInsertStatmentsForDatabase(this._database); }
private void loadSchemas(DatabaseContainer database) { Action loadSchemas = () => { listBoxSchemas.DataSource = null; listBoxSchemas.DataSource = database.Schemas; listBoxSchemas.DisplayMember = "Name"; if (listBoxSchemas.Items.Count > 0) { listBoxSchemas.SelectedIndex = 0; } }; if (this.listBoxSchemas.InvokeRequired) { this.listBoxSchemas.Invoke(new MethodInvoker(delegate { loadSchemas(); })); } else { loadSchemas(); } }
public async Task LoadAllocations(DatabaseContainer database) { Log.Debug($"Getting allocations"); foreach (var file in database.Files) { Log.Debug($"Getting allocations for File: {file.FileId} - {file.FileName}"); var fileSize = file.Size; Log.Debug($"Loading GAM"); var gam = await AllocationService.GetAllocation(database.DatabaseId, new PageAddress(file.FileId, 2), fileSize); database.Gam.Add(file.FileId, gam); Log.Debug($"Loading SGAM"); var sGam = await AllocationService.GetAllocation(database.DatabaseId, new PageAddress(file.FileId, 3), fileSize); database.SGam.Add(file.FileId, sGam); Log.Debug($"Loading DCM"); var dcm = await AllocationService.GetAllocation(database.DatabaseId, new PageAddress(file.FileId, 6), fileSize); database.Dcm.Add(file.FileId, dcm); Log.Debug($"Loading BCM"); var bcm = await AllocationService.GetAllocation(database.DatabaseId, new PageAddress(file.FileId, 7), fileSize); database.Bcm.Add(file.FileId, bcm); } }
public MainViewModel() { // Insert code required on object creation below this point. mEntities = new DatabaseContainer(new Uri("http://localhost:11424/DataAccess.svc/")); LoadItems(); }
private void btn_submit_course_Click(object sender, EventArgs e) { if (CourseFormValidator()) { Course course = new Course(); course.name = txtBox_name_course.Text; course.code = int.Parse(txtBox_code_course.Text); course.capacity = byte.Parse(txtBox_capacity_course.Text); course.TeacherId = ((Teacher)cmb_teacher_course.SelectedItem).Id; course.time1 = (byte)(Program.TimeToDataBaseCodeConverter(cmb_day_1_course.SelectedIndex, cmb_time_1_course.SelectedIndex)); course.time2 = (byte)(Program.TimeToDataBaseCodeConverter(cmb_day_2_course.SelectedIndex, cmb_time_2_course.SelectedIndex)); if (course.time1 == course.time2) { MessageBox.Show("ساعت کلاس ها مشابه است"); return; } course.exam_time = time_picker_exam_course.Value; course.exam_date = time_picker_exam_course.Value; DatabaseContainer db = new DatabaseContainer(); if (db.Courses.FirstOrDefault(c => c.code == course.code) != null) { MessageBox.Show("درسی با این کد وجود دارد!"); } db.Courses.Add(course); db.SaveChanges(); MessageBox.Show("درس مورد نظر اضافه شد"); formManagement.loadCourses(); } else { MessageBox.Show("مشخصات درس را به درستی وارد کنید!"); } }
public void Update(Profile profileEntity) { if (IsValid(profileEntity)) { using (var context = new DatabaseContainer()) { profileEntity.City = context.CitySet.Find(profileEntity.CityId); context.ProfileSet.AddOrUpdate(profileEntity); try { context.SaveChanges(); } catch (DbEntityValidationException e) { var newException = new FormattedDbEntityValidationException(e); Debug.Write(newException.Message); throw newException; } catch (Exception) { throw new ArgumentException("Update Exception"); } } } }
public FormDatabaseForge(bool codenesiumMode = false, DatabaseContainer container = null) { this._settings.CodenesiumMode = codenesiumMode; this.DatabaseContainer = container; InitializeComponent(); this.initializeUserControls(); this.setPanelUserControl(this._userControlDBForgeEditor); }
public int GetProfile(string userid) { using (var context = new DatabaseContainer()) { Profile pr = context.ProfileSet.Where(p => p.AspNetUsersId.Equals(userid)).FirstOrDefault(); return(pr.Id); } }
public void Close(DatabaseContainer categoryList) { XmlSerializer serializer = new XmlSerializer(typeof(DatabaseContainer)); Stream writer = new FileStream(_filePath, FileMode.Create); serializer.Serialize(writer, categoryList); writer.Close(); }
/// <summary> /// Iterates a database one table at a time building the dependency tree for each table and outputing the tree to the screen. /// </summary> /// <param name="database"></param> public void BuildDependencyTree(DatabaseContainer database) { Resolver resolver = new Resolver(); this._database = database; List <DependencyTable> convertedTables = resolver.ConvertToDependencyTables(database); string output = string.Empty; Action <DependencyTable> recursivePrintTable = null; int depth = 0; recursivePrintTable = (t) => { t.Columns.ForEach(c => { string refersTo = string.Empty; if (c.RefersTo != null) { refersTo += $" > {c.RefersTo.Table.Schema}.{ c.RefersTo.Table.Name}.{ c.RefersTo.Name}"; } string tabs = ""; for (int i = 0; i < depth; i++) { tabs += "---"; } string item = $"{tabs} {t.Schema }.{t.Name}.{c.Name} {refersTo}" + Environment.NewLine; output += item; if (c.RefersTo != null) { depth++; recursivePrintTable(c.RefersTo.Table); depth--; } }); }; string currentTable = string.Empty; convertedTables.ForEach(t => { if (t.Name != currentTable) { output += Environment.NewLine; } currentTable = t.Name; resolver.ClearValues(t); resolver.BuildDependsOnList(this._database.GetForeignKeys(), convertedTables, t); recursivePrintTable(t); }); textBoxOutput.Text = output; }
public bool Authenticate(string email, byte[] token, out byte attemptsLeft) { if (_salt == null || _authenticated) { attemptsLeft = 255; return(false); } using (var db = new DatabaseContainer()) { var query = from u in db.UsersSet where u.Email == email select u; if (query.Count() == 0) { attemptsLeft = 255; return(false); } var user = query.First(); attemptsLeft = user.AttemptsLeft; if (attemptsLeft == 0) { return(false); } if (user.Online) { attemptsLeft = 255; return(false); } _authenticated = AuthChecker.CheckToken(token, _salt, user.Password); if (!_authenticated) { attemptsLeft--; user.AttemptsLeft--; } else { user.AttemptsLeft = Config.MaxAuthAttempts; user.Online = true; _email = user.Email; _id = user.Id; } var entry = db.Entry(user); entry.Property(e => e.AttemptsLeft).IsModified = true; entry.Property(e => e.Online).IsModified = true; db.SaveChanges(); _salt = null; return(_authenticated); } }
public static async Task <User> GetUser(string identity, string password) { using (var context = new DatabaseContainer()) { var id = identity.ToLower(); var ep = Md5.Encrypt(password); return(await context.Users.Where(u => (u.Email.ToLower() == id || u.Login.ToLower() == id) && u.Password == ep).FirstOrDefaultAsync()); } }
public void LoadProject(DatabaseContainer container) { this.setPanelUserControl(this._userControlSchemaEntry); this._database = container; listBoxColumns.DataSource = null; listBoxTables.DataSource = null; listBoxSchemas.DataSource = null; this._userControlFieldRapidEntry.SetProvider(this._database.DatabaseType); loadSchemas(this._database); }
protected virtual ChangeFeedProcessor CreateChangeFeedProcessor() => DatabaseContainer .GetChangeFeedProcessorBuilder( processorName: ProcessorName, onChangesDelegate: HandleChangeFeedStream ) .WithInstanceName($"{DateTime.UtcNow:O}-{Guid.NewGuid()}") .WithLeaseContainer(LeaseContainer) .WithPollInterval(PollInterval) .WithMaxItems(MaxItemsPerBatch) .WithStartTime(StartTime) .Build();
private void SaveResult() { using (var db = new DatabaseContainer()) { int max = db.UrlsSet.Count() > 0 ? db.UrlsSet.Max(u => u.Group) : 0; var queryId = from u in db.UsersSet where u.Email == Owner select u.Id; if (queryId.Count() != 1) { return; } int userId = queryId.First(); foreach (var url in _URLs) { db.UrlsSet.Add(new Urls() { Group = max + 1, Url = url }); } Database.Reports report = new Database.Reports() { Duration = Duration, RequestDuration = RequestDuration, Strategy = (byte)Strategy, Time = DateTime.Now, Timeout = Timeout, UrlGroup = max + 1, UserId = userId, VirtualUsers = VirtualUsers }; db.ReportsSet.Add(report); db.SaveChanges(); foreach (var point in Points) { db.PointsSet.Add(new Database.Points() { ReportId = report.Id, X = point.x, Y = point.y }); } db.SaveChanges(); } }
public CodeSnippetModule ( IConfiguration configuration, ILogger <FileExplorerModule> logger, DatabaseContainer <SnippetInfo> container ) { _configuration = configuration; _logger = logger; _container = container; }
public int GetAmountOfRecords() { int returnValue; using (var db = new DatabaseContainer()) { returnValue = db.Persons.Count(); } return(returnValue); }
public async Task <bool> Validate(string value) { using (var context = new DatabaseContainer()) { if (await context.Users.Where(u => u.Email.ToLower() == value.ToLower()).CountAsync() != 0) { Errors.Add("Пользователь с таким Email уже существует"); return(false); } return(true); } }
public Profile GetByUserId(string userId) { using (var context = new DatabaseContainer()) { IQueryable <Profile> user = context.ProfileSet.Where(q => q.AspNetUsers.Id == userId); if (!user.Any()) { return(null); } return(user.First()); } }
public PollModule ( IOptions <DiscordSettings> options, ILogger <FileExplorerModule> logger, DatabaseContainer <PollInfo> container ) { _logger = logger; string prefix = options.Value.CommandPrefix; _prefix = prefix; _container = container; }
private void FormNewCourse_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'course_managementDataSet.Teachers' table. You can move, or remove it, as needed. this.teachersTableAdapter.Fill(this.course_managementDataSet.Teachers); cmb_day_1_course.SelectedIndex = 0; cmb_day_2_course.SelectedIndex = 0; cmb_time_1_course.SelectedIndex = 0; cmb_time_2_course.SelectedIndex = 0; DatabaseContainer db = new DatabaseContainer(); var teachers = db.Teachers.ToArray(); cmb_teacher_course.DataSource = teachers; }
public SerializableContainer(DatabaseContainer<long> longContainer, DatabaseContainer<string> stringContainer) : this() { StringValues = stringContainer.Values; LongValues = longContainer.Values; }