public ActionResult Edit(int id)
        {
            var model = new NoteFormModel();
            var note = NoteRepository.NoteFetch(id);

            model.Title = "Note Edit";
            model.Note = note;

            return this.View(model);
        }
        public ActionResult Create(int sourceId, int sourceTypeId)
        {
            var model = new NoteFormModel();
            var note = NoteRepository.NoteNew(sourceId, (SourceType)sourceTypeId);

            model.Title = "Note Create";
            model.Note = note;

            return this.View(model);
        }
        public ActionResult Create(int sourceType, int sourceId, NoteFormModel model)
        {
            var note = NoteService.NoteNew((SourceType)sourceType, sourceId);

            Csla.Data.DataMapper.Map(model, note, true);

            note = NoteService.NoteSave(note);

            if (note.IsValid)
            {
                return new JsonResult { Data = this.Url.Action("Edit", new { id = note.NoteId, message = Resources.SaveSuccessfulMessage }) };
            }

            this.Map(note, model, false);

            return this.View(model);
        }
        public ActionResult Create(int sourceType, int sourceId)
        {
            var model = new NoteFormModel();

            try
            {
                var note = NoteService.NoteNew((SourceType)sourceType, sourceId);

                this.Map(note, model, true);
            }
            catch (Exception ex)
            {
                this.ModelState.AddModelError(string.Empty, ex.Message);
            }

            return this.View(model);
        }
        public ActionResult Create(int sourceId, int sourceTypeId, FormCollection collection)
        {
            var model = new NoteFormModel();
            var note = NoteRepository.NoteNew(sourceId, (SourceType)sourceTypeId);

            this.Map(collection, note);

            note = NoteRepository.NoteSave(note);

            if (note.IsValid)
            {
                return this.RedirectToAction("Details", note.SourceTypeName, new { id = note.SourceId });
            }

            model.Title = "Note Create";
            model.Note = note;

            ModelHelper.MapBrokenRules(this.ModelState, note);

            return this.View(model);
        }
        public ActionResult Add(int sourceType, int sourceId, NoteFormModel model)
        {
            var note = NoteService.NoteNew((SourceType)sourceType, sourceId);

            Csla.Data.DataMapper.Map(model, note, true);

            note = NoteService.NoteSave(note);

            if (note.IsValid)
            {
                note = NoteService.NoteFetch(note.NoteId);

                this.Map(note, model, true);

                model.IsNew = true;

                return PartialView("NoteUserControl", model);
            }

            this.Map(note, model, false);

            return this.View(model);
        }
        public ActionResult Edit(int id, string message)
        {
            var model = new NoteFormModel();

            try
            {
                var note = NoteService.NoteFetch(id);

                model.Message = message;

                this.Map(note, model, true);
            }
            catch (Exception ex)
            {
                this.ModelState.AddModelError(string.Empty, ex.Message);
            }

            return this.View(model);
        }
        public NoteFormModel Map(Note note, NoteFormModel model, bool ignoreBrokenRules)
        {
            Csla.Data.DataMapper.Map(note, model, true);

            model.Tab = "Task";
            model.IsNew = note.IsNew;
            model.IsValid = note.IsValid;

            if (!ignoreBrokenRules)
            {
                foreach (var brokenRule in note.BrokenRulesCollection)
                {
                    this.ModelState.AddModelError(string.Empty, brokenRule.Description);
                }
            }

            return model;
        }
        public ActionResult Edit(int id, NoteFormModel model)
        {
            var note = NoteService.NoteFetch(id);

            Csla.Data.DataMapper.Map(model, note, true);

            note = NoteService.NoteSave(note);

            if (note.IsValid)
            {
                model.Message = Resources.SaveSuccessfulMessage;
            }

            this.Map(note, model, true);

            return this.View(model);
        }