public ActionResult Edit(int id)
        {
            var service = CreateAttachmentService();
            var detail  = service.GetAttachmentById(id);
            var model   =
                new AttachmentEdit
            {
                AttachmentId = detail.AttachmentId,
                Name         = detail.Name,
                Description  = detail.Description,
                IsPrimary    = detail.IsPrimary,
            };

            return(View(model));
        }
Exemplo n.º 2
0
        public bool UpdateAttachment(AttachmentEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Attachments
                    .Single(e => e.AttachmentId == model.AttachmentId && e.OwnerId == _userId);

                entity.Name        = model.Name;
                entity.Description = model.Description;
                entity.IsPrimary   = model.IsPrimary;
                entity.ModifiedUtc = DateTimeOffset.UtcNow;

                return(ctx.SaveChanges() == 1);
            }
        }
        public ActionResult Edit(int id, AttachmentEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

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

            var service = CreateAttachmentService();

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

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