Esempio n. 1
0
        public bool UpdatePark(ParkEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity = ctx.Parks.Single(e => e.ParkId == model.ParkId && e.OwnerId == _ownerId);

                entity.ParkName = model.ParkName;
                entity.CityName = model.CityName;

                return(ctx.SaveChanges() == 1);
            }
        }
Esempio n. 2
0
        public string UpdatePark(ParkEdit model, int id)
        {
            using (var ctx = new ApplicationDbContext())
            {
                try
                {
                    var entity = ctx.Parks.Single(e => e.ID == id);

                    if (model.Name != null)
                    {
                        entity.Name = model.Name;
                    }
                    if (model.CityID != 0)
                    {
                        entity.CityID = model.CityID;
                    }
                    if (model.Acreage != 0)
                    {
                        entity.Acreage = model.Acreage;
                    }
                    if (model.Hours != null)
                    {
                        entity.Hours = model.Hours;
                    }
                    if (model.PhoneNumber != null)
                    {
                        entity.PhoneNumber = model.PhoneNumber;
                    }
                    if (model.Website != null)
                    {
                        entity.Website = model.Website;
                    }

                    try
                    {
                        ctx.SaveChanges();
                        return("Okay");
                    }
                    catch
                    {
                        if (entity.City == null)
                        {
                            return("Invalid City ID");
                        }
                    }
                }
                catch { }
                return("Update Error");
            }
        }
Esempio n. 3
0
        public IHttpActionResult Put(ParkEdit park)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var service = CreateParkService();

            if (!service.UpdatePark(park))
            {
                return(InternalServerError());
            }
            return(Ok());
        }
Esempio n. 4
0
        //Edit
        public ActionResult Edit(int id)
        {
            var service = CreateParkService();
            var detail  = service.GetParkById(id);
            var model   =
                new ParkEdit
            {
                ParkId   = detail.ParkId,
                ParkName = detail.ParkName,
                CityName = detail.CityName
            };

            return(View(model));
        }
Esempio n. 5
0
        public bool UpdatePark(ParkEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Parks
                    .Single(e => e.ParkID == model.ParkID && e.OwnerID == _userID);

                entity.ParkName    = model.ParkName;
                entity.City        = model.City;
                entity.State       = model.State;
                entity.ModifiedUtc = DateTimeOffset.UtcNow;

                return(ctx.SaveChanges() == 1);
            }
        }
Esempio n. 6
0
        //GET: Park/Edit/{id}
        public ActionResult Edit(int id)
        {
            var service = CreateParkService();
            var detail  = service.GetParkById(id);
            var model   =
                new ParkEdit
            {
                ParkId          = detail.ParkId,
                Name            = detail.Name,
                Address         = detail.Address,
                YearEstablished = detail.YearEstablished,
                ParkSize        = detail.ParkSize,
                Description     = detail.Description
            };

            return(View(model));
        }
Esempio n. 7
0
        //EDIT
        public bool EditPark(ParkEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Parks
                    .Single(p => p.ParkId == model.ParkId && p.IsDeleted == false);

                entity.Name            = model.Name;
                entity.Address         = model.Address;
                entity.YearEstablished = model.YearEstablished;
                entity.ParkSize        = model.ParkSize;
                entity.Description     = model.Description;

                return(ctx.SaveChanges() == 1);
            }
        }
Esempio n. 8
0
        /// <summary> Update Park </summary>
        /// <param name="id"> park id </param>
        /// <param name="park"></param>
        /// <returns> Updates Park Object </returns>
        public IHttpActionResult Put(ParkEdit park, int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var parkService = CreateParkService();

            result = parkService.UpdatePark(park, id);
            if (result == "Invalid City ID")
            {
                return(BadRequest("Invalid City ID."));
            }
            if (result == "Update Error")
            {
                return(BadRequest("Invalid Park ID."));
            }
            return(Ok());
        }
Esempio n. 9
0
        public bool UpdatePark(ParkEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Parks
                    .Single(e => e.ParkID == model.ParkID && e.OwnerID == _userID);

                entity.ParkName        = model.ParkName;
                entity.ParkCost        = model.ParkCost;
                entity.ParkAddress     = model.ParkAddress;
                entity.ParkCity        = model.ParkCity;
                entity.ParkState       = model.ParkState;
                entity.ParkZip         = model.ParkZip;
                entity.ParkPhone       = model.ParkPhone;
                entity.ParkWebsite     = model.ParkWebsite;
                entity.ParkDescription = model.ParkDescription;

                return(ctx.SaveChanges() == 1);
            }
        }
Esempio n. 10
0
        public ActionResult Edit(int id, ParkEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.ParkID != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }

            var service = CreateParkService();

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

            ModelState.AddModelError("", "Your Park could not be updated.");
            return(View(model));
        }