Example #1
0
        public ActionResult Create(string courseTermShortName, string siteShortName, FormCollection input)
        {
            Tag newTag = new Tag();
            UpdateModel(newTag);
            if (ModelState.IsValid)
            {
                    try
                    {
                        newTag.CreatedBy = dataRepository.GetLoggedInProfile().MembershipID;
                        courseTerm.Tags.Add(newTag);
                        newTag.Name = newTag.Name.Trim();
                        if (newTag.IsCourseOutcome)
                        {
                            foreach (var outcome in site.ProgramOutcomes)
                            {

                                string checkedState = input[outcome.ProgramOutcomeID.ToString()];
                                if (checkedState != "false")
                                {
                                    TagProgramOutcome tpo = new TagProgramOutcome()
                                    {
                                        Tag = newTag,
                                        ProgramOutcomeID = outcome.ProgramOutcomeID
                                    };
                                }
                            }
                        }
                        dataRepository.Save();
                        return RedirectToAction("Index", new { siteShortName = siteShortName, courseTermShortName = courseTermShortName });
                    }
                    catch (RuleViolationException)
                    {
                        ModelState.AddModelErrors(newTag.GetRuleViolations());
                    }
                    catch (Exception ex)
                    {
                        ModelState.AddModelError("_FORM", ex);
                    }
            }
            TagEditViewModel model = new TagEditViewModel(newTag, site.ProgramOutcomes.ToList());
            return View(model);
        }
Example #2
0
        public ActionResult Edit(string courseTermShortName, string siteShortName, Guid id, FormCollection collection)
        {
            Tag tag = dataRepository.GetTagByID(courseTerm, id);
            if (tag == null)
                return View("TagNotFound");

            UpdateModel(tag);
            tag.Name = tag.Name.Trim();
            if (ModelState.IsValid)
            {
                try
                {
                    if (tag.IsCourseOutcome)
                    {
                        foreach (var outcome in site.ProgramOutcomes)
                        {
                            string checkedState = collection[outcome.ProgramOutcomeID.ToString()];
                            TagProgramOutcomeRelationship rel = new TagProgramOutcomeRelationship(tag, outcome);
                            if (checkedState != "false")
                            {
                                if (!rel.AreRelated)
                                {
                                    TagProgramOutcome tpo = new TagProgramOutcome()
                                        {
                                            Tag = tag,
                                            ProgramOutcome = outcome
                                        };
                                }
                            }
                            else
                            {
                                if (rel.AreRelated)
                                {
                                    TagProgramOutcome tpo = dataRepository.Single<TagProgramOutcome>(t => t.ProgramOutcome == outcome && t.Tag == tag);
                                    dataRepository.Remove<TagProgramOutcome>(tpo);
                                }
                            }
                        }
                    }
                    dataRepository.Save();
                    return RedirectToAction("Index", new { siteShortName = siteShortName, courseTermShortName = courseTermShortName });
                }
                catch (RuleViolationException)
                {
                    ModelState.AddModelErrors(tag.GetRuleViolations());
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("_FORM", ex);
                }
            }
            TagEditViewModel model = new TagEditViewModel(tag, site.ProgramOutcomes.ToList());
            return View(model);
        }
Example #3
0
 public ActionResult Create(string courseTermShortName, string siteShortName)
 {
     Tag newTag = new Tag();
     TagEditViewModel model = new TagEditViewModel(newTag, site.ProgramOutcomes.ToList());
     return View(model);
 }
Example #4
0
 public ActionResult Edit(string courseTermShortName, string siteShortName, Guid id)
 {
     Tag tag = dataRepository.GetTagByID(courseTerm, id);
     if (tag == null)
         return View("TagNotFound");
     TagEditViewModel model = new TagEditViewModel(tag, site.ProgramOutcomes.ToList());
     return View(model);
 }