Ejemplo n.º 1
0
        public ActionResult Create(ChoreCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateChoreService();

            if (service.CreateChore(model))
            {
                TempData["SaveResult"] = "Chore was created.";
                return(RedirectToAction("Index"));
            }
            ;

            ModelState.AddModelError("", "Chore could not be created.");

            return(View(model));
        }
Ejemplo n.º 2
0
        // CREATE
        public bool CreateChore(ChoreCreate model)
        {
            var entity =
                new Chore()
            {
                UserId           = _userId.ToString(),
                ChoreName        = model.ChoreName,
                ChoreDescription = model.ChoreDescription,
                Location         = model.Location,
                Animal           = model.Animal,
                TimeOfDay        = model.TimeOfDay,
                IsDaily          = model.IsDaily,
                //IsPublished = model.IsPublished,
                CreatedUtc  = DateTimeOffset.Now,
                ModifiedUtc = DateTimeOffset.Now
            };

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