Example #1
0
        /// <summary>
        /// 按条件删除数据
        /// </summary>
        /// <param name="where">查询条件</param>
        public virtual void Delete(Expression <Func <TEntity, bool> > @where)
        {
            var objects = Dbset.Where(where);

            //foreach (TEntity obj in objects)
            Dbset.RemoveRange(objects);
        }
Example #2
0
        public List <BasicModel> GetMatchesForSaving(DateTime?date = null)
        {
            var matches = Dbset.Where(w => w.Participants.Count > 0 && w.TeamTwo != null && w.TeamOne != null).ToList();

            if (date.HasValue)
            {
                matches = matches.Where(w => w.Date.Value.Date == date.Value.Date).ToList();
            }

            matches = matches.OrderByDescending(o => o.Date).Take(15).ToList();

            var result = new List <BasicModel>();

            foreach (var match in matches)
            {
                result.Add(new BasicModel
                {
                    Name = $"{match.Date.Value.ToShortDateString()}: {match.TeamOne.Name} " +
                           $"{match.Participants.Where(w => w.TeamId == match.TeamOneId).Sum(s => s.Points)} " +
                           $" : {match.Participants.Where(w => w.TeamId == match.TeamTwoId).Sum(s => s.Points)} " +
                           $" {match.TeamTwo.Name}",
                    Id = match.Id
                });
            }

            return(result);
        }
Example #3
0
        public async Task <List <Category> > GetBySectionIdAsync(int sectionId)
        {
            var records = await Dbset.Where(r => r.SectionId == sectionId && !r.Deleted)
                          .OrderBy(h => h.Title).ToListAsync();

            return(records);
        }
Example #4
0
        public async Task <List <AccountTransferEntity> > GetTransfers(int accountId, TransferType transferType, DateTime from, DateTime to)
        {
            var records = await Dbset.Where(r => r.AccountId == accountId && r.TransferType == transferType && r.TransferDate > from && r.TransferDate < to)
                          .OrderBy(r => r.TransferDate).ToListAsync();

            return(records);
        }
        public List <CompanyIndicator> Get(string ticker)
        {
            var records = Dbset
                          .Where(c => c.Ticker == ticker)
                          .ToList();

            return(records);
        }
Example #6
0
        public Task <int> DeleteHash(int id)
        {
            var result = Dbset.Where(x => x.Id == id);

            Dbset.Remove(result.FirstOrDefault());
            Context.SaveChanges();
            return(null);
        }
Example #7
0
        public virtual void Delete(Expression <Func <T, bool> > where)
        {
            IEnumerable <T> objects = Dbset.Where <T>(where).AsEnumerable();

            foreach (T obj in objects)
            {
                Dbset.Remove(obj);
            }
        }
Example #8
0
        public virtual void DeleteAllForSeries(int seriesId, string userId)
        {
            var objects = Dbset.Where(x => x.UserId == userId && x.Comic.SeriesId == seriesId).ToList();

            foreach (var obj in objects)
            {
                Dbset.Remove(obj);
            }
        }
        public async Task <IList <ScheduledJob> > GetHistoryAsync(ScheduledJobType jobType)
        {
            var jobs = await Dbset
                       .Where(j => (j.Status == JobStatus.Cancelled || j.Status == JobStatus.Completed || j.Status == JobStatus.Error) &&
                              (j.JobType == jobType || jobType == ScheduledJobType.All))
                       .OrderByDescending(j => j.StartDate).ToListAsync();

            return(jobs);
        }
        public async Task <IList <ScheduledJob> > GetActiveJobsAsync(ScheduledJobType jobType)
        {
            var jobs = await Dbset.Where(j =>
                                         (j.Status == JobStatus.InProgress || j.Status == JobStatus.Paused || j.Status == JobStatus.Pending) &&
                                         (j.JobType == jobType || jobType == ScheduledJobType.All))
                       .OrderByDescending(j => j.StartDate).ToListAsync();

            return(jobs);
        }
        public async Task <Article> GetFeaturedAsync(int categoryId, bool withFallback)
        {
            var record = await Dbset.FirstOrDefaultAsync(r => r.CategoryId == categoryId && r.IsFeatured);

            if (record == null && withFallback)
            {
                record = await Dbset.Where(r => r.CategoryId == categoryId).OrderBy(r => r.OrderId).FirstOrDefaultAsync();
            }
            return(record);
        }
