Exemple #1
0
        public ActionResult Edit(int id)
        {
            var service = CreatePhysicalService();
            var detail  = service.GetPhysicalById(id);
            var model   =
                new PhysicalEdit
            {
                PhysicalId   = detail.PhysicalId,
                CategoryType = detail.CategoryType,
                Title        = detail.Title,
                ResourceType = detail.ResourceType,
                Description  = detail.Description,
                City         = detail.City,
                State        = detail.State,
                InPerson     = detail.InPerson,
                Url          = detail.Url,
            };

            return(View(model));
        }
        public bool UpdatePhysical(PhysicalEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Physicals
                    .Single(e => e.PhysicalId == model.PhysicalId && e.OwnerId == _userId);
                entity.CategoryType = model.CategoryType;
                entity.Title        = model.Title;
                entity.ResourceType = model.ResourceType;
                entity.Description  = model.Description;
                entity.City         = model.City;
                entity.State        = model.State;
                entity.InPerson     = model.InPerson;
                entity.Url          = model.Url;
                entity.ModifiedUtc  = DateTimeOffset.UtcNow;

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

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

            var service = CreatePhysicalService();

            if (service.UpdatePhysical(model))
            {
                TempData["SaveResult"] = "Successfully updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Your entry could not be updated.");
            return(View(model));
        }