Example #1
0
        public ActionResult Edit(EntriesEditViewModel viewModel)
        {
            ValidateEntry(viewModel.Entry);

            if (ModelState.IsValid)
            {
                var entry  = viewModel.Entry;
                var userId = User.Identity.GetUserId();

                if (!_entriesRepository.EntryOwnedByUserId(entry.Id, userId))
                {
                    return(HttpNotFound());
                }

                entry.UserId = userId;

                _entriesRepository.Update(viewModel.Entry);

                TempData["Message"] = "Your entry was successfully updated!";

                return(RedirectToAction("Index"));
            }

            viewModel.Init(_activitiesRepository);

            return(View(viewModel));
        }
Example #2
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var userId = User.Identity.GetUserId();

            Entry entry = _entriesRepository.Get((int)id, userId);

            if (entry == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new EntriesEditViewModel()
            {
                Entry = entry
            };

            viewModel.Init(_activitiesRepository);

            return(View(viewModel));
        }
Example #3
0
        public ActionResult Edit(EntriesEditViewModel viewModel)
        {
            ValidateEntry(viewModel.Entry);

            if (ModelState.IsValid)
            {
                _entriesRepository.Update(viewModel.Entry);

                TempData["Message"] = "Your entry was successfully updated!";

                return(RedirectToAction("Index"));
            }

            viewModel.Init(_activitiesRepository);

            return(View(viewModel));
        }