// GET: JournalEntry
        public ActionResult New(int?id)
        {
            EntryFormModel model = new EntryFormModel();

            model.journal = _context.Journals.SingleOrDefault(j => j.Id == id);
            return(View("EntryForm", model));
        }
        public ActionResult Update(EntryFormModel model)
        {
            var oldVersion = _context.JournalEntries.Single(e => e.Id == model.entry.Id);

            if (oldVersion == null)
            {
                return(HttpNotFound());
            }
            oldVersion.Flag = JournalEntry.EntryFlag.E;
            var newVersion = new JournalEntry()
            {
                CreatedOn         = DateTime.Now,
                EntryBody         = model.entry.EntryBody,
                Flag              = JournalEntry.EntryFlag.N,
                EntryEditedReason = model.entry.EntryEditedReason,
                EntryEditedId     = model.entry.Id,
                JournalId         = model.journal.Id,
                Title             = model.entry.Title,
                Version           = (model.entry.Version + 1)
            };

            _context.JournalEntries.Add(newVersion);
            _context.SaveChanges();

            return(RedirectToAction("Details", "Journal", new { id = model.journal.Id }));
        }
Beispiel #3
0
        public void EntryFormModel_DataAnnotationTest(EntryFormModel model, bool isValid)
        {
            var validationResultsList = new List <ValidationResult>();
            var validationContext     = new ValidationContext(model, null, null);
            var validaitonResult      = Validator.TryValidateObject(model, validationContext, validationResultsList, true);

            Assert.AreEqual(isValid, validaitonResult);
            Assert.AreEqual(isValid, !validationResultsList.Any());
        }
        public ActionResult Create(EntryFormModel model)
        {
            model.entry.JournalId         = model.journal.Id;
            model.entry.CreatedOn         = DateTime.Now;
            model.entry.Version           = 1;
            model.entry.EntryEditedId     = 0;
            model.entry.EntryEditedReason = null;
            model.entry.Flag = JournalEntry.EntryFlag.N;

            _context.JournalEntries.Add(model.entry);
            _context.SaveChanges();

            return(RedirectToAction("Details", "Journal", new { Id = model.journal.Id }));
        }
Beispiel #5
0
        public ActionResult Create(EntryFormModel entry)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index"));
            }
            var entryDataModel = _mapper.Map(entry);

            if (entryDataModel.Airport == null)
            {
                return(RedirectToAction("Index"));
            }
            _entryDataModelRepository.Add(entryDataModel);
            return(RedirectToAction("Detail", new { entry = entryDataModel }));
        }
        public ActionResult UpdateEntry(int id)
        {
            JournalEntry entry = _context.JournalEntries.SingleOrDefault(j => j.Id == id);

            if (entry == null)
            {
                return(HttpNotFound());
            }
            //  Get the Entry and pass it to the view
            //  render it in the view
            //  allow changes to be made
            //  pass both back to Update

            var model = new EntryFormModel()
            {
                entry   = entry,
                journal = _context.Journals.SingleOrDefault(j => j.Id == entry.JournalId)
            };

            return(View("EntryForm", model));
        }