Esempio n. 1
0
        public IHttpActionResult PutAdress(int id, AdressDTO adress)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != adress.AdressId)
            {
                return(BadRequest());
            }

            Handin22.Adress a = _unitOfWork.Adress.Get(id);

            if (a == null)
            {
                return(NotFound());
            }
            a.Street   = adress.Street;
            a.Number   = adress.Number;
            a.AdressId = adress.AdressId;

            _unitOfWork.Complete();

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 2
0
        public IHttpActionResult GetAdress(int id)
        {
            Handin22.Adress adress = _unitOfWork.Adress.Get(id);
            if (adress == null)
            {
                return(NotFound());
            }

            var adressDTO = new AdressDTO()
            {
                AdressId = adress.AdressId,
                Number   = adress.Number,
                Street   = adress.Street
            };

            return(Ok(adress));
        }
Esempio n. 3
0
        public IHttpActionResult DeleteAdress(int id)
        {
            Handin22.Adress adress = _unitOfWork.Adress.Get(id);
            if (adress == null)
            {
                return(NotFound());
            }

            _unitOfWork.Adress.Remove(adress);
            _unitOfWork.Complete();

            var adDTO = new AdressDTO()
            {
                AdressId = adress.AdressId,
                Number   = adress.Number,
                Street   = adress.Street
            };

            return(Ok(adress));
        }
Esempio n. 4
0
        public IHttpActionResult PostAdress(Handin22.Adress adress)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Handin22.Adress adressdto = new Handin22.Adress()
            {
                Street   = adress.Street,
                Number   = adress.Number,
                AdressId = adress.AdressId
            };

            _unitOfWork.Adress.Add(adressdto);
            _unitOfWork.Complete();

            adress.AdressId = adressdto.AdressId;

            return(CreatedAtRoute("DefaultApi", new { id = adress.AdressId }, adress));
        }