示例#1
0
        public IActionResult Post([FromBody] MunicipalityCreateDto body)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest());
            }

            var municipalitiesWithName = this.service.ReadAll().Where(m => m.MunicipalityName == body.MunicipalityName);

            if (municipalitiesWithName.Count() != 0)
            {
                return(this.BadRequest("Municipality with the same name exists"));
            }

            var id = this.service.Create(body);

            return(this.Created($"api/Municipalities/{id}", id));
        }
示例#2
0
        public IActionResult Update(Guid municipalityId, [FromBody] MunicipalityCreateDto body)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest());
            }

            int retVal = this.service.Update(municipalityId, body);

            if (retVal == 0)
            {
                return(this.BadRequest($"No entities found to update"));
            }
            else
            {
                return(this.NoContent());
            }
        }