Beispiel #1
0
        public async Task Execute(IJobExecutionContext context)
        {
            try
            {
                var projects = await _db.Projects.Where(p => p.Status == Project.ProjectStatusEnum.Ongoing &&
                                                        p.ExpireDate <= HelperMethod.GetCurrentDateTimeWithTimeZone(DateTime.UtcNow))
                               .ToListAsync();

                foreach (var item in projects)
                {
                    if (item.CurrentFund < item.Goal)
                    {
                        item.Status           = Project.ProjectStatusEnum.Suspended;
                        _db.Entry(item).State = EntityState.Modified;
                        await _db.SaveChangesAsync();

                        await HelperMethod.FailProject(item.Id);
                    }
                    else
                    {
                        item.Status           = Project.ProjectStatusEnum.Success;
                        _db.Entry(item).State = EntityState.Modified;
                        await _db.SaveChangesAsync();

                        await HelperMethod.SuccessProject(item.Id);
                    }
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                Console.WriteLine(e);
            }
        }