コード例 #1
0
ファイル: MowerController.cs プロジェクト: will81656/Clipz
        public ActionResult Edit(int id, MowerEdit model)
        {
            if (!ModelState.IsValid)
            {
                //Populate();

                return(View(model));
            }

            if (model.MowerId != id)
            {
                //Populate();
                ModelState.AddModelError("", "Mower Profile does not exist");
                return(View(model));
            }

            var service = CreateMowerService();

            if (service.UpdateMower(model))
            {
                TempData["SaveResult"] = "Your Mower Profile was updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Your Mower Profile could not be updated.");
            return(View());
        }
コード例 #2
0
        public IHttpActionResult Put(MowerEdit mower)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateMowerService();

            if (!service.UpdateMower(mower))
            {
                return(InternalServerError());
            }
            return(Ok());
        }
コード例 #3
0
        public ActionResult Edit(int id)
        {
            var service = CreateMowerService();
            var detail  = service.GetMowerById(id);
            var model   =
                new MowerEdit
            {
                MowerId      = detail.MowerId,
                MowerName    = detail.MowerName,
                MowerCity    = detail.MowerCity,
                MowerService = detail.MowerService,
                MowerRate    = detail.MowerRate
            };

            return(View(model));
        }
コード例 #4
0
ファイル: MowerController.cs プロジェクト: will81656/Clipz
        // Read: Mower/Edit/{id}
        public ActionResult Edit(int id)
        {
            var service = CreateMowerService();
            var detail  = service.GetMowerById(id);
            var model   =
                new MowerEdit
            {
                MowerId    = detail.MowerId,
                FirstName  = detail.FirstName,
                LastName   = detail.LastName,
                LocationId = detail.LocationId,
            };

            //Populate();
            return(View(model));
        }
コード例 #5
0
        public bool UpdateMower(MowerEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Mowers
                    .Single(e => e.MowerId == model.MowerId && e.LandscapeId == _userId);
                entity.MowerId      = model.MowerId;
                entity.MowerName    = model.MowerName;
                entity.MowerCity    = model.MowerCity;
                entity.MowerService = model.MowerService;
                entity.MowerRate    = model.MowerRate;

                return(ctx.SaveChanges() == 1);
            }
        }
コード例 #6
0
        public ActionResult Edit(int id, MowerEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.MowerId != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }
            var service = CreateMowerService();

            if (service.UpdateMower(model))
            {
                TempData["SaveResult"] = "Your mower was updated.";
                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("", "Your mower could not be updated.");
            return(View(model));
        }