public async Task <IActionResult> Edit(int id, [Bind("HomeworkId,CourseId,AssignmentId,Due,Description")] Homework homework)
        {
            if (id != homework.HomeworkId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(homework);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!HomeworkExists(homework.HomeworkId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                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));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Date,Theme,OpeningSong,OpeningPrayer,Conducting,SacramentHymn,Speaker1,TalkTopic1,Speaker2,TalkTopic2,ClosingSong,ClosingPrayer")] Plan plan)
        {
            if (id != plan.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(plan);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!planExists(plan.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(plan));
        }
        public async Task <IActionResult> Edit(int id, [Bind("AssignmentId,Name")] Assignment assignment)
        {
            if (id != assignment.AssignmentId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(assignment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AssignmentExists(assignment.AssignmentId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(assignment));
        }
Exemple #4
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,SacramentDate,Conducting,OpeningHymn,Invocation,SacramentHymn,FirstSpeaker,SecondSpeaker,RestHymn,ThirdSpeaker,ClosingHymn,Convocation")] Sacrament sacrament)
        {
            if (id != sacrament.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(sacrament);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SacramentExists(sacrament.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(sacrament));
        }
        public async Task <IActionResult> Edit(int id, [Bind("CourseId,Name")] Course course)
        {
            if (id != course.CourseId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(course);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CourseExists(course.CourseId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(course));
        }
        public async Task <IActionResult> Edit(int id, [Bind("ID,SacramentDate,Conducting,Hymns,Prayer,Speakers,Subject")] Sacrament sacrament)
        {
            if (id != sacrament.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(sacrament);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SacramentExists(sacrament.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            return(View(sacrament));
        }
Exemple #7
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 #8
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));
        }