public async Task <IActionResult> PutAccounting([FromRoute] int id, [FromBody] Accounting accounting) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != accounting.Id) { return(BadRequest()); } _context.Entry(accounting).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AccountingExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Create([Bind("StudentID,CourseID,Paid,Active")] CourseSelection courseSelection) { if (ModelState.IsValid) { // Define an object of CourseSelectionOwing and set the details CourseSelectionOwing courseSelectionOwing = new CourseSelectionOwing(); courseSelectionOwing.StudentID = courseSelection.StudentID; courseSelectionOwing.CourseID = courseSelection.CourseID; courseSelectionOwing.Active = true; var course = await _context.Courses.FindAsync(courseSelection.CourseID); if (course == null) { courseSelectionOwing.Owing = 0; } else { courseSelectionOwing.Owing = course.Cost; } // Add entry for course selection _context.Add(courseSelection); // Add entry for course selection owing _context.Add(courseSelectionOwing); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Create), courseSelection.StudentID)); } if (courseSelection.StudentID == 0) { return(NotFound()); } var student = await GetStudentWithCourseSelections(courseSelection.StudentID); if (student == null) { return(NotFound()); } var allCourses = await _context.Courses.Where(m => m.Active == true).ToListAsync(); var availableCourses = new List <Course>(); // Get available courses for enrollment foreach (var course in allCourses) { if (!student.CourseSelections.Any(m => (m.CourseID == course.CourseID && m.Active))) { availableCourses.Add(course); } } ViewData["CourseID"] = new SelectList(availableCourses, "CourseID", "CourseName"); return(View(new CourseSelection { Student = student })); }
public async Task <IActionResult> Create([Bind("StudentID,Name,Age,Active")] Student student) { if (ModelState.IsValid) { _context.Add(student); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(student)); }
public async Task <IActionResult> Create([Bind("CourseID,CourseName,Cost,Active")] Course course) { if (ModelState.IsValid) { _context.Add(course); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(course)); }
public async Task <ActionResult <Transaction> > PostTransaction(Transaction transaction) { var account = _context.Accounts.First(); TransactionType transactionType; if (Enum.TryParse(transaction.Type, out transactionType) && transactionType == TransactionType.debit) { if (account.Balance < transaction.Amount) { return(BadRequest("Account balance is unsufficient to perform the operation")); } account.Balance -= transaction.Amount; } else { account.Balance += transaction.Amount; } _context.Transactions.Add(transaction); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetTransaction), new { id = transaction.Id }, transaction)); }
private async Task CreateUserRoles(IServiceProvider serviceProvider, AccountingContext context) { var roleManager = serviceProvider.GetRequiredService <RoleManager <IdentityRole> >(); var userManager = serviceProvider.GetRequiredService <UserManager <User> >(); // local variables DateTime createdDate = new DateTime(2016, 03, 01, 12, 30, 00); DateTime lastModifiedDate = DateTime.Now; string roleAdministrators = "Administrators"; string roleRegistered = "Registered"; //Create Roles (if they doesn't exist yet) if (!await roleManager.RoleExistsAsync(roleAdministrators)) { await roleManager.CreateAsync(new IdentityRole(roleAdministrators)); } if (!await roleManager.RoleExistsAsync(roleRegistered)) { await roleManager.CreateAsync(new IdentityRole(roleRegistered)); } // Create the "Admin" ApplicationUser account (if it doesn't exist already) var userAdmin = new User { UserName = "******", Email = "*****@*****.**" }; // Insert "Admin" into the Database and also assign the "Administrator" // role to him. if (await userManager.FindByNameAsync(userAdmin.UserName) == null) { await userManager.CreateAsync(userAdmin, "12345678x@X"); await userManager.AddToRoleAsync(userAdmin, roleAdministrators); userAdmin.EmailConfirmed = true; userAdmin.LockoutEnabled = true; } #if DEBUG var userMinh = new User { UserName = "******", Email = "*****@*****.**" }; if (await userManager.FindByNameAsync(userMinh.UserName) == null) { await userManager.CreateAsync(userMinh, "12345678x@X"); await userManager.AddToRoleAsync(userMinh, roleRegistered); userMinh.EmailConfirmed = true; userMinh.LockoutEnabled = true; } #endif await context.SaveChangesAsync(); }
public async Task <string> InsertAsync(Position position) { var result = await _accountingContext.Positions.AddAsync(position); await _accountingContext.SaveChangesAsync(); return(result.Entity.Id.ToString()); }
public Task <int> SaveAsync() => accountingContext.SaveChangesAsync();
public async Task CreateAsync(Employee employee) { await _accountingContext.Employees.AddAsync(employee); await _accountingContext.SaveChangesAsync(); }