예제 #1
0
        public ActionResult Create(MotherCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateMotherService();

            if (service.CreateMother(model))
            {
                TempData["SaveResult"] = "You added a new mother.";
                return(RedirectToAction("Index"));
            }
            ;

            ModelState.AddModelError("", "New mother could not be added.");

            return(View(model));
        }
예제 #2
0
        public bool CreateMother(MotherCreate model)
        {
            var entity =
                new Mother()
            {
                OwnerId        = _userId,
                FirstName      = model.FirstName,
                LastName       = model.LastName,
                MotherLocation = model.MotherLocation,
                DateOfBirth    = model.DateOfBirth,
                DueDate        = model.DueDate,
                FirstPregnancy = model.FirstPregnancy,
                VagBirAftCes   = model.VagBirAftCes,
                BreastFeeding  = model.BreastFeeding
            };

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