public async Task <IActionResult> Create(Report newReport)
        {
            if (ModelState.IsValid)
            {
                var userId = User.FindFirstValue(ClaimTypes.NameIdentifier) ?? throw new ArgumentNullException("User.FindFirstValue(ClaimTypes.NameIdentifier)");
                newReport.UserId = userId;

                // if (newReport.SendingSchedule == "hourly")
                // {
                //     newReport.NextScheduledDate = DateTime.Now.AddHours(1);
                // } else if (newReport.SendingSchedule == "daily")
                // {
                //     newReport.NextScheduledDate = DateTime.Now.AddDays(1);
                // } else if (newReport.SendingSchedule == "weekly")
                // {
                //     newReport.NextScheduledDate = DateTime.Now.AddDays(7);
                // } else
                // {
                //     newReport.NextScheduledDate = DateTime.Now;
                // }

                // For testing purposes, override schedule on report creation
                newReport.ScheduleOverride = true;

                await _context.AddAsync(newReport);

                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(newReport));
        }
Exemple #2
0
        public async Task AddAsync(T entity)
        {
            Assert.ArgumentIsNull(entity, nameof(entity));

            await _context.Set <T>().AddAsync(entity);

            await _context.SaveChangesAsync();
        }
        public async Task <IActionResult> Create([Bind("Name")] Assignment assignment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(assignment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(assignment));
        }
Exemple #4
0
        public async Task <IActionResult> Create([Bind("ID,SacramentDate,Conducting,OpeningHymn,Invocation,SacramentHymn,FirstSpeaker,SecondSpeaker,RestHymn,ThirdSpeaker,ClosingHymn,Convocation")] Sacrament sacrament)
        {
            if (ModelState.IsValid)
            {
                _context.Add(sacrament);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(sacrament));
        }
        public async Task <IActionResult> Create([Bind("ID,SacramentDate,Conducting,Hymns,Prayer,Speakers,Subject")] Sacrament sacrament)
        {
            if (ModelState.IsValid)
            {
                _context.Add(sacrament);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(sacrament));
        }
        public async Task <IActionResult> Create([Bind("Id,Date,Theme,OpeningSong,OpeningPrayer,Conducting,SacramentHymn,Speaker1,TalkTopic1,Speaker2,TalkTopic2,ClosingSong,ClosingPrayer")] Plan plan)
        {
            if (ModelState.IsValid)
            {
                _context.Add(plan);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(plan));
        }
        public async Task <ActionResult> Create([Bind(Include = "VotingId,Name,Description,IsOpenQuestion")] Voting voting)
        {
            if (ModelState.IsValid)
            {
                db.Voting.Add(voting);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(voting));
        }
Exemple #8
0
        public async Task <ActionResult> Create([Bind(Include = "VotingAnswerId,AnswerText,VotingId")] VotingAnswer votingAnswer)
        {
            if (ModelState.IsValid)
            {
                db.VotingAnswer.Add(votingAnswer);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(votingAnswer));
        }
        public async Task <ActionResult> Create([Bind(Include = "VoteId,OpenAnswer")] Vote vote)
        {
            if (ModelState.IsValid)
            {
                db.Vote.Add(vote);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(vote));
        }
        public async Task <IActionResult> Create([Bind("HomeworkId,CourseId,AssignmentId,Due,Description")] Homework homework)
        {
            if (ModelState.IsValid)
            {
                _context.Add(homework);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AssignmentId"] = new SelectList(_context.Assignment, "AssignmentId", "Name", homework.AssignmentId);
            ViewData["CourseId"]     = new SelectList(_context.Course, "CourseId", "Name", homework.CourseId);
            return(View(homework));
        }
Exemple #11
0
        public async Task <IActionResult> Register(RegisterViewModel userModel)
        {
            if (ModelState.IsValid)
            {
                var user = new IdentityUser {
                    UserName = userModel.Email, Email = userModel.Email
                };
                var result = await _userManager.CreateAsync(user, userModel.Password);

                var wallet = new Wallet();
                wallet.Amount = 0;
                wallet.UserId = user.Id;

                await _context.Wallets.AddAsync(wallet);

                await _context.SaveChangesAsync();

                if (result.Succeeded)
                {
                    await _signInManager.SignInAsync(user, isPersistent : false);

                    return(RedirectToAction("Index", "Home"));
                }

                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError("", error.Description);
                }
            }

            return(View(userModel));
        }
        public async Task <IActionResult> Create(PlanningViewModel newPlanModel)
        {
            if (ModelState.IsValid)
            {
                var userId       = User.FindFirstValue(ClaimTypes.NameIdentifier) ?? throw new ArgumentNullException("User.FindFirstValue(ClaimTypes.NameIdentifier)");
                var goalStatuses = await _context.GoalStatuses.ToListAsync();

                var inProgressGoalStatus = goalStatuses.Find(x => x.Status == "In Progress").Id;

                var planStatuses = await _context.PlanStatuses.ToListAsync();

                var inProgressPlanStatus = planStatuses.Find(x => x.Status == "In Progress").Id;

                var newPlan = new Plan
                {
                    Title           = newPlanModel.Title,
                    EventCategoryId = newPlanModel.EventCategoryId,
                    UserId          = userId
                };
                await _context.AddAsync(newPlan);

                await _context.SaveChangesAsync();

                if (newPlanModel.Goals.Count > 0)
                {
                    foreach (var goal in newPlanModel.Goals)
                    {
                        var newGoal = new Goal
                        {
                            PlanId            = newPlan.Id,
                            GoalTypeId        = goal.GoalTypeId,
                            GoalStatusId      = inProgressGoalStatus,
                            Title             = goal.Title,
                            NumericalTarget   = goal.NumericalTarget,
                            NumericalProgress = goal.NumericalProgress
                        };
                        await _context.AddAsync(newGoal);
                    }
                    newPlan.PlanStatusId = inProgressPlanStatus;
                }

                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(newPlanModel));
        }
Exemple #13
0
        public async Task <ActionResult <Task> > PostTask(Task task)
        {
            _context.Task.Add(task);

            await _context.SaveChangesAsync();

            return(Ok());
        }
Exemple #14
0
        public async Task <IActionResult> TaskType([FromBody] TaskType taskType)
        {
            _context.TaskType.Add(taskType);

            await _context.SaveChangesAsync();

            return(Ok(taskType));
        }
Exemple #15
0
        public async Task Execute(IJobExecutionContext context)
        {
            List <IdentityUser> users = await GetUsers();

            foreach (var user in users)
            {
                var userId = user.Id;
                var email  = user.Email;

                using (var msg = new MailMessage("*****@*****.**", email))
                {
                    var reports = await GetReports(userId);

                    var currentDateTime = DateTime.Now;
                    var reportsToSend   = reports.Where(r => (r.NextScheduledDate - currentDateTime).TotalSeconds < 60 || r.ScheduleOverride).ToList();

                    if (reportsToSend.Any())
                    {
                        foreach (var report in reportsToSend)
                        {
                            var title = report.Title;
                            var plan  = await GetPlan(report.PlantId);

                            var goals = await GetGoals(plan.Id);

                            msg.Subject = title + " notification";
                            msg.Body    = "";
                            if (plan != null)
                            {
                                msg.Body += "Hi!\n Here's a status update about your plan " + plan.Title + "\n";
                                msg.Body += "Goals:\n";
                                foreach (var goal in goals)
                                {
                                    msg.Body += "Title: " + goal.Title + "\n";
                                    msg.Body += "Target: " + goal.NumericalTarget + "\n";
                                    msg.Body += "Progress: " + goal.NumericalProgress + "\n";
                                }
                            }
                            using (SmtpClient sc = new SmtpClient())
                            {
                                sc.EnableSsl   = true;
                                sc.Host        = "smtp.gmail.com";
                                sc.Port        = 587;
                                sc.Credentials = new NetworkCredential("*****@*****.**", "jE6hxxcN5RApxscWqmhv");
                                // sc.Send(msg);
                            }

                            if (report.ScheduleOverride)
                            {
                                report.ScheduleOverride = false;
                            }
                            else
                            {
                                if (report.SendingSchedule == "hourly")
                                {
                                    report.NextScheduledDate = DateTime.Now.AddHours(1);
                                }
                                else if (report.SendingSchedule == "daily")
                                {
                                    report.NextScheduledDate = DateTime.Now.AddDays(1);
                                }
                                else if (report.SendingSchedule == "weekly")
                                {
                                    report.NextScheduledDate = DateTime.Now.AddDays(7);
                                }
                            }

                            _context.Update(report);
                            await _context.SaveChangesAsync();
                        }
                    }
                }
            }
        }
