public ActionResult Feedback(DiaryEntries mentfeedback) { if (string.IsNullOrEmpty(mentfeedback.MentorFeedback)) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DiaryEntries diaryEntries = db.DiaryEntries.Find(mentfeedback.Id); if (diaryEntries == null) { return(HttpNotFound()); } diaryEntries.MentorFeedback = mentfeedback.MentorFeedback; db.Entry(diaryEntries).State = EntityState.Modified; db.SaveChanges(); var UserManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>(); var menteeUser = UserManager.FindById(mentfeedback.UsersId); var mentee = db.Users.Find(mentfeedback.UsersId); var mentor = db.Users.Find(mentee.MentorId); EmailController mail = new EmailController(); mail.FeedbackProvided(menteeUser.Email, mentee.FirstName, mentor.FirstName, mentor.LastName); // Type options : info, danger, success, warning TempData["UserMessage"] = new JavaScriptSerializer().Serialize(new { Type = "success", Title = "Success!", Message = "Feedback added correctly!" }); //return RedirectToAction("Dashboard", "DiaryEntries"); return(View(diaryEntries)); }
public void DeleteEntry(DiaryEntry entryToDelete) { if (DiaryEntries != null) { DiaryEntries.Remove(entryToDelete); } }
public void AddNewEntry(DiaryEntry newEntry) { if (DiaryEntries == null) { DiaryEntries = new ObservableCollection <DiaryEntry>(); } DiaryEntries.Add(newEntry); }
private async void RemoveEntry(ViewModel_DiaryEntry entry) { //Removes an entry bool answer = await App.Current.MainPage.DisplayAlert("Removing a Diary Entry", "Are you sure you want to delete this Diary Entry?", "Yes", "No"); if (answer == true) { Console.WriteLine("Removing Entry "); DiaryEntries.Remove(entry); List <ViewModel_DiaryPage> entries = new List <ViewModel_DiaryPage>(DiaryEntries); UserDiaryFileController.Save(entries); } }
//Creates a new Entry in the Diary with the EDITING state private void CreateEntry() { //Creates a new entry if (DiaryEntries.Count <= 50) //Diary Cover counts as diary Entry { ViewModel_DiaryPage newEntry = new ViewModel_DiaryEntry() { Entry = new DiaryEntry() { FirstSubmit = DateTime.Now }, CurrentState = ViewModel_DiaryPage.PageState.EDITING }; DiaryEntries.Add(newEntry); NewDiaryEntryAdded(this, EventArgs.Empty); } else { EntryLimitReached(this, EventArgs.Empty); } }
private void EditEntry(ViewModel_DiaryEntry entry) { //Edits an entry Console.WriteLine(entry); //Triggered when the user clicks the EditEntry or NewEntry button if (entry.CurrentState == ViewModel_DiaryPage.PageState.COMPLETED) { //If it was a new frame, change the first submit field Console.WriteLine("Setting First Submit"); (entry.Entry).FirstSubmit = DateTime.Now; (entry.Entry).LastEdited = DateTime.Now; } //Finally, change the current entry to be EDIT state //entry.CurrentState = ViewModel_DiaryEntry.DiaryEntryState.EDITING; ViewModel_DiaryEntry updatedEntry = new ViewModel_DiaryEntry() { Entry = entry.Entry, CurrentState = ViewModel_DiaryPage.PageState.EDITING }; int i = DiaryEntries.IndexOf(entry); DiaryEntries[i] = updatedEntry; }
//Saves the Diary Entry public void SaveEntry(ViewModel_DiaryEntry entry) { //Saves an entry Console.WriteLine("Saving Entry " + entry.CurrentState); entry.Entry.LastEdited = DateTime.Now; AppPreferences.LastDiaryEntry = entry.Entry.LastEdited; ViewModel_DiaryEntry updatedEntry = new ViewModel_DiaryEntry() { Entry = entry.Entry }; updatedEntry.CurrentState = ViewModel_DiaryPage.PageState.COMPLETED; int i = DiaryEntries.IndexOf(entry); DiaryEntries[i] = updatedEntry; List <ViewModel_DiaryPage> entries = new List <ViewModel_DiaryPage>(DiaryEntries); //Adds current diary list from viewmodel UserDiaryFileController.Save(entries); }
public ActionResult Create([Bind(Include = "Id,Entry,UsersId,MentorId,SentimentScore,MentorFeedback,Date,MenteeFeedback")] DiaryEntries diaryEntries) { // Calculate the sentiment score of the text to save it in the database SentimentPy sent = new SentimentPy(); var score = sent.getSentimentScore(diaryEntries.Entry); diaryEntries.SentimentScore = score; // Get the user's information and update the diary before saving it ApplicationUser user = System.Web.HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId <int>()); Users currentUser = db.Users.Find(user.Id); diaryEntries.UsersId = currentUser.Id; diaryEntries.MentorId = currentUser.MentorId.Value; diaryEntries.Date = DateTime.Now; if (ModelState.IsValid) { // Save changes to DB db.DiaryEntries.Add(diaryEntries); db.SaveChanges(); // Send e-mail to mentor EmailController mail = new EmailController(); var UserManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>(); var users = UserManager.FindById(diaryEntries.MentorId); Users mentor = db.Users.Find(users.Id); mail.NewDiary(users.Email, mentor.FirstName, currentUser.FirstName, currentUser.LastName); // Type options : info, danger, success, warning TempData["UserMessage"] = new JavaScriptSerializer().Serialize(new { Type = "success", Title = "Success!", Message = "Diary entry added correctly!" }); return(View()); } ViewBag.UsersId = new SelectList(db.Users, "Id", "FirstName", diaryEntries.UsersId); return(View(diaryEntries)); }
public ActionResult Feedback(int Id) { DiaryEntries diaryEntries = db.DiaryEntries.Find(Id); return(View(diaryEntries)); }