コード例 #1
0
        public IHttpActionResult CreateChurch(ChurchDto churchDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var church = Mapper.Map <ChurchDto, Church>(churchDto);

            _context.churches.Add(church);
            _context.SaveChanges();

            churchDto.Id = church.Id;

            return(Created(new Uri(Request.RequestUri + "/" + church.Id), churchDto));
        }
コード例 #2
0
        public void UpdateChurch(int Id, ChurchDto churchDto)
        {
            if (!ModelState.IsValid)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
            var churchInDB = _context.churches.SingleOrDefault(c => c.Id == Id);

            if (churchInDB == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
            //Mapper.Map<ChurchDto, Church>(churchDto, churchInDB);
            Mapper.Map(churchDto, churchInDB);

            /*
             * churchInDB.Name = churchDto.Name;
             * churchInDB.Address = churchDto.Address;
             * churchInDB.ProvinceId = churchDto.ProvinceId;*/

            _context.SaveChanges();
        }