Esempio n. 1
0
        public ActionResult Edit(int id)
        {
            using (var ctx = new ApplicationDbContext())
            {
                ViewBag.ShelterList = ctx.Shelters.Select
                                          (s => new SelectListItem()
                {
                    Text  = s.ShelterName,
                    Value = s.ShelterId.ToString()
                }
                                          ).ToList();
            }
            var service = new CatService();
            var detail  = service.GetCatById(id);
            var model   =
                new CatEdit
            {
                CatId     = detail.CatId,
                CatName   = detail.CatName,
                CatSex    = detail.CatSex,
                CatWeight = detail.CatWeight,
                CatAge    = detail.CatAge,
                CatPrice  = detail.CatPrice,
                CatImage  = detail.CatImage,
                ShelterId = detail.ShelterId
            };

            return(View(model));
        }
Esempio n. 2
0
        public ActionResult Edit(int id)
        {
            var service = CreateCatService();
            var detail  = service.GetCatById(id);
            var model   =
                new CatEdit
            {
                Name     = detail.Name,
                ClientId = detail.ClientId
            };

            return(View(model));
        }
Esempio n. 3
0
        public bool UpdateCat(CatEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Cats
                    .Single(e => e.CatId == model.CatId);

                entity.Name     = model.Name;
                entity.ClientId = model.ClientId;

                return(ctx.SaveChanges() == 1);
            }
        }
Esempio n. 4
0
        //edit cat
        /// <summary>
        /// Allows user to edit information of cat
        /// </summary>
        /// <param name="cat"></param>
        /// <returns></returns>
        public IHttpActionResult Put(int id, [FromBody] CatEdit cat)
        {
            GetById(id);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateCatServices();

            if (!service.UpdateCat(cat))
            {
                return(InternalServerError());
            }

            return(Ok("Cat has been updated! (◕‿◕✿)"));
        }
Esempio n. 5
0
        public bool UpdateCat(CatEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Cats
                    .Single(e => e.CatId == model.CatId);
                entity.CatName   = model.CatName;
                entity.CatSex    = model.CatSex;
                entity.CatWeight = model.CatWeight;
                entity.CatAge    = model.CatAge;
                entity.CatPrice  = model.CatPrice;
                entity.ShelterId = model.ShelterId;
                entity.CatImage  = model.CatImage;


                return(ctx.SaveChanges() == 1);
            }
        }
Esempio n. 6
0
        //update cat
        public bool UpdateCat(CatEdit model)
        {
            //add ownerId guid here? (shelter should be the only one able to delete/ update cats
            Cat oldCat = GetCatById(model.CatId);

            if (oldCat != null)
            {
                oldCat.IsDeclawed = model.IsDeclawed;
                oldCat.IsFat      = model.IsFat;
                oldCat.Name       = model.Name;
                oldCat.Breed      = model.Breed;
                oldCat.Age        = model.Age;
                oldCat.AboutMe    = model.AboutMe;

                return(_context.SaveChanges() == 1);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 7
0
        public ActionResult Edit(int id, CatEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

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

            var service = CreateCatService();

            if (service.UpdateCat(model))
            {
                TempData["SaveResult"] = "Cat updated";
                return(RedirectToAction("Index"));
            }

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