Exemple #1
0
        public void Test()
        {
            var child = new Child
            {
                Id     = 1,
                Name   = "John",
                Mother = new Parent {
                    Id = 3
                },
                Father = new Parent {
                    Id = 9
                },
                Brother = new Child {
                    Id = 5
                },
                Sister = new Child {
                    Id = 7
                }
            };
            var childEdit = new ChildEdit();

            childEdit.InjectFrom(child)
            .InjectFrom <EntityToInt>(child);

            Assert.Equal(1, childEdit.Id);
            Assert.Equal("John", childEdit.Name);
            Assert.Equal(3, childEdit.MotherId);
            Assert.Equal(9, childEdit.FatherId);
            Assert.Equal(5, childEdit.BrotherId);
            Assert.Equal(7, childEdit.SisterId);
            Assert.Equal(0, childEdit.Sister2Id);

            var c = new Child();

            c.InjectFrom(childEdit)
            .InjectFrom <IntToEntity>(childEdit);

            Assert.Equal(1, c.Id);
            Assert.Equal("John", c.Name);
            Assert.Equal(3, c.Mother.Id);
            Assert.Equal(9, c.Father.Id);
            Assert.Equal(5, c.Brother.Id);
            Assert.Equal(7, c.Sister.Id);
            Assert.Null(c.Sister2);
        }
Exemple #2
0
        public ActionResult Edit(int id)
        {
            var service = CreateChildService();
            var detail  = service.GetChildById(id);
            var model   =
                new ChildEdit
            {
                ChildId           = detail.ChildId,
                ChildName         = detail.ChildName,
                BedsNeed          = detail.BedsNeed,
                ChildGender       = detail.ChildGender,
                ChildAge          = detail.ChildAge,
                SchoolDistNeed    = detail.SchoolDistNeed,
                Comments          = detail.Comments,
                CaseworkerName    = detail.CaseworkerName,
                CaseworkerContact = detail.CaseworkerContact,
                PhotoUrl          = detail.PhotoUrl,
            };

            return(View(model));
        }
Exemple #3
0
        public ActionResult Edit(int id, ChildEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

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

            var service = CreateChildService();

            if (service.UpdateChild(model))
            {
                TempData["SaveResult"] = "The child's info has been updated.";
                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("", "The child's info could not be updated.");
            return(View(model));
        }
Exemple #4
0
        public bool UpdateChild(ChildEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Children
                    .Single(e => e.ChildId == model.ChildId);

                entity.ChildId           = model.ChildId;
                entity.ChildName         = model.ChildName;
                entity.BedsNeed          = model.BedsNeed;
                entity.ChildGender       = model.ChildGender;
                entity.ChildAge          = model.ChildAge;
                entity.SchoolDistNeed    = model.SchoolDistNeed;
                entity.CaseworkerName    = model.CaseworkerName;
                entity.CaseworkerContact = model.CaseworkerContact;
                entity.Comments          = model.Comments;
                entity.PhotoUrl          = model.PhotoUrl;
                entity.ModifiedUtc       = model.ModifiedUtc;

                return(ctx.SaveChanges() == 1);
            }
        }