Example #1
0
        public ActionResult Edit(int id)
        {
            var service = CreateEntryService();
            var detail  = service.GetEntryById(id);
            var model   = new EntryEdit {
                EntryId = detail.EntryId, EntryDate = detail.EntryDate, MoodRating = detail.MoodRating, EntryContent = detail.EntryContent
            };

            return(View(model));
        }
Example #2
0
        public bool UpdateEntry(EntryEdit model)
        {
            var existingEntry = _db.Entries.Single(data => data.EntryId == model.EntryId && data.OwnerId == _userId);

            existingEntry.EntryDate    = model.EntryDate;
            existingEntry.MoodRating   = model.MoodRating;
            existingEntry.EntryContent = model.EntryContent;
            existingEntry.ModifiedUtc  = DateTimeOffset.UtcNow;

            return(_db.SaveChanges() == 1);
        }
Example #3
0
        public bool UpdateEntry(EntryEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity = ctx.Entries.Single(e => e.EntryId == model.EntryId && e.OwnerId == _userId);

                entity.Title       = model.Title;
                entity.Content     = model.Content;
                entity.ModifiedUtc = DateTimeOffset.UtcNow;

                return(ctx.SaveChanges() == 1);
            }
        }
Example #4
0
        public ActionResult Edit(int id)
        {
            var service = CreateEntryService();
            var detail  = service.GetEntryById(id);
            var model   = new EntryEdit
            {
                EntryId = detail.EntryId,
                Title   = detail.Title,
                Content = detail.Content
            };

            return(View(model));
        }
Example #5
0
        public IHttpActionResult Put(EntryEdit entry)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateEntryService();

            if (!service.UpdateEntry(entry))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
Example #6
0
        // Update - Edit the Entry
        public ActionResult Edit(int id)
        {
            var service = CreateEntryService();
            var detail  = service.GetEntryById(id);
            var model   =
                new EntryEdit
            {
                EntryId      = detail.EntryId,
                EntryTitle   = detail.EntryTitle,
                EntryContent = detail.EntryContent,
                ForGoal      = detail.ForGoal,
                GoalId       = detail.GoalId,
                ModifiedUtc  = DateTime.UtcNow
            };

            return(View(model));
        }
Example #7
0
        // Put - Update
        public bool UpdateEntry(EntryEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Entries
                    .SingleOrDefault(e => e.EntryId == model.EntryId);

                entity.EntryTitle   = model.EntryTitle;
                entity.EntryContent = model.EntryContent;
                entity.ForGoal      = model.ForGoal;
                entity.GoalId       = model.GoalId;
                entity.ModifiedUtc  = DateTimeOffset.UtcNow;

                return(ctx.SaveChanges() == 1);
            }
        }
Example #8
0
        public ActionResult Edit(int id, EntryEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.EntryId != id)
            {
                ModelState.AddModelError("", "We're sorry, this doesn't match an ID in our system.");
                return(View(model));
            }

            var service = CreateEntryService();

            if (service.UpdateEntry(model))
            {
                TempData["SaveResult"] = "Your journal entry has been updated!";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Your note could not be updated, please give it another try.");
            return(View(model));
        }
Example #9
0
        public ActionResult Edit(int id, EntryEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.EntryId != id)
            {
                ModelState.AddModelError("", "Id Mismatch!");
                return(View(model));
            }

            var service = CreateEntryService();

            if (service.UpdateEntry(model))
            {
                TempData["SaveResult"] = "Your Entry was updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Your Entry failed to update.");
            return(View(model));
        }