Ejemplo n.º 1
0
        public IHttpActionResult Post(MowerCreate mower)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateMowerService();

            if (!service.CreateMower(mower))
            {
                return(InternalServerError());
            }
            return(Ok());
        }
Ejemplo n.º 2
0
        public bool CreateMower(MowerCreate model)
        {
            var entity =
                new Mower()
            {
                LandscapeId  = _userId,
                MowerName    = model.MowerName,
                MowerCity    = model.MowerCity,
                MowerRate    = model.MowerRate,
                MowerService = model.MowerService
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Mowers.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Ejemplo n.º 3
0
        public ActionResult Create(MowerCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateMowerService();

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

            ModelState.AddModelError("", "Mower could not be created.");
            return(View(model));
        }