Example #1
0
        public ActionResult Create(ChildCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateChildService();

            if (service.CreateChild(model))
            {
                TempData["SaveResult"] = "Child's info was saved.";
                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("", "Child's info could not be saved.");

            return(View(model));
        }
Example #2
0
        public bool CreateChild(ChildCreate model)
        {
            var entity = new Child()
            {
                UserId            = _userId,
                ChildName         = model.ChildName,
                BedsNeed          = model.BedsNeed,
                ChildGender       = model.ChildGender,
                ChildAge          = model.ChildAge,
                SchoolDistNeed    = model.SchoolDistNeed,
                CaseworkerName    = model.CaseworkerName,
                CaseworkerContact = model.CaseworkerContact,
                Comments          = model.Comments,
                PhotoUrl          = model.PhotoUrl,
                ModifiedUtc       = model.ModifiedUtc,
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Children.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }