Exemplo n.º 1
0
 public void DeleteByCondition(Func <T, bool> expression)
 {
     foreach (var record in Context.Set <T>().Where(expression))
     {
         record.IsDeleted = true;
     }
 }
 private void ClearSupportedFrameworks(Package package)
 {
     foreach (var supportedFramework in package.SupportedFrameworks.ToList())
     {
         _entitiesContext.Set <PackageFramework>().Remove(supportedFramework);
     }
     package.SupportedFrameworks.Clear();
 }
Exemplo n.º 3
0
        public virtual async Task <ActionResult> UndoPendingEdits(string id, string version)
        {
            var package = _packageService.FindPackageByIdAndVersion(id, version);

            if (package == null)
            {
                return(HttpNotFound());
            }

            if (!package.IsOwner(User))
            {
                return(new HttpStatusCodeResult(403, "Forbidden"));
            }

            // To do as much successful cancellation as possible, Will not batch, but will instead try to cancel
            // pending edits 1 at a time, starting with oldest first.
            var pendingEdits = _entitiesContext.Set <PackageEdit>()
                               .Where(pe => pe.PackageKey == package.Key)
                               .OrderBy(pe => pe.Timestamp)
                               .ToList();

            int numOK        = 0;
            int numConflicts = 0;

            foreach (var result in pendingEdits)
            {
                try
                {
                    _entitiesContext.DeleteOnCommit(result);
                    await _entitiesContext.SaveChangesAsync();

                    numOK += 1;
                }
                catch (DataException)
                {
                    numConflicts += 1;
                }
            }

            if (numConflicts > 0)
            {
                TempData["Message"] = "Your pending edit has already been completed and could not be canceled.";
            }
            else if (numOK > 0)
            {
                TempData["Message"] = "Your pending edits for this package were successfully canceled.";
            }
            else
            {
                TempData["Message"] = "No pending edits were found for this package. The edits may have already been completed.";
            }

            return(Redirect(Url.Package(id, version)));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Add in Single Record in the dataSet
        /// </summary>
        /// <param name="entity">Generics dbSet type</param>
        public TEntity Add(TEntity entity)
        {
            try
            {
                if (entity == null)
                {
                    throw new NullReferenceException("Attempt to add a null record");
                }

                IDbSet <TEntity> dbSet       = _dbContext.Set <TEntity>();
                TEntity          addedEntity = dbSet.Add(entity);
                _dbContext.SetAsCreated(entity);
                return(addedEntity);
            }
            catch (DbEntityValidationException dbEx)
            {
                throwException(dbEx);
                return(null);
            }
        }
 public void DeleteOnCommit(T entity)
 {
     if (TraceLogEvents)
     {
         MethodExtensionWrappers.WrapExecutionTracingTime(
             () => entities.Set <T>().Remove(entity),
             "Remove '{0}' ('{1}') from database".format_with(typeof(T).Name, entity.Key.to_string()));
     }
     else
     {
         entities.Set <T>().Remove(entity);
     }
 }
Exemplo n.º 6
0
 public void DeleteOnCommit(T entity)
 {
     _entities.Set <T>().Remove(entity);
 }
Exemplo n.º 7
0
 public Repository(IEntitiesContext context)
 {
     _context     = context;
     _dbEntitySet = _context.Set <TEntity>();
 }
 public IQueryable <TEntity> GetAll()
 {
     return(_dbContext.Set <TEntity>());
 }
Exemplo n.º 9
0
 public void InsertOnCommit(T entity)
 {
     _entities.Set <T>().Add(entity);
 }
Exemplo n.º 10
0
 public EfRepository(IEntitiesContext dbContext)
 {
     _dbContext = dbContext;
     _objectSet = _dbContext.Set <T>();
 }
Exemplo n.º 11
0
 private T FindById(params object[] keyValues)
 {
     return(_context.Set <T>().Find(keyValues));
 }
Exemplo n.º 12
0
 /// <summary>
 /// Gets all the entities
 /// </summary>
 /// <param name="tenantId">The tenant identifier</param>
 /// <returns>IQueryable collection of the entities</returns>
 public IQueryable <TEntity> GetAll(Guid tenantId)
 {
     return(_dbContext.Set <TEntity>().Where(e => e.TenantId == tenantId));
 }
 public BaseRepository(IUnitOfWork uow)
 {
     _uow       = uow;
     _context   = _uow.Context;
     _objectSet = _context.Set <T>();
 }