private void cmdDelete_Click(object sender, EventArgs e) { if (MessageBox.Show("Czy na pewno chcesz usunąć wskazane pozycje?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { try { var recordCount = 0; var sqlParamWithValue = new HashSet <Tuple <string, object> >(); foreach (Teacher t in olvSubject.CheckedObjects) { sqlParamWithValue.Add(new Tuple <string, object>("@ID", t.ID)); } using (var scope = AppSession.TypeContainer.BeginLifetimeScope()) { var dbs = scope.Resolve <IDataBaseService>(); recordCount = dbs.RemoveManyRecordsAsync(TeacherSQL.DeleteTeacher(), sqlParamWithValue).Result; } GetData(olvSubject); MessageBox.Show($"Liczba usuniętych rekordów: {recordCount}", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private async Task <int> UpdateTeacherAsync(dlgTeacher dlg, int id) { using (var scope = AppSession.TypeContainer.BeginLifetimeScope()) { var dbs = scope.Resolve <IDataBaseService>(); return(await dbs.UpdateRecordAsync(TeacherSQL.UpdateTeacher(), CreateUpdateParams(dlg, id))); } }
private async Task <IEnumerable <Teacher> > GetSchoolTeacherList() { try { using (var scope = AppSession.TypeContainer.BeginLifetimeScope()) { var dbs = scope.Resolve <IDataBaseService>(); return(await dbs.FetchRecordSetAsync(TeacherSQL.SelectTeacher(UserSession.User.Settings.SchoolID.ToString()), TeacherModel)); } } catch (Exception ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); return(new HashSet <Teacher>()); } }
int AddSchoolTeacher(List <Teacher> tcr) { try { var sqlParamWithValue = new HashSet <IDictionary <string, object> >(); foreach (var t in tcr) { sqlParamWithValue.Add(CreateParamWithValue(t)); } using (var scope = AppSession.TypeContainer.BeginLifetimeScope()) { var dbs = scope.Resolve <IDataBaseService>(); return(dbs.AddManyRecordsAsync(TeacherSQL.InsertTeacher(), sqlParamWithValue).Result.RecordCount); } } catch (Exception ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); return(-1); } }
public static void RegisterSQL(MigrationBuilder migrationBuilder) { migrationBuilder.Sql(TeacherSQL.SpGetTeacherById()); migrationBuilder.Sql(CourseSQL.CoursesByTeacherView()); migrationBuilder.Sql(CourseSQL.CourseInsertTrigger()); }
protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "AspNetRoles", columns: table => new { Id = table.Column <string>(type: "nvarchar(450)", nullable: false), Name = table.Column <string>(type: "nvarchar(256)", maxLength: 256, nullable: true), NormalizedName = table.Column <string>(type: "nvarchar(256)", maxLength: 256, nullable: true), ConcurrencyStamp = table.Column <string>(type: "nvarchar(max)", nullable: true) }, constraints: table => { table.PrimaryKey("PK_AspNetRoles", x => x.Id); }); migrationBuilder.CreateTable( name: "AspNetUsers", columns: table => new { Id = table.Column <string>(type: "nvarchar(450)", nullable: false), UserName = table.Column <string>(type: "nvarchar(256)", maxLength: 256, nullable: true), NormalizedUserName = table.Column <string>(type: "nvarchar(256)", maxLength: 256, nullable: true), Email = table.Column <string>(type: "nvarchar(256)", maxLength: 256, nullable: true), NormalizedEmail = table.Column <string>(type: "nvarchar(256)", maxLength: 256, nullable: true), EmailConfirmed = table.Column <bool>(type: "bit", nullable: false), PasswordHash = table.Column <string>(type: "nvarchar(max)", nullable: true), SecurityStamp = table.Column <string>(type: "nvarchar(max)", nullable: true), ConcurrencyStamp = table.Column <string>(type: "nvarchar(max)", nullable: true), PhoneNumber = table.Column <string>(type: "nvarchar(max)", nullable: true), PhoneNumberConfirmed = table.Column <bool>(type: "bit", nullable: false), TwoFactorEnabled = table.Column <bool>(type: "bit", nullable: false), LockoutEnd = table.Column <DateTimeOffset>(type: "datetimeoffset", nullable: true), LockoutEnabled = table.Column <bool>(type: "bit", nullable: false), AccessFailedCount = table.Column <int>(type: "int", nullable: false) }, constraints: table => { table.PrimaryKey("PK_AspNetUsers", x => x.Id); }); migrationBuilder.CreateTable( name: "Students", columns: table => new { Id = table.Column <Guid>(type: "uniqueidentifier", nullable: false), FirstName = table.Column <string>(type: "nvarchar(100)", maxLength: 100, nullable: false), LastName = table.Column <string>(type: "nvarchar(100)", maxLength: 100, nullable: false), Email = table.Column <string>(type: "nvarchar(max)", nullable: false), RegistrationNo = table.Column <string>(type: "nvarchar(10)", maxLength: 10, nullable: false), PhoneNo = table.Column <string>(type: "nvarchar(max)", nullable: true), CreatedAt = table.Column <DateTime>(type: "datetime2", nullable: false), UpdatedAt = table.Column <DateTime>(type: "datetime2", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Students", x => x.Id); }); migrationBuilder.CreateTable( name: "Teachers", columns: table => new { Id = table.Column <Guid>(type: "uniqueidentifier", nullable: false), FirstName = table.Column <string>(type: "nvarchar(max)", nullable: false), LastName = table.Column <string>(type: "nvarchar(max)", nullable: false), Email = table.Column <string>(type: "nvarchar(max)", nullable: false), PhoneNo = table.Column <string>(type: "nvarchar(max)", nullable: false), Designation = table.Column <int>(type: "int", nullable: false), CreatedAt = table.Column <DateTime>(type: "datetime2", nullable: false), UpdatedAt = table.Column <DateTime>(type: "datetime2", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Teachers", x => x.Id); }); migrationBuilder.CreateTable( name: "AspNetRoleClaims", columns: table => new { Id = table.Column <int>(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), RoleId = table.Column <string>(type: "nvarchar(450)", nullable: false), ClaimType = table.Column <string>(type: "nvarchar(max)", nullable: true), ClaimValue = table.Column <string>(type: "nvarchar(max)", nullable: true) }, constraints: table => { table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id); table.ForeignKey( name: "FK_AspNetRoleClaims_AspNetRoles_RoleId", column: x => x.RoleId, principalTable: "AspNetRoles", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "AspNetUserClaims", columns: table => new { Id = table.Column <int>(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), UserId = table.Column <string>(type: "nvarchar(450)", nullable: false), ClaimType = table.Column <string>(type: "nvarchar(max)", nullable: true), ClaimValue = table.Column <string>(type: "nvarchar(max)", nullable: true) }, constraints: table => { table.PrimaryKey("PK_AspNetUserClaims", x => x.Id); table.ForeignKey( name: "FK_AspNetUserClaims_AspNetUsers_UserId", column: x => x.UserId, principalTable: "AspNetUsers", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "AspNetUserLogins", columns: table => new { LoginProvider = table.Column <string>(type: "nvarchar(450)", nullable: false), ProviderKey = table.Column <string>(type: "nvarchar(450)", nullable: false), ProviderDisplayName = table.Column <string>(type: "nvarchar(max)", nullable: true), UserId = table.Column <string>(type: "nvarchar(450)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey }); table.ForeignKey( name: "FK_AspNetUserLogins_AspNetUsers_UserId", column: x => x.UserId, principalTable: "AspNetUsers", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "AspNetUserRoles", columns: table => new { UserId = table.Column <string>(type: "nvarchar(450)", nullable: false), RoleId = table.Column <string>(type: "nvarchar(450)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId }); table.ForeignKey( name: "FK_AspNetUserRoles_AspNetRoles_RoleId", column: x => x.RoleId, principalTable: "AspNetRoles", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_AspNetUserRoles_AspNetUsers_UserId", column: x => x.UserId, principalTable: "AspNetUsers", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "AspNetUserTokens", columns: table => new { UserId = table.Column <string>(type: "nvarchar(450)", nullable: false), LoginProvider = table.Column <string>(type: "nvarchar(450)", nullable: false), Name = table.Column <string>(type: "nvarchar(450)", nullable: false), Value = table.Column <string>(type: "nvarchar(max)", nullable: true) }, constraints: table => { table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); table.ForeignKey( name: "FK_AspNetUserTokens_AspNetUsers_UserId", column: x => x.UserId, principalTable: "AspNetUsers", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Courses", columns: table => new { Id = table.Column <Guid>(type: "uniqueidentifier", nullable: false), Code = table.Column <string>(type: "nvarchar(10)", maxLength: 10, nullable: false), Title = table.Column <string>(type: "nvarchar(250)", maxLength: 250, nullable: false), Credit = table.Column <decimal>(type: "decimal(18,2)", nullable: false), TeacherId = table.Column <Guid>(type: "uniqueidentifier", nullable: false), StudentId = table.Column <Guid>(type: "uniqueidentifier", nullable: true), CreatedAt = table.Column <DateTime>(type: "datetime2", nullable: false), UpdatedAt = table.Column <DateTime>(type: "datetime2", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Courses", x => x.Id); table.ForeignKey( name: "FK_Courses_Students_StudentId", column: x => x.StudentId, principalTable: "Students", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Courses_Teachers_TeacherId", column: x => x.TeacherId, principalTable: "Teachers", principalColumn: "Id"); }); migrationBuilder.CreateTable( name: "Exams", columns: table => new { Id = table.Column <Guid>(type: "uniqueidentifier", nullable: false), Title = table.Column <string>(type: "nvarchar(250)", maxLength: 250, nullable: false), TotalMark = table.Column <decimal>(type: "decimal(18,2)", nullable: false), ObtainedMark = table.Column <decimal>(type: "decimal(18,2)", nullable: false, defaultValue: 0m), CourseId = table.Column <Guid>(type: "uniqueidentifier", nullable: false), TeacherId = table.Column <Guid>(type: "uniqueidentifier", nullable: false), StudentId = table.Column <Guid>(type: "uniqueidentifier", nullable: true), CreatedAt = table.Column <DateTime>(type: "datetime2", nullable: false), UpdatedAt = table.Column <DateTime>(type: "datetime2", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Exams", x => x.Id); table.ForeignKey( name: "FK_Exams_Courses_CourseId", column: x => x.CourseId, principalTable: "Courses", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Exams_Students_StudentId", column: x => x.StudentId, principalTable: "Students", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Exams_Teachers_TeacherId", column: x => x.TeacherId, principalTable: "Teachers", principalColumn: "Id"); }); migrationBuilder.Sql(TeacherSQL.SpGetTeacherById()); migrationBuilder.Sql(TeacherSQL.SpDeleteTeacherById()); migrationBuilder.CreateIndex( name: "IX_AspNetRoleClaims_RoleId", table: "AspNetRoleClaims", column: "RoleId"); migrationBuilder.CreateIndex( name: "RoleNameIndex", table: "AspNetRoles", column: "NormalizedName", unique: true, filter: "[NormalizedName] IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_AspNetUserClaims_UserId", table: "AspNetUserClaims", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_AspNetUserLogins_UserId", table: "AspNetUserLogins", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_AspNetUserRoles_RoleId", table: "AspNetUserRoles", column: "RoleId"); migrationBuilder.CreateIndex( name: "EmailIndex", table: "AspNetUsers", column: "NormalizedEmail"); migrationBuilder.CreateIndex( name: "UserNameIndex", table: "AspNetUsers", column: "NormalizedUserName", unique: true, filter: "[NormalizedUserName] IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_Courses_Id", table: "Courses", column: "Id"); migrationBuilder.CreateIndex( name: "IX_Courses_StudentId", table: "Courses", column: "StudentId"); migrationBuilder.CreateIndex( name: "IX_Courses_TeacherId", table: "Courses", column: "TeacherId", unique: true); migrationBuilder.CreateIndex( name: "IX_Exams_CourseId", table: "Exams", column: "CourseId"); migrationBuilder.CreateIndex( name: "IX_Exams_Id", table: "Exams", column: "Id"); migrationBuilder.CreateIndex( name: "IX_Exams_StudentId", table: "Exams", column: "StudentId"); migrationBuilder.CreateIndex( name: "IX_Exams_TeacherId", table: "Exams", column: "TeacherId", unique: true); migrationBuilder.CreateIndex( name: "IX_Students_Id", table: "Students", column: "Id"); migrationBuilder.CreateIndex( name: "IX_Teachers_Id", table: "Teachers", column: "Id"); }