Example #1
0
        public IHttpActionResult PutRoomType(int id, RoomTypeViewModel roomTypeViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != roomTypeViewModel.RoomTypeId)
            {
                return(BadRequest());
            }
            RoomType roomType = ViewModelMapper.ToModelRoomTypes(roomTypeViewModel);

            db.Entry(roomType).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RoomTypeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #2
0
        public IHttpActionResult PostRoomType(RoomTypeViewModel roomTypeViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            RoomType roomType = ViewModelMapper.ToModelRoomTypes(roomTypeViewModel);

            db.RoomTypes.Add(roomType);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = roomType.RoomTypeId }, ViewModelMapper.ToViewModelRoomTypes(roomType)));
        }