Beispiel #1
0
        public ActionResult Delete(int id)
        {
            PetsRepository repo = new PetsRepository();
            Pet            item = repo.GetById(id);

            if (AuthenticationManager.LoggedUser.Id != 1 &&
                AuthenticationManager.LoggedUser.Id != item.UserId)
            {
                RedirectToAction("Login", "Home");
            }
            else
            {
                repo.Delete(item);
            }

            return(RedirectToAction("Index", "Pet"));
        }
Beispiel #2
0
        public ActionResult Edit(int?id)
        {
            Pet item = null;

            PetsRepository     repo   = new PetsRepository();
            VaccinesRepository v_repo = new VaccinesRepository();

            item = id == null ? new Pet() : repo.GetById(id.Value);

            EditVM model = new EditVM(item);

            List <Vaccine>      available = new List <Vaccine>();
            List <CheckBoxItem> selected  = new List <CheckBoxItem>();

            available = v_repo.GetAllItems();

            foreach (var v in available)
            {
                selected.Add(new CheckBoxItem()
                {
                    ID        = v.Id,
                    Display   = v.Name,
                    IsChecked = item.ContainsV(v)
                });
            }
            foreach (var v in selected)
            {
                model.Selected.Add(v);
            }

            if (AuthenticationManager.LoggedUser.Id != 1 &&
                AuthenticationManager.LoggedUser.Id != model.User_Id)
            {
                return(RedirectToAction("Login", "Home"));
            }
            return(View(model));
        }