public async Task <Product> Get(int id) { using (var db = new DbAccessContext()) { return(await db.Products.FindAsync(id)); } }
public async Task <IList <Product> > Load() { using (var db = new DbAccessContext()) { var list = await db.Products.ToListAsync(); return(list); } }
public IList <EmployeeViewModel> GetEmployeeList() { DbAccessContext db = new DbAccessContext(); var employeeList = (from e in db.Employees join d in db.Departments on e.DepartmentId equals d.DepartmentId select new EmployeeViewModel { Name = e.Name, Email = e.Email, Age = (int)e.Age, Address = e.Address, Department = d.DepartmentName }).ToList(); return(employeeList); }
public bool Insert(Product product) { IsValid = false; using (var db = new DbAccessContext()) { try { // Insert the new entity db.Products.Add(product); db.SaveChanges(); } catch (DbEntityValidationException ex) { ValidationErrorsToMessages(ex); } catch (Exception ex) { LastException = ex; } } return(IsValid); }
public bool Delete(int id) { IsValid = false; using (var db = new DbAccessContext()) { try { // Get the product Product product = db.Products.Find(id); // Delete the product db.Products.Remove(product); db.SaveChanges(); IsValid = true; } catch (Exception ex) { LastException = ex; } } return(IsValid); }
public bool Update(Product product) { IsValid = false; using (var db = new DbAccessContext()) { try { // Update the product db.Entry(product).State = EntityState.Modified; db.SaveChanges(); IsValid = true; } catch (DbEntityValidationException ex) { ValidationErrorsToMessages(ex); } catch (Exception ex) { LastException = ex; } } return(IsValid); }
public UsuarioController(ItsDbContextOptions iTsDbContextOptions, UserManager <ApplicationUser> userManager, SignInManager <ApplicationUser> signInManager) { _context = new DbAccessContext(iTsDbContextOptions); _userManager = userManager; _signInManager = signInManager; }
public MenuController(ItsDbContextOptions iTsDbContextOptions) { _context = new DbAccessContext(iTsDbContextOptions); }