public async Task <ShopBridgeItemModel> Create(ShopBridgeItemModel model) { DBContext.Set <ShopBridgeItemModel>().Add(model); await DBContext.SaveChangesAsync(); return(model); }
public async Task <Product> AddNewProduct(Product product) { _myDBContext.Set <Product>().Add(product); await _myDBContext.SaveChangesAsync(); return(product); }
public async virtual Task <T> AddAsync(T entity) { _context.Set <T>().Add(entity); await _context.SaveChangesAsync(); return(entity); }
public IEnumerable <TModel> Get <TModel>( Expression <Func <TEntity, bool> > predicate, params Expression <Func <TEntity, object> >[] includes) { var result = _context.Set <TEntity>() .Where(predicate); if (includes != null) { foreach (var include in includes) { result = result.Include(include); } } return(_mapper.Map <IList <TModel> >(result)); }
/// <summary> /// Forward the request to the appropriate external data source /// </summary> /// <param name="request"></param> /// <returns></returns> private async Task <List <EconomicRelease> > FillExternalRequest(EconomicReleaseRequest request) { var client = GetClient(request); if (client == null) { _logger.Error($"ERB: Could not find specified data source {request.DataSource}"); RaiseEvent(Error, this, new ErrorArgs(-1, $"ERB: Could not find specified data source {request.DataSource}")); return(new List <EconomicRelease>()); } var data = await client.RequestData(request.FromDate, request.ToDate).ConfigureAwait(false); //save the data we got try { using (var context = new MyDBContext()) { var dbSet = context.Set <EconomicRelease>(); foreach (var release in data) { //the data we get might be a duplicate and we want the latest values of everything, so we can't just insert dbSet.AddOrUpdate(x => new { x.Name, x.Country, x.DateTime }, release); } context.SaveChanges(); } } catch (Exception ex) { _logger.Error(ex, "ERB: Could not save data"); } //Filter the data if necessary if (request.Filter != null) { data = data.AsQueryable().Where(request.Filter).ToList(); } _logger.Info($"ERB returning {data?.Count} items from {client.Name}"); return(data); }
private async Task <List <Dividend> > FillExternalRequest(DividendRequest request) { var client = GetClient(request); if (client == null) { _logger.Error($"DivB: Could not find specified data source {request.DataSource}"); RaiseEvent(Error, this, new ErrorArgs(-1, $"DivB: Could not find specified data source {request.DataSource}")); throw new Exception("Could not find specified data source {request.DataSource}"); } var data = await client.RequestData(request).ConfigureAwait(false); //save the data we got try { using (var context = new MyDBContext()) { var dbSet = context.Set <Dividend>(); foreach (var dividend in data) { //the data we get might be a duplicate and we want the latest values of everything, so we can't just insert dbSet.AddOrUpdate(x => new { x.ExDate, x.Symbol }, dividend); } context.SaveChanges(); } } catch (Exception ex) { _logger.Error(ex, "DivB: Could not save data"); } _logger.Info($"DivB returning {data?.Count} items from {client.Name}"); return(data); }
public NationResponsitory(MyDBContext context) : base(context) { nationEntity = context.Set <Nation>(); }
public BonusResponsitory(MyDBContext context) : base(context) { bonusEntinty = context.Set <Bonus>(); }
public DisciplineResponsitory(MyDBContext context) : base(context) { disciplinesEntity = context.Set <Discipline>(); }
public ShopRepository(MyDBContext ctx) { _ctx = ctx; _dbSet = _ctx.Set <T>(); }
public IEnumerable <T> GetAll2() { return(_context.Set <T>().ToList()); }
public AdFormResponsitory(MyDBContext context) : base(context) { formEntity = context.Set <Forms>(); }
// GET: Customers/Create public IActionResult Create() { ViewData["TipoMembresiaId"] = new SelectList(_context.Set <TipoMembresia>(), "Id", "Id"); return(View()); }
public RegisterResponsitory(MyDBContext context) : base(context) { registerEntity = context.Set <Register>(); }
public ComplainResponsitory(MyDBContext context) : base(context) { compalinEntity = context.Set <Complain>(); }
public AdToabroadResponsitory(MyDBContext context) : base(context) { toabroadsEntity = context.Set <Toabroad>(); }
public FormResponsitory(MyDBContext context) : base(context) { formBoEntiry = context.Set <Forms>(); }
public BaseRepository(MyDBContext db) { this.db = db; entities = db.Set <T>(); }
// GET: GroupInfos/Create public IActionResult Create() { ViewData["GroupId"] = new SelectList(_context.Set <Group>(), "GroupId", "GroupId"); ViewData["StudentAuId"] = new SelectList(_context.Students, "StudentAuId", "FirstName"); return(View()); }
public void Add(T item) { try { db.Set <T>().Add(item); } catch (DbEntityValidationException dbValEx) { var outputLines = new StringBuilder(); foreach (var eve in dbValEx.EntityValidationErrors) { outputLines.AppendFormat("{0}: Entity of type '{ 1}' in state '{ 2}' has the following validation errors:" , DateTime.Now, eve.Entry.Entity.GetType().Name, eve.Entry); foreach (var ve in eve.ValidationErrors) { outputLines.AppendFormat("- Property: '{ 0}', Error: '{ 1}'" , ve.PropertyName, ve.ErrorMessage); } } //Tools.Notify(this, outputLines.ToString(),"error"); throw new DbEntityValidationException(string.Format("Validation errorsrn{0}", outputLines.ToString()), dbValEx); } }
// GET: MoviesController2/Create public IActionResult Create() { ViewData["GeneroId"] = new SelectList(_context.Set <Genero>(), "Id", "Nombre"); return(View()); }
public FileResponsitory(MyDBContext context) : base(context) { fileEntity = context.Set <Files>(); }
public int Count(Func <T, bool> predicate) { return(context.Set <T>().Where(predicate).Count()); }
public UserMoveResponsitory(MyDBContext context) : base(context) { userMovesEntiry = context.Set <UserMove>(); }
public ImageProductResponsitory(MyDBContext context) : base(context) { imgproductEntity = context.Set <ImageProducts>(); }
public AdFileResponsitory(MyDBContext context, IFormFileResponsitory formFileResponsitory) : base(context) { fileEntity = context.Set <Files>(); m_formFileResponsitory = formFileResponsitory; }
public AdUserResponsitory(MyDBContext context, IHashPass hashPass) : base(context) { userEntity = context.Set <Users>(); m_hashPass = hashPass; }
public DangBoResponsitory(MyDBContext context) : base(context) { dangBoEntiry = context.Set <DangBo>(); }
public StatisticalResponsitory(MyDBContext context) : base(context) { userEntity = context.Set <Users>(); }
public void Add(T item) { db.Set <T>().Add(item); Save(); }