Ejemplo n.º 1
0
        //[Route("Ping/Location")]
        //public ViewResult PingLocationDetail(string location)
        //{
        //    using (var ctx = new ApplicationDbContext())
        //    {
        //        var svc = CreatePingService();
        //        var model = svc.GetPingByPingLocation(location);

        //        var locations = from l in ctx.Ping select l;
        //        if (!string.IsNullOrWhiteSpace(location))
        //        {
        //            locations = locations.Where(l => l.PingLocation.Contains(location));
        //        }
        //        return View("PingLocationDetail");
        //    }

        //}

        public ActionResult Edit(int id)
        {
            var service = CreatePingService();
            var detail  = service.GetPingById(id);

            var userId   = Guid.Parse(User.Identity.GetUserId());
            var sservice = new SharkTagService(userId);

            List <SharkTag> SharkTags = sservice.GetSharkTagsList().ToList();

            ViewBag.SharkTagId = SharkTags.Select(s => new SelectListItem()
            {
                Value    = s.SharkTagId.ToString(),
                Text     = s.TagId.ToString(),
                Selected = detail.SharkTagId == s.SharkTagId
            });

            var model = new PingEdit
            {
                PingId       = detail.PingId,
                PingDate     = detail.PingDate,
                PingLocation = detail.PingLocation,
                SharkTagId   = detail.SharkTagId,
            };

            return(View(model));
        }
Ejemplo n.º 2
0
        public bool UpdatePing(PingEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity = ctx.Ping.Single(e => e.PingId == model.PingId && e.OwnerId == _userId);
                entity.PingDate     = model.PingDate;
                entity.PingLocation = model.PingLocation;
                entity.SharkTagId   = model.SharkTagId;

                return(ctx.SaveChanges() == 1);
            }
        }
Ejemplo n.º 3
0
        public ActionResult Edit(int id, PingEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            if (model.PingId != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }
            var service = CreatePingService();

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

            ModelState.AddModelError("", "Your Ping would not be updated.");

            return(View(model));
        }