public async Task <IActionResult> Edit(int id, [Bind("DailyInformationID,Title,JournalText,DailyInformationDateTime,User,UserMood,GeneratedMood,MinExercising,DownTime, UpTime, MinPhone, MinHobby, NumGoodThings, NumPoorThings, OverallDay, ExcitedForTomorrow")] DailyInformation dailyInformtion) { dailyInformtion.HoursSlept = (dailyInformtion.DownTime.Hour - dailyInformtion.UpTime.Hour) / 2; if (id != dailyInformtion.DailyInformationID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(dailyInformtion); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DailyInformtionExists(dailyInformtion.DailyInformationID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(dailyInformtion)); }
public async Task <IActionResult> Create([Bind("DailyInformationID,Title,JournalText,DailyInformationDateTime,User,UserMood,GeneratedMood,MinExercising,DownTime, UpTime, MinPhone, MinHobby, NumGoodThings, NumPoorThings, OverallDay, ExcitedForTomorrow")] DailyInformation dailyInformtion) { dailyInformtion.HoursSlept = (dailyInformtion.DownTime.Hour - dailyInformtion.UpTime.Hour) / 2; if (ModelState.IsValid) { string errorText = string.Empty; ApiData apiData = dailyInformtion.CreateWatsonReport(_configuration); if (apiData != null) { _context.Add(apiData); dailyInformtion.ApiData = apiData; dailyInformtion.GoneThroughWatson = true; } else { errorText = "Cound't Get Report from Watson Api. You Form was still submited."; } dailyInformtion.ApplicationUser = await _userManager.GetUserAsync(User); dailyInformtion.DailyInformationDateTime = DateTime.Now; _context.Add(dailyInformtion); await _context.SaveChangesAsync(); return(RedirectToAction("Index", new { error = errorText })); } return(View(dailyInformtion)); }
// Custom Methods /// <summary> /// Checks to see if the current user owns a journal. /// Doesn't check to see if journal exist /// </summary> /// <param name="journal"> /// A journal object from the JournalContext /// </param> /// <returns> /// Returns true if the user owns the journal, false if not /// </returns> private bool AuthorizeData(DailyInformation dailyInformation) { if (dailyInformation.ApplicationUser.Email == User.Identity.Name) { return(true); } return(false); }