コード例 #1
0
        public ActionResult <Tuin> PostTuin(TuinDTO tuin)
        {
            Tuin tuinOmToeTeVoegen = new Tuin()
            {
                Naam      = tuin.Naam,
                dateAdded = DateTime.Now
            };

            foreach (var i in tuin.Planten)
            {
                if (i.DatumGeplant.Equals("Invalid Date"))
                {
                    ;
                }
                {
                    i.DatumGeplant = DateTime.Now.ToLongDateString();
                }
                Plant plant = new Plant(i.Naam, Convert.ToDateTime(i.DatumGeplant), i.DagenTotOogst);
                tuinOmToeTeVoegen.AddPlant(plant);
            }

            _tuinRepository.Add(tuinOmToeTeVoegen);
            _tuinRepository.SaveChanges();

            return(CreatedAtAction(nameof(GetTuin), new { id = tuinOmToeTeVoegen.Id }, tuinOmToeTeVoegen));
        }
コード例 #2
0
        public ActionResult <Tuin> GetTuin(int id)
        {
            Tuin tuin = _tuinRepository.GetBy(id);

            if (tuin == null)
            {
                return(NotFound());
            }
            return(tuin);
        }
コード例 #3
0
        public IActionResult DeleteTuin(int id)
        {
            Tuin tuin = _tuinRepository.GetBy(id);

            if (tuin == null)
            {
                return(NotFound());
            }

            _tuinRepository.Delete(tuin);
            _tuinRepository.SaveChanges();

            return(NoContent());
        }
コード例 #4
0
        public IActionResult PutTuin(int id, Tuin tuin)
        {
            if (id != tuin.Id)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid) //throws 404?
            {
                return(BadRequest());
            }

            _tuinRepository.Update(tuin);
            _tuinRepository.SaveChanges();
            return(NoContent());
        }
コード例 #5
0
        static void Main(string[] args)
        {
            /*
             * Persoon pol = new Persoon();
             * pol.voornaam = "Pol";
             * pol.familienaam = "Polsen";
             * pol.gebortedatum = DateTime.Now;
             *
             * pol.Schreeuw();
             * Console.WriteLine();
             *
             * Persoon linde = new Persoon();
             * linde.voornaam = "Linde";
             * linde.familienaam = "Boon";
             * linde.gebortedatum = DateTime.Now;
             *
             * linde.Schreeuw();
             * Console.WriteLine();
             */

            /*
             * exercise:
             * Tuin garden = new Tuin();
             * garden.locality = "Brugge";
             * garden.squareMeters = 15f;
             * garden.registerNumber = 5190;
             *
             * garden.Descript();
             */

            //Persoon pol = new Persoon("Pol", "Polsen", DateTime.Now);
            //pol.Schreeuw();

            Tuin garden = new Tuin("Brugge", 1234, 5.7f);

            garden.Descript();

            Console.WriteLine();

            Tuin garden1 = new Tuin("Knokke", 5555, 6.7f, DateTime.Now);

            garden1.Descript();
        }
コード例 #6
0
 public void Delete(Tuin tuin)
 {
     _tuinen.Remove(tuin);
 }
コード例 #7
0
 public void Update(Tuin tuin)
 {
     _context.Update(tuin);
 }
コード例 #8
0
 public void Add(Tuin tuin)
 {
     _tuinen.Add(tuin);
 }
コード例 #9
0
 public bool TryGetTuin(int id, out Tuin tuin)
 {
     tuin = _context.Tuinen.Include(t => t.Planten).FirstOrDefault(t => t.Id == id);
     return(tuin != null);
 }
コード例 #10
0
 // PUT api/tuin/5
 public void Put(int id, [FromBody] Tuin value)
 {
     repo.EditTuin(id, value);
 }
コード例 #11
0
 // POST api/tuin
 public void Post([FromBody] Tuin value)
 {
     repo.SaveTuin(value);
 }