public ActionResult AddEditKeeper(int?id, keeper model)
        {
            OwnerKeeperVM keeperVm = new OwnerKeeperVM();

            keeperVm.farms = new SelectList(_repo.Farm.GetModel().ToList(), "id", "orgtanizationName");
            if (id.HasValue)
            {
                keeper ownerkeeper = _repo.keepers.GetById(id.Value);

                if (ownerkeeper != null)
                {
                    //Mapping the model to viewModel
                    var config = new MapperConfiguration(cfg =>
                    {
                        cfg.CreateMap <keeper, OwnerKeeperVM>();
                    });

                    IMapper mapper = config.CreateMapper();

                    keeperVm       = mapper.Map <keeper, OwnerKeeperVM>(ownerkeeper);
                    keeperVm.farms = new SelectList(_repo.Farm.GetModel().ToList(), "id", "orgtanizationName", ownerkeeper.farmid);


                    keeperVm.id = ownerkeeper.id;
                }
            }
            return(View(keeperVm));
        }
        public IActionResult DeleteOwnerKeeper(int id)
        {
            keeper feed = _repo.keepers.GetById(id);

            _repo.keepers.Delete(id);

            return(RedirectToAction("Index"));
        }
        public IActionResult Postkeeper([FromBody] keeper keeper)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.keepers.Insert(keeper);

            return(CreatedAtAction("Getkeeper", new { id = keeper.id }, keeper));
        }
Example #4
0
 void Awake()
 {
     //Debug.Log ("random scene: " + activeFirst);
     if (Instance == null)
     {
         DontDestroyOnLoad(gameObject);
         Instance = this;
     }
     else if (Instance != this)
     {
         Destroy(gameObject);
     }
 }
        public ActionResult AddEditKeeper(int?id, OwnerKeeperVM model)

        {
            try
            {
                if (ModelState.IsValid)
                {
                    bool isNew = !id.HasValue;

                    // OwnerKeeper owner = isNew ? new OwnerKeeper { } : _repo.GetById(id.Value);
                    // feed = model;
                    if (isNew)
                    {
                        //Mapping the model to viewModel
                        var config = new MapperConfiguration(cfg =>
                        {
                            cfg.CreateMap <OwnerKeeperVM, keeper>();
                        });

                        IMapper mapper = config.CreateMapper();

                        keeper owner = mapper.Map <OwnerKeeperVM, keeper>(model);


                        _repo.keepers.Insert(owner);
                        _repo.Save();
                    }
                    else
                    {
                        var config = new MapperConfiguration(cfg =>
                        {
                            cfg.CreateMap <OwnerKeeperVM, keeper>();
                        });

                        IMapper mapper = config.CreateMapper();

                        keeper owner = mapper.Map <OwnerKeeperVM, keeper>(model);


                        //To Avoid tracking error
                        // DbContextInMemory.Entry(entity).State = EntityState.Detached;
                        _repo.keepers.Update(owner);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(RedirectToAction("Index"));
        }
        public void Insert(AnimalRegistration animal)
        {
            db.animalRegistration.Add(animal);

            db.SaveChanges();
            keeper keeper = db.keeper.FirstOrDefault(m => m.id == animal.keeperId);

            animal.keeper = keeper;
            animal        = db.animalRegistration.LastOrDefault();
            if (db.OwnerKeeper.Any(m => m.id == animal.ownerId))
            {
                AnimalOwner animalowner = new AnimalOwner();
                animalowner.Owner              = db.OwnerKeeper.Find(Convert.ToInt32(animal.ownerId));
                animalowner.OwnerId            = Convert.ToInt32(animal.ownerId);
                animalowner.AnimalId           = animal.id;
                animalowner.AnimalRegistration = animal;

                db.AnimalOwners.Add(animalowner);
                db.SaveChanges();
            }
        }
        public IActionResult Putkeeper([FromRoute] int id, [FromBody] keeper keeper)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != keeper.id)
            {
                return(BadRequest());
            }

            keeper.id = id;
            _context.keepers.Update(keeper);



            if (!keeperExists(id))
            {
                return(NotFound());
            }

            return(NoContent());
        }
        public IActionResult Details(int id)
        {
            keeper owner = _repo.keepers.GetById(id);

            return(View(owner));
        }