public async Task <IActionResult> PutChildrenWork([FromRoute] int id, [FromBody] ChildrenWork childrenWork)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != childrenWork.ID)
            {
                return(BadRequest());
            }

            _context.Entry(childrenWork).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ChildrenWorkExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PostChildrenWork([FromBody] ChildrenWork childrenWork)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.ChildWorkList.Add(childrenWork);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetChildrenWork", new { id = childrenWork.ID }, childrenWork));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("ID,Chore,RoomID,UserID,DollarAmount,ParentID,DateDue,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday,ChoreCompleted,DateChoreCompleted,ParentVerified,ParentVerifiedDate,ChoreID")] ChildrenWork childrenWork)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(childrenWork);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                return(View(childrenWork));
            }
            catch (Exception ex)
            {
                _logger.LogError(string.Format("{0} - Error Message: {1}", System.Reflection.MethodBase.GetCurrentMethod(), ex.Message));
                return(RedirectToAction("Index", "StatusCode", 500));
            }
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> CompleteChore(IFormCollection CompletedChores)
        {
            try
            {
                string completedchores = Convert.ToString(CompletedChores["CompletedChores"]);
                ViewBag.Results = completedchores;
                List <string> completedchoreList = new List <string>();
                if (string.IsNullOrEmpty(completedchores) == false)
                {
                    IList <CompletedChoresList> completedchoreslist = JsonConvert.DeserializeObject <List <CompletedChoresList> >(completedchores);
                    //Update the Childrens work table.
                    foreach (CompletedChoresList item in completedchoreslist)
                    {
                        ChildrenWork chore = _context.ChildWorkList.Where(a => a.ID == item.TaskID).FirstOrDefault();
                        if (chore != null)
                        {
                            //update the chore
                            chore.MondayCompleted    = (item.Monday == 1) ? true : false;
                            chore.TuesdayCompleted   = (item.Tuesday == 1) ? true : false;
                            chore.WednesdayCompleted = (item.Wednesday == 1) ? true : false;
                            chore.ThursdayCompleted  = (item.Thursday == 1) ? true : false;
                            chore.FridayCompleted    = (item.Friday == 1) ? true : false;
                            chore.SaturdayCompleted  = (item.Saturday == 1) ? true : false;
                            chore.SundayCompleted    = (item.Sunday == 1) ? true : false;
                            chore.ChoreCompleted     = true;
                            chore.DateChoreCompleted = DateTime.Now;
                            chore.ParentVerified     = false;

                            _context.ChildWorkList.Update(chore);
                            await _context.SaveChangesAsync();

                            //Get the chore name
                            var chorename = _context.ChoreTypes.Where(b => b.ID == Convert.ToInt16(chore.Chore)).FirstOrDefault();
                            if (chorename != null)
                            {
                                completedchoreList.Add(chorename.Chore);
                            }
                        }
                    }
                }

                /* Get an instance of the logged in child user. */
                var user = await _userManager.GetUserAsync(User);

                if (user == null)
                {
                    throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
                }

                var    childID = user.Id;
                string message = string.Format("Unicorn Chores: {0} has completed the following chores: {1}. Click on this link https://goo.gl/1kNbd6 to confirm that {0} chore(s) has been completed.", user.FirstName, String.Join(",", completedchoreList.ToArray <string>()));
                //Get parents ids as well.
                List <AccountAssociations> parentIDs = _context.AccountAssociations.Where(a => a.AssociatedUserID == childID).ToList <AccountAssociations>();
                if (parentIDs.Count != 0)
                {
                    List <string> phoneNumbers = new List <string>();
                    foreach (AccountAssociations parent in parentIDs)
                    {
                        //Get the parent profile record.
                        var parentProfile = _context.AccountUsers.Where(b => b.Id == parent.PrimaryUserID).FirstOrDefault();
                        if (parentProfile != null)
                        {
                            //Add the parent's phone number to the list.
                            phoneNumbers.Add(parentProfile.PhoneNumber);
                        }
                    }
                    //Notify the parents that a task has been completed.
                    await _smsSender.SendSMSMessage(message, phoneNumbers);
                }
                else
                {
                    throw new ApplicationException("There are not phone numbers to text.");
                }
                //ITwilioRestClient _client;
                //string _accountSid = "AC907f2ca57b80571d219274b8c056cc21";
                //string _authToken = "729d26355cd483620071a7d3bb56d501";
                //string twilioNumber = "+14126936790";

                //string message = string.Format("Unicorn Chores: {0} has completed the following chores {1}. Click on the https://tinyurl.com/1zq to access to the Unicron site and acess Completed Chores for further details.", user.FirstName, String.Join(",", completedchoreList.ToArray<string>()));
                //_client = new TwilioRestClient(_accountSid, _authToken);
                //var mommyPhoneNumber = new PhoneNumber(secondphonenumber);
                //var daddyPhoneNumber = new PhoneNumber("+17249141738");
                //MessageResource.Create(mommyPhoneNumber, from: new PhoneNumber(twilioNumber),body: message, client: _client);
                //MessageResource.Create(daddyPhoneNumber, from: new PhoneNumber(twilioNumber),body: message, client: _client);

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                _logger.LogError(string.Format("{0} - Error Message: {1}", System.Reflection.MethodBase.GetCurrentMethod(), ex.Message));
                return(RedirectToAction("Index", "StatusCode", 500));
            }
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> PublishChore(int id)
        {
            try
            {
                //Grab an instance of the chore.
                var chore = _context.UserChores.Where(a => a.ID == id).FirstOrDefault();
                if (chore != null)
                {
                    //Check to see if this is a new record or an old record.
                    List <ChildrenWork> workitems = _context.ChildWorkList.Where(a => a.ChoreID == id).ToList();
                    if (workitems.Count != 0)
                    {
                        // Delete all the records
                        _context.ChildWorkList.RemoveRange(_context.ChildWorkList.Where(a => a.ChoreID == id).ToList <ChildrenWork>());
                        await _context.SaveChangesAsync();
                    }


                    //Enter each chore as a seperate record for each day.
                    if (chore.Monday)
                    {
                        var workitem = new ChildrenWork()
                        {
                            Chore                  = chore.Chore,
                            ChoreID                = id,
                            RoomID                 = chore.RoomID,
                            UserID                 = chore.UserID,
                            DollarAmount           = chore.DollarAmount,
                            ParentID               = chore.ParentID,
                            DateDue                = chore.DateDue,
                            Monday                 = true,
                            Tuesday                = false,
                            Wednesday              = false,
                            Thursday               = false,
                            Friday                 = false,
                            Saturday               = false,
                            Sunday                 = false,
                            StartOfWeekDate        = UtilityService.GetFirstDayOfWeek(DateTime.Now),
                            StartOfWeekDateDisplay = UtilityService.GetFirstDayOfWeek(DateTime.Now).ToString("MM/dd/yyyy"),
                            ChoreDescription       = chore.ChoreDescription
                        };
                        _context.ChildWorkList.Add(workitem);
                    }
                    if (chore.Tuesday)
                    {
                        var workitem = new ChildrenWork()
                        {
                            Chore                  = chore.Chore,
                            ChoreID                = id,
                            RoomID                 = chore.RoomID,
                            UserID                 = chore.UserID,
                            DollarAmount           = chore.DollarAmount,
                            ParentID               = chore.ParentID,
                            DateDue                = chore.DateDue,
                            Monday                 = false,
                            Tuesday                = true,
                            Wednesday              = false,
                            Thursday               = false,
                            Friday                 = false,
                            Saturday               = false,
                            Sunday                 = false,
                            StartOfWeekDate        = UtilityService.GetFirstDayOfWeek(DateTime.Now),
                            StartOfWeekDateDisplay = UtilityService.GetFirstDayOfWeek(DateTime.Now).ToString("MM/dd/yyyy"),
                            ChoreDescription       = chore.ChoreDescription
                        };
                        _context.ChildWorkList.Add(workitem);
                    }
                    if (chore.Wednesday)
                    {
                        var workitem = new ChildrenWork()
                        {
                            Chore                  = chore.Chore,
                            ChoreID                = id,
                            RoomID                 = chore.RoomID,
                            UserID                 = chore.UserID,
                            DollarAmount           = chore.DollarAmount,
                            ParentID               = chore.ParentID,
                            DateDue                = chore.DateDue,
                            Monday                 = false,
                            Tuesday                = false,
                            Wednesday              = true,
                            Thursday               = false,
                            Friday                 = false,
                            Saturday               = false,
                            Sunday                 = false,
                            StartOfWeekDate        = UtilityService.GetFirstDayOfWeek(DateTime.Now),
                            StartOfWeekDateDisplay = UtilityService.GetFirstDayOfWeek(DateTime.Now).ToString("MM/dd/yyyy"),
                            ChoreDescription       = chore.ChoreDescription
                        };
                        _context.ChildWorkList.Add(workitem);
                    }
                    if (chore.Thursday)
                    {
                        var workitem = new ChildrenWork()
                        {
                            Chore                  = chore.Chore,
                            ChoreID                = id,
                            RoomID                 = chore.RoomID,
                            UserID                 = chore.UserID,
                            DollarAmount           = chore.DollarAmount,
                            ParentID               = chore.ParentID,
                            DateDue                = chore.DateDue,
                            Monday                 = false,
                            Tuesday                = false,
                            Wednesday              = false,
                            Thursday               = true,
                            Friday                 = false,
                            Saturday               = false,
                            Sunday                 = false,
                            StartOfWeekDate        = UtilityService.GetFirstDayOfWeek(DateTime.Now),
                            StartOfWeekDateDisplay = UtilityService.GetFirstDayOfWeek(DateTime.Now).ToString("MM/dd/yyyy"),
                            ChoreDescription       = chore.ChoreDescription
                        };
                        _context.ChildWorkList.Add(workitem);
                    }
                    if (chore.Friday)
                    {
                        var workitem = new ChildrenWork()
                        {
                            Chore                  = chore.Chore,
                            ChoreID                = id,
                            RoomID                 = chore.RoomID,
                            UserID                 = chore.UserID,
                            DollarAmount           = chore.DollarAmount,
                            ParentID               = chore.ParentID,
                            DateDue                = chore.DateDue,
                            Monday                 = false,
                            Tuesday                = false,
                            Wednesday              = false,
                            Thursday               = false,
                            Friday                 = true,
                            Saturday               = false,
                            Sunday                 = false,
                            StartOfWeekDate        = UtilityService.GetFirstDayOfWeek(DateTime.Now),
                            StartOfWeekDateDisplay = UtilityService.GetFirstDayOfWeek(DateTime.Now).ToString("MM/dd/yyyy"),
                            ChoreDescription       = chore.ChoreDescription
                        };
                        _context.ChildWorkList.Add(workitem);
                    }
                    if (chore.Saturday)
                    {
                        var workitem = new ChildrenWork()
                        {
                            Chore                  = chore.Chore,
                            ChoreID                = id,
                            RoomID                 = chore.RoomID,
                            UserID                 = chore.UserID,
                            DollarAmount           = chore.DollarAmount,
                            ParentID               = chore.ParentID,
                            DateDue                = chore.DateDue,
                            Monday                 = false,
                            Tuesday                = false,
                            Wednesday              = false,
                            Thursday               = false,
                            Friday                 = false,
                            Saturday               = true,
                            Sunday                 = false,
                            StartOfWeekDate        = UtilityService.GetFirstDayOfWeek(DateTime.Now),
                            StartOfWeekDateDisplay = UtilityService.GetFirstDayOfWeek(DateTime.Now).ToString("MM/dd/yyyy"),
                            ChoreDescription       = chore.ChoreDescription
                        };
                        _context.ChildWorkList.Add(workitem);
                    }
                    if (chore.Sunday)
                    {
                        var workitem = new ChildrenWork()
                        {
                            Chore                  = chore.Chore,
                            ChoreID                = id,
                            RoomID                 = chore.RoomID,
                            UserID                 = chore.UserID,
                            DollarAmount           = chore.DollarAmount,
                            ParentID               = chore.ParentID,
                            DateDue                = chore.DateDue,
                            Monday                 = false,
                            Tuesday                = false,
                            Wednesday              = false,
                            Thursday               = false,
                            Friday                 = false,
                            Saturday               = false,
                            Sunday                 = true,
                            StartOfWeekDate        = UtilityService.GetFirstDayOfWeek(DateTime.Now),
                            StartOfWeekDateDisplay = UtilityService.GetFirstDayOfWeek(DateTime.Now).ToString("MM/dd/yyyy"),
                            ChoreDescription       = chore.ChoreDescription
                        };
                        _context.ChildWorkList.Add(workitem);
                    }



                    await _context.SaveChangesAsync();

                    //Update the Publish Status
                    chore.PublishStatus   = "Published";
                    chore.LastPublishDate = DateTime.Now;
                    _context.UserChores.Update(chore);
                    await _context.SaveChangesAsync();
                }
                else
                {
                    _logger.LogError(string.Format("PublishCore - unable to publish chore id {0}", id));
                    throw new ApplicationException($"Unable to load publish chore.");
                }
                return(RedirectToAction("Index", "Dashboard"));
            }
            catch (Exception ex)
            {
                _logger.LogError(string.Format("{0} - Error Message: {1}", System.Reflection.MethodBase.GetCurrentMethod(), ex.Message));
                return(RedirectToAction("Index", "StatusCode", 500));
            }
        }
        public async Task <IActionResult> ChoreCompleted(int id)
        {
            try
            {
                var user = await _userManager.GetUserAsync(User);

                if (user == null)
                {
                    throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
                }
                else if (user.IsChild == "1")
                {
                    throw new ApplicationException($"User '{user.FirstName}' tried to complete a chore on your behalf.");
                }
                else
                {
                    // Lookup the chore
                    ChildrenWork pendingchore = _context.ChildWorkList.Where(a => a.ID == id).FirstOrDefault();
                    if (pendingchore != null)
                    {
                        pendingchore.ParentVerified     = true;
                        pendingchore.ParentVerifiedDate = DateTime.Now;
                        _context.ChildWorkList.Update(pendingchore);
                        CompletedChildrenWork completedChore = new CompletedChildrenWork()
                        {
                            Chore                  = pendingchore.Chore,
                            RoomID                 = pendingchore.RoomID,
                            UserID                 = pendingchore.UserID,
                            DollarAmount           = pendingchore.DollarAmount,
                            ParentID               = pendingchore.ParentID,
                            DateDue                = pendingchore.DateDue,
                            Monday                 = pendingchore.Monday,
                            MondayCompleted        = pendingchore.MondayCompleted,
                            Tuesday                = pendingchore.Tuesday,
                            TuesdayCompleted       = pendingchore.TuesdayCompleted,
                            Wednesday              = pendingchore.Wednesday,
                            WednesdayCompleted     = pendingchore.WednesdayCompleted,
                            Thursday               = pendingchore.Thursday,
                            ThursdayCompleted      = pendingchore.ThursdayCompleted,
                            Friday                 = pendingchore.Friday,
                            FridayCompleted        = pendingchore.FridayCompleted,
                            Saturday               = pendingchore.Saturday,
                            SaturdayCompleted      = pendingchore.SaturdayCompleted,
                            Sunday                 = pendingchore.Sunday,
                            SundayCompleted        = pendingchore.SundayCompleted,
                            ParentVerified         = pendingchore.ParentVerified,
                            ParentVerifiedDate     = pendingchore.ParentVerifiedDate,
                            ChoreID                = pendingchore.ChoreID,
                            TotalEarned            = pendingchore.TotalEarned,
                            DateChoreCompleted     = pendingchore.DateChoreCompleted,
                            ChoreCompleted         = pendingchore.ChoreCompleted,
                            ChildCompleted         = pendingchore.ChildCompleted,
                            StartOfWeekDate        = UtilityService.GetFirstDayOfWeek(DateTime.Now),
                            StartOfWeekDateDisplay = UtilityService.GetFirstDayOfWeek(DateTime.Now).ToString("MM/dd/yyyy")
                        };
                        _context.CompletedChildWorkList.Add(completedChore);
                        //Save Completed Task to Archive table
                        await _context.SaveChangesAsync();
                    }
                    return(RedirectToAction("CompletedChores", "Dashboard"));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(string.Format("{0} - Error Message: {1}", System.Reflection.MethodBase.GetCurrentMethod(), ex.Message));
                return(RedirectToAction("Index", "StatusCode", 500));
            }
        }