public IHttpActionResult PutCountry(int id, Country country)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

            try
            {
                db.UpdateCountry(id, country);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CountryExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
Exemplo n.º 2
0
        public Country CreateCountry(Country country)
        {
            db.Countries.Add(country);
            db.SaveChanges();

            return country;
        }
Exemplo n.º 3
0
        public Country Create(Country oCountry)
        {
            if (oCountry != null)
            {
                return oCountryRepos.CreateCountry(oCountry);
            }

            return null;
        }
        public IHttpActionResult PostCountry(Country country)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.CreateCountry(country);

            return CreatedAtRoute("DefaultApi", new { id = country.CountryID }, country);
        }
Exemplo n.º 5
0
        public void UpdateCountry(int id, Country country)
        {
            db.Entry(country).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Converts this instance of <see cref="CountryDTO"/> to an instance of <see cref="Country"/>.
        /// </summary>
        /// <param name="dto"><see cref="CountryDTO"/> to convert.</param>
        public static Country ToEntity(this CountryDTO dto)
        {
            if (dto == null) return null;

            var entity = new Country();

            entity.CountryID = dto.CountryID;
            entity.Name = dto.Name;
            entity.Abbreviation = dto.Abbreviation;
            entity.Code = dto.Code;
            entity.PhoneCode = dto.PhoneCode;

            dto.OnEntity(entity);

            return entity;
        }
Exemplo n.º 7
0
 /// <summary>
 /// Invoked when <see cref="ToEntity"/> operation is about to return.
 /// </summary>
 /// <param name="entity"><see cref="Country"/> converted from <see cref="CountryDTO"/>.</param>
 static partial void OnEntity(this CountryDTO dto, Country entity);