public ActionResult Delete(int id) { var service = new AffirmationService(); var model = service.GetAffirmationById(id); return(View(model)); }
// GET: Affirmation public ActionResult Index() { AffirmationService service = new AffirmationService(); var model = service.GetAffirmations(); return(View(model)); }
public ActionResult Edit(int id) { var service = new AffirmationService(); var detail = service.GetAffirmationById(id); var model = new AffirmationEdit { AffirmationId = detail.AffirmationId, AffirmationText = detail.AffirmationText }; return(View(model)); }
public ActionResult DeletePost(int id) { var service = new AffirmationService(); service.DeleteAffirmation(id); TempData["SaveResult"] = "Affirmation was deleted..."; return(RedirectToAction("Index")); }
public ActionResult Create(AffirmationCreate model) { if (ModelState.IsValid) { var service = new AffirmationService(); service.CreateAffirmation(model); return(RedirectToAction("Index")); } else { return(View(model)); } }
public ActionResult Edit(int id, AffirmationEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.AffirmationId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = new AffirmationService(); if (service.UpdateAffirmation(model)) { TempData["SaveResult"] = "Your entry was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Sorry, your entry could not be updated."); return(View(model)); }
// GET: Entry public ActionResult Index() { EntryService entryService = CreateEntryService(); AffirmationService affirmationService = new AffirmationService(); var affirmationList = affirmationService.GetRandomAffirmation(); var entryList = entryService.GetEntries().OrderByDescending(order => order.EntryDate).ThenByDescending(order => order.CreatedUtc).ToList(); var verySad = 0; var modSad = 0; var balanced = 0; var modHappy = 0; var veryHappy = 0; foreach (var entry in entryList) { var mood = entry.MoodRating; switch (mood) { case RatingOfMood.Very_Sad: verySad++; break; case RatingOfMood.Moderately_Sad: modSad++; break; case RatingOfMood.Balanced: balanced++; break; case RatingOfMood.Moderately_Happy: modHappy++; break; case RatingOfMood.Very_Happy: veryHappy++; break; } } Dictionary <string, int> moodDictionary = new Dictionary <string, int>(); moodDictionary.Add("Very Happy", veryHappy); moodDictionary.Add("Moderately Happy", modHappy); moodDictionary.Add("Balanced", balanced); moodDictionary.Add("Moderately Sad", modSad); moodDictionary.Add("Very Sad", verySad); Dictionary <string, int> orderedMoodDictionary = new Dictionary <string, int>(); foreach (KeyValuePair <string, int> item in moodDictionary.OrderBy(key => key.Value)) { orderedMoodDictionary.Add(item.Key, item.Value); } var model = new EntryWithAffirmationListItem { EntryList = entryList, Affirmation = affirmationList, VerySadCount = verySad, ModSadCount = modSad, BalancedCount = balanced, ModHappyCount = modHappy, VeryHappyCount = veryHappy, OrderedMoodDictionary = orderedMoodDictionary }; return(View(model)); }