Example #12
0
        public virtual void Delete(Expression <Func <TEntity, bool> > @where, Action <TEntity> action)
        {
            var objects = Dbset.Where(where);

            foreach (TEntity entity in objects)
            {
                action(entity);
                Dbset.Remove(entity);
            }
        }
Example #13
0
        public async Task <Category> GetAsync(string categoryUrl, bool withFallback)
        {
            var record = await Dbset.FirstOrDefaultAsync(r => r.Url == categoryUrl && !r.Deleted);

            if (record == null && withFallback)
            {
                record = await Dbset.Where(r => !r.Deleted).OrderBy(r => r.OrderId).FirstOrDefaultAsync();
            }
            return(record);
        }
        public async Task <List <ProcessorLog> > GetAllAsync(int jobId)
        {
            var records = await Dbset.Where(r => r.JobId == jobId).OrderByDescending(r => r.Logged).ToListAsync();

            if (records.Any(r => r.Level == "Error"))
            {
                return(records.Where(r => r.Level == "Error").OrderBy(r => r.Logged).ToList());
            }
            return(records.Take(1).ToList());
        }
Example #15
0
        public IQueryable <T> GetQueryByTenant(Guid tenantId, bool isCheckDeleted = true)
        {
            var query = Dbset.Where(w => w.TenantId == tenantId);

            if (isCheckDeleted)
            {
                //return Dbset.Where(w => !w.IsDeleted);
            }

            return(query);
        }
Example #16
0
        public IQueryable <T> GetQuery(RequestContext context, bool isCheckDeleted = true)
        {
            var query = Dbset.Where(w => w.TenantId == context.TenantId);

            if (isCheckDeleted)
            {
                return(Dbset.Where(w => !w.IsDeleted));
            }

            return(query);
        }
        public async Task DeleteAsync(int ruleSetId)
        {
            var records = await Dbset.Where(r => r.RuleSetId == ruleSetId).OrderBy(r => r.OrderId).ToListAsync();

            if (records != null)
            {
                foreach (var entity in records)
                {
                    Dbset.Remove(entity);
                }
            }
        }
        public string GetRandomByType(PickyMessageType pickyMessageType, string currentUserName)
        {
            var messages = Dbset.Where(x => x.Type == (byte)pickyMessageType).ToArray();

            if (messages.Length == 0)
            {
                throw new MyException("Tell the developer that no messages exist for the [" + pickyMessageType + "] type. He needs to create some!");
            }

            var random      = new Random();
            int randomIndex = random.Next(0, messages.Length);

            return(messages[randomIndex].Message.Replace("#USER#", currentUserName));
        }
        public override async Task InsertAsync(MeetingContent entity)
        {
            var itemsToUpdate = Dbset.Where(x =>
                                            x.MeetingAgendaId == entity.MeetingAgendaId &&
                                            x.Ordinal >= entity.Ordinal);

            foreach (var item in itemsToUpdate)
            {
                item.Ordinal     = item.Ordinal + 1;
                item.UpdatedBy   = entity.UpdatedBy;
                item.UpdatedDate = DateTime.Now;
            }

            await base.InsertAsync(entity);
        }
Example #20
0
        public void Archive(Task task)
        {
            var tasksToReorder = Dbset.Where(x => x.UserId == task.UserId && x.IsArchived == false && x.Order > task.Order).ToList();

            foreach (var taskToReorder in tasksToReorder)
            {
                taskToReorder.Order--;
                _context.Entry(taskToReorder).State = EntityState.Modified;
            }

            task.Archive();

            _context.Entry(task).State = EntityState.Modified;
            _context.SaveChanges();
        }
        public IEnumerable <PickyMessage> GetAllWithFilters(string searchMessage, byte?searchType, short page, byte pageSize)
        {
            searchMessage = searchMessage ?? "";
            var messages = Dbset.Where(x => x.Message.Contains(searchMessage));

            if (searchType.HasValue)
            {
                messages = messages.Where(x => x.Type == searchType);
            }

            return(messages.OrderByDescending(x => x.Id)
                   .Skip(pageSize * (page - 1))
                   .Take(pageSize)
                   .ToList());
        }
