Exemplo n.º 1
0
        public async Task <IActionResult> GetByPostalCode([FromRoute] string cp)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var localite = await _context.Localites.Include(x => x.Professionnels)
                           .Include(x => x.Particuliers)
                           .SingleOrDefaultAsync(l => l.CodePostal.Equals(cp));

            if (localite == null)
            {
                return(NotFound());
            }
            else
            {
                var loc = new Localite {
                    CodePostal     = cp,
                    Ville          = localite.Ville,
                    Particuliers   = localite.Particuliers,
                    Professionnels = localite.Professionnels
                };
                // TODO : include the elements of the particuliers and the professionels
                return(Ok(localite));
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PostLocalite([FromBody] LocaliteDTO localiteDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var localite = new Localite();

            localite.CodePostal = localiteDto.CodePostal;
            localite.Ville      = localiteDto.Ville;

            await _context.Localites.AddAsync(localite);

            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetLocalites",
                                   new { codePostal = localite.CodePostal },
                                   localite));
        }