public List <Guid> Add(IFormCollection formCollection) { List <Guid> result = new List <Guid>(); if (formCollection.Files.Count > 0) { foreach (IFormFile filee in formCollection.Files) { Guid id = Guid.NewGuid(); string ext = Path.GetExtension(filee.FileName); Asset asset = new Asset { Id = id, FileName = id.ToString() + ext, OriginalFileName = filee.FileName, MimeType = filee.ContentType, FileExtention = ext }; result.Add(id); using (Stream stream = new FileStream("./Assets/" + asset.FileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read)) { filee.CopyTo(stream); } _context.Set <Asset>().Add(asset); } if (_context.SaveChanges() > 0) { return(result); } } return(result); }
public static void SeedUsers(this AppDataContext context) { var admin = context.UserAccounts.SingleOrDefault(x => x.Username == "admin"); if (admin != null) { return; } new List <UserAccount> { new UserAccount { Tenant = "default", Username = "******", ID = Guid.NewGuid(), HashedPassword = new DefaultCrypto().HashPassword("admin", 10), Email = "*****@*****.**", LastUpdated = DateTime.Now, IsLoginAllowed = true, IsAccountVerified = true, FirstName = "Gas Price", LastName = "Admin", Created = DateTime.Now, ClaimCollection = new UserClaimCollection { new UserClaim(ClaimTypes.Role, "Admin") { ObjectState = ObjectState.Added } }, ObjectState = ObjectState.Added } }.ForEach(x => context.Set <UserAccount>().AddOrUpdate(x)); }
public TEntity Update <TEntity>(TEntity entity) where TEntity : class { using var context = new AppDataContext(_dbOptions); var dbSet = context.Set <TEntity>(); var dbEntity = dbSet.Update(entity); context.SaveChanges(); return(dbEntity.Entity); }
public string GenerateOrderNo() { string result = ""; IQueryable <Order> query = context.Set <Order>(); try { var lastRecord = query.Where(x => x.CreatedAt == query.Max(x => x.CreatedAt)).FirstOrDefault(); if (lastRecord != null) { result = $"OR{ (Convert.ToInt32(lastRecord.OrderNo[3..]) +1).ToString().PadLeft(4, '0')}";
// ========================================= private void Seed <TEntity>(TEntity entity) where TEntity : class { using var context = new AppDataContext(_dbOptions); var dbSet = context.Set <TEntity>(); if (!dbSet.Any()) { dbSet.Add(entity); context.SaveChanges(); } }
private void Seed <TEntity>(IEnumerable <TEntity> entityList) where TEntity : class { using var context = new AppDataContext(_dbOptions); var dbSet = context.Set <TEntity>(); if (!dbSet.Any()) { dbSet.AddRange(entityList); context.SaveChanges(); } }
private void Remove <TEntity>() where TEntity : class { using var context = new AppDataContext(_dbOptions); var dbSet = context.Set <TEntity>(); if (dbSet.Any()) { var entities = dbSet.ToList(); dbSet.RemoveRange(entities); context.SaveChanges(); } }
public int Add(TEntity entity) { _appDataContext.Set <TEntity>().Add(entity); _appDataContext.SaveChanges(); return(entity.Id); }
public IList <TEntity> GetAll <TEntity>(string includeProperties = null) where TEntity : class { using var context = new AppDataContext(_dbOptions); IQueryable <TEntity> query = context.Set <TEntity>(); includeProperties ??= string.Empty; foreach (var includeProperty in includeProperties.Split(',', StringSplitOptions.RemoveEmptyEntries)) { query = query.Include(includeProperty); } return(query.ToList()); }
protected virtual IQueryable <TEntity> GetQueryable <TEntity>( Expression <Func <TEntity, bool> > filter = null, Func <IQueryable <TEntity>, IOrderedQueryable <TEntity> > orderBy = null, string includeProperties = null, int?skip = null, int?take = null, bool readOnly = false) where TEntity : class, IEntity { includeProperties ??= string.Empty; IQueryable <TEntity> query = _context.Set <TEntity>(); if (filter != null) { query = query.Where(filter); } foreach (var includeProperty in includeProperties.Split(',', StringSplitOptions.RemoveEmptyEntries)) { query = query.Include(includeProperty); } if (orderBy != null) { query = orderBy(query); } if (skip.HasValue) { query = query.Skip(skip.Value); } if (take.HasValue) { query = query.Take(take.Value); } if (readOnly) { query = query.AsNoTracking(); } return(query); }
public TEntity GetByIdTracking(Guid id, string includes) { var db = _db.Set <TEntity>().AsQueryable(); string[] includeArray = includes.Split(','); if (includeArray.Any()) { foreach (var include in includeArray) { db = db.Include(include); } } return(db .AsExpandable() .FirstOrDefault(x => x.Id == id)); }
public IEnumerable <TEntity> Find(Func <TEntity, bool> condition) { return(_dbContext.Set <TEntity>().Where(condition)); }
public Repository(AppDataContext dbContext) { Db = dbContext; DbSet = dbContext.Set <TEntity>(); }
public Repository(AppDataContext context) { _context = context; DbSet = _context.Set <TEntity>(); }
public int Count(Func <T, bool> predicate) { return(_context.Set <T>().Where(predicate).Count()); }
public Repository(AppDataContext context) { Db = context; DbSet = Db.Set <TEntity>(); }
public BaseRepository(AppDataContext AppDataContext) { context = AppDataContext; entities = context.Set <T>(); }
public IActionResult Index() { var allCapturedGoodies = _ctx.Set <ExfiltratedData>().ToList(); return(View(allCapturedGoodies)); }
public virtual IQueryable <T> Get() { return(context.Set <T>()); }
public TEntity GetById(int id) { return(_context.Set <TEntity>().Find(id)); }
public void Add(T entity) { _dataContext.Set <T>().Add(entity); _dataContext.SaveChanges(); }
public Repository(AppDataContext context) { _db = context; this.dbSet = context.Set <T>(); }
public IList <Todo> All() => context.Set <Todo>().ToList();
public IEnumerable <Entity> GetAll() { return(Db.Set <Entity>().ToList()); }
public async Task Delete(T entity) { _context.Set <T>().Remove(entity); await _context.SaveChangesAsync(); }
public Repository(AppDataContext dbContext) { this.Db = dbContext; entities = dbContext.Set <T>(); }
public Repository(AppDataContext context) { this.context = context; this.dbSet = context.Set <TEntity>(); }
public async Task <IReadOnlyList <T> > GetAllAsync() { return(await _AspNetCoreWebApiContext.Set <T>().Where(t => t.IsDeleted == false).ToListAsync()); }
public GenericRepository(AppDataContext context) { this.Context = context; this.Dbset = context.Set <T>(); }
public void Adicionar(Produto produto) { _context.Set <Produto>().Add(produto); _context.SaveChanges(); }