Example #22
0
        public int GetTotalRegistros(string search)
        {
            try
            {
                var query = Dbset.Where(x => x.NOME.Contains(search) ||
                                        x.SITUACAO.Contains(search) ||
                                        x.DISPONIVEL.Contains(search)).Count();

                var _object = CompiledQuery.Compile <ObjectContext, int>(ctx => query);
                return(_object.Invoke(((IObjectContextAdapter)Entities).ObjectContext));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public List <CompanyQuotesModel> FindCompaniesForUpdate(TimeSpan fromTimeAgo, int count)
        {
            var fromDate = DateTime.Now.Subtract(fromTimeAgo).Date;
            var records  = Dbset.Where(c => c.Filtered && c.LastUpdated < fromDate)
                           .Select(c => new CompanyQuotesModel
            {
                Ticker            = c.Ticker,
                LastUpdated       = c.LastUpdated,
                HistoryQuotesJson = c.HistoryQuotesJson
            })
                           .OrderBy(c => c.Ticker)
                           .Take(count)
                           .ToList();

            return(records);
        }
Example #24
0
        public IEnumerable <Task> GetAllForSchedule(int userId, DateTime fromDate, DateTime toDate)
        {
            var tasks   = Dbset.Where(x => x.UserId == userId && x.IsArchived == false).ToList();
            var taskIds = tasks.Select(x => x.Id).ToArray();

            var completedTaskItems = _context.CompletedTaskItems.Where(y => taskIds.Contains(y.TaskId) && y.Date >= fromDate && y.Date <= toDate).ToList();

            foreach (var task in tasks)
            {
                var currentTask = task;
                foreach (var item in completedTaskItems.Where(item => item.TaskId == currentTask.Id))
                {
                    task.CompletedTaskItems.Add(item);
                }
            }

            return(tasks);
        }
Example #25
0
        /// <summary>
        /// Updates the specified where.
        /// </summary>
        /// <param name="where">The where.</param>
        /// <param name="action">The action.</param>
        public virtual void Update(Expression <Func <TEntity, bool> > @where, Action <TEntity> action)
        {
            var objects = Dbset.Where(where);

            //objects.ForEach(entity =>
            //{
            //    Dbset.Attach(entity);
            //    var entityEntry = _dataContext.Entry(entity);
            //    action(entity);
            //    entityEntry.State = EntityState.Modified;
            //});
            foreach (TEntity entity in objects)
            {
                Dbset.Attach(entity);
                var entityEntry = _dataContext.Entry(entity);
                action(entity);
                entityEntry.State = EntityState.Modified;
            }
        }
        public override async Task UpdateAsync(MeetingContent entityToUpdate)
        {
            var existsEntity = await GetAsync(entityToUpdate.Id);

            if (existsEntity.Ordinal != entityToUpdate.Ordinal)
            {
                if (existsEntity.Ordinal > entityToUpdate.Ordinal)
                {
                    var itemsToUpdate = Dbset.Where(x =>
                                                    x.MeetingAgendaId == entityToUpdate.MeetingAgendaId &&
                                                    x.Ordinal >= entityToUpdate.Ordinal &&
                                                    x.Ordinal < existsEntity.Ordinal &&
                                                    x.Id != entityToUpdate.Id);
                    foreach (var item in itemsToUpdate)
                    {
                        item.Ordinal     = item.Ordinal + 1;
                        item.UpdatedBy   = entityToUpdate.UpdatedBy;
                        item.UpdatedDate = DateTime.Now;
                    }
                }
                else
                {
                    var itemsToUpdate = Dbset.Where(x =>
                                                    x.MeetingAgendaId == entityToUpdate.MeetingAgendaId &&
                                                    x.Ordinal > existsEntity.Ordinal &&
                                                    x.Ordinal <= entityToUpdate.Ordinal &&
                                                    x.Id != entityToUpdate.Id);
                    foreach (var item in itemsToUpdate)
                    {
                        item.Ordinal     = item.Ordinal - 1;
                        item.UpdatedBy   = entityToUpdate.UpdatedBy;
                        item.UpdatedDate = DateTime.Now;
                    }
                }
            }

            existsEntity.FileName    = entityToUpdate.FileName;
            existsEntity.FileBase64  = entityToUpdate.FileBase64;
            existsEntity.Ordinal     = entityToUpdate.Ordinal;
            existsEntity.UpdatedBy   = entityToUpdate.UpdatedBy;
            existsEntity.UpdatedDate = DateTime.Now;
        }
Example #27
0
        public TaskTheme ThemeAutoPick(int userId)
        {
            var userTaskThemes = Dbset.Where(x => x.UserId == userId && x.IsArchived == false).Select(x => (int)x.Theme).Distinct().ToArray();
            var allThemes = Enum.GetValues(typeof(TaskTheme));
            var allValidThemes = Enumerable.Range(1, allThemes.Length - 1).ToArray();
            var random = new Random();
            int randomIndex, theme;

            if (userTaskThemes.Count() == allValidThemes.Length)
            {
                randomIndex = random.Next(0, allValidThemes.Length);
                theme       = allValidThemes[randomIndex];
            }
            else
            {
                var unusedThemes = allValidThemes.Except(userTaskThemes).ToArray();
                randomIndex = random.Next(0, unusedThemes.Length);
                theme       = unusedThemes[randomIndex];
            }

            return((TaskTheme)theme);
        }
Example #28
0
        public void Reorder(int oldOrder, int newOrder, int userId)
        {
            var task = Dbset.FirstOrDefault(x => x.UserId == userId && x.IsArchived == false && x.Order == oldOrder);

            if (task == null)
            {
                throw new MyException("Task does not exist in the database.");
            }

            var tasksToReorder = (newOrder > oldOrder) ?
                                 Dbset.Where(x => x.UserId == userId && x.IsArchived == false && x.Order >= oldOrder && x.Order <= newOrder).ToList()
                : Dbset.Where(x => x.UserId == userId && x.IsArchived == false && x.Order <= oldOrder && x.Order >= newOrder).ToList();

            foreach (var taskToReorder in tasksToReorder)
            {
                taskToReorder.Order = (newOrder > oldOrder) ? --taskToReorder.Order : ++taskToReorder.Order;
                _context.Entry(taskToReorder).State = EntityState.Modified;
            }

            task.Order = (byte?)newOrder;
            _context.Entry(task).State = EntityState.Modified;
            _context.SaveChanges();
        }
        public async Task <List <CompanyHeader> > SearchAsync(string ticker, int maxCount)
        {
            var records = await Dbset
                          .Where(c => c.Filtered && c.Ticker.StartsWith(ticker))
                          .OrderBy(c => c.Ticker)
                          .Take(maxCount)
                          .Select(company =>
                                  new CompanyHeader
            {
                Ticker               = company.Ticker,
                Name                 = company.Name,
                LastUpdated          = company.LastUpdated,
                Volume               = company.Volume,
                Price                = company.Price,
                HighestPrice52       = company.HighestPrice52,
                LowestPrice52        = company.LowestPrice52,
                ChaosPercentage      = company.ChaosPercentage,
                UpdateSuccessful     = company.UpdateSuccessful,
                UpdateError          = company.UpdateError,
                Filtered             = company.Filtered,
                MarketCap            = company.MarketCap,
                LastCalculated       = company.LastCalculated,
                NextReportDate       = company.NextReportDate,
                CalculatedSuccessful = company.CalculatedSuccessful,
                CalculatedError      = company.CalculatedError,
                StartDate            = company.StartDate,
                EndDate              = company.EndDate,
                SectorId             = company.SectorId,
                IndustryId           = company.IndustryId,
                SP500                = company.SP500,
                IsIndex              = company.IsIndex,
            })
                          .ToListAsync();

            return(records);
        }
        public async Task <List <AccountTradeEntity> > GetTrades(int accountId, DateTime from, DateTime to)
        {
            var records = await Dbset.Where(r => r.AccountId == accountId && r.EntryDate > from && r.EntryDate < to).OrderBy(r => r.EntryDate).ToListAsync();

            return(records);
        }