Exemple #16
0
        public async Task <IActionResult> Create([Bind("Title,Description,StartDate,EndDate,EventCategoryId,GoalId,GoalTypeId,EventStatusId")] Event newEvent, int financialAmount, int fitnessDistance, int fitnessDuration)
        {
            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier) ?? throw new ArgumentNullException("User.FindFirstValue(ClaimTypes.NameIdentifier)");

            newEvent.CreatedAt = DateTime.Now;
            newEvent.UserId    = User.FindFirstValue(ClaimTypes.NameIdentifier);


            if (ModelState.IsValid)
            {
                bool goalAdded = false;
                var  goalType  = await _context.GoalTypes.FindAsync(newEvent.GoalTypeId);

                var goalStatuses = await _context.GoalStatuses.ToListAsync();


                if (newEvent.GoalId != 0)
                {
                    goalAdded = true;
                }

                if (goalType.Name == "Financial")
                {
                    var financialEvent = new FinancialEvent {
                        Amount = financialAmount
                    };
                    var wallet = await _context.Wallets.Where(x => x.UserId == userId).ToListAsync();

                    wallet[0].Amount -= financialAmount;
                    _context.Update(wallet[0]);

                    if (goalAdded)
                    {
                        var goal = await _context.Goals.FindAsync(newEvent.GoalId);

                        goal.NumericalProgress += financialAmount;
                        if (goal.NumericalProgress >= goal.NumericalTarget)
                        {
                            goal.GoalStatusId = goalStatuses.Find(x => x.Status == "Succeeded").Id;
                        }
                        else
                        {
                            goal.GoalStatusId = goalStatuses.Find(x => x.Status == "In Progress").Id;
                        }

                        _context.Update(goal);
                    }

                    await _context.FinancialEvents.AddAsync(financialEvent);

                    await _context.SaveChangesAsync();

                    newEvent.FinancialEventId = financialEvent.Id;
                }
                else if (goalType.Name == "Fitness")
                {
                    var fitnessEvent = new FitnessEvent();
                    fitnessEvent.Distance = fitnessDistance;
                    fitnessEvent.Duration = 0;

                    if (goalAdded)
                    {
                        var goal = await _context.Goals.FindAsync(newEvent.GoalId);

                        goal.NumericalProgress += fitnessDistance;
                        if (goal.NumericalProgress >= goal.NumericalTarget)
                        {
                            goal.GoalStatusId = goalStatuses.Find(x => x.Status == "Succeeded").Id;
                        }
                        else
                        {
                            goal.GoalStatusId = goalStatuses.Find(x => x.Status == "In Progress").Id;
                        }

                        _context.Update(goal);
                    }

                    await _context.FitnessEvents.AddAsync(fitnessEvent);

                    await _context.SaveChangesAsync();

                    newEvent.FitnessEventId = fitnessEvent.Id;
                }
                else if (goalType.Name == "General")
                {
                    if (goalAdded)
                    {
                        var goal = await _context.Goals.FindAsync(newEvent.GoalId);

                        goal.GoalStatusId = goalStatuses.Find(x => x.Status == "Succeeded").Id;

                        _context.Update(goal);
                    }
                    await _context.SaveChangesAsync();
                }

                await _context.AddAsync(newEvent);

                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(newEvent));
        }
Exemple #17
0
        public async Task ExecuteAsync(CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return;
            }

            this.PrettyPrint("Start fetching Events Data..", ConsoleColor.Green);

            var optionsBuilder = new DbContextOptionsBuilder <PlannerContext>();

            optionsBuilder.UseMySql(ConnectionString);

            using (var db = new PlannerContext(optionsBuilder.Options)) {
                this.PrettyPrint("Database connection established");

                bool shouldBeProc = await db.Event.AnyAsync(Condition, cancellationToken);

                if (shouldBeProc)
                {
                    Event[] @events = await db.Event.Where(Condition).ToArrayAsync(cancellationToken);

                    foreach (var @event in @events)
                    {
                        var from = @event.Status;

                        if (@event.HasSubscriptionWindow() && @event.SubscribtionOpen())
                        {
                            @event.Status = Status.SUBSCRIPTION;
                        }
                        else if (@event.OnGoingWindow())
                        {
                            @event.Status = Status.ONGOING;
                        }
                        else if (@event.CloseAt >= DateTime.Now &&
                                 ([email protected]() || @event.EndAt <= DateTime.Now))
                        {
                            @event.Status = Status.INCOMING;
                        }
                        else if (@event.CloseAt <= DateTime.Now)
                        {
                            @event.Status = Status.DONE;

                            // Remove top event when event is done
                            int       id  = @event.Id;
                            TopEvents top = db.Tops.FirstOrDefault(e => e.EventId == id);
                            if (top != null)
                            {
                                ITopEventServices service = new TopEventServices(db) as ITopEventServices;
                                TopEvents[]       tops    = db.Tops.Where(e => e.EventId != id)
                                                            .OrderBy(e => e.Index).ToArray();
                                service.ReArrangeTopEvents(tops);

                                db.Tops.Remove(top);
                                db.Tops.UpdateRange(tops);
                            }
                        }
                        else
                        {
                            @event.Status = Status.PENDING;
                        }

                        this.PrettyPrint($"Event: {@event.Id} is updating from: [{from}] to: [{@event.Status}] ");
                    }

                    try {
                        db.Event.UpdateRange(@events);
                        await db.SaveChangesAsync(cancellationToken);
                    } catch (DbUpdateException exception) {
                        this.PrettyPrint($"Error: {exception.Message}", ConsoleColor.Red);
                        throw exception;
                    }

                    this.PrettyPrint($"Event Updated: {@events.Count()}", ConsoleColor.Green);
                }
                else
                {
                    this.PrettyPrint("No Event available for update", ConsoleColor.Cyan);
                }
            }
        }