Ejemplo n.º 1
0
        public IHttpActionResult PutRoom(int id, Room room)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != room.Id)
            {
                return BadRequest();
            }

            unitOfWork.Rooms.Update(room);

            try
            {
                unitOfWork.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!unitOfWork.Rooms.IsExist(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
Ejemplo n.º 2
0
        public async Task<IHttpActionResult> PostRoom(Room room, string name)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            unitOfWork.Rooms.Add(room);
            unitOfWork.SaveChanges();

            //string userName = User.Identity.GetUserName();
            IdentityUser user = await _repo.FindUserByName(name);
            string userId = user.Id;

            var link = new UserRoomLink()
            {
                RoomId = room.Id,
                UserId = userId,
                IsAdmin = true
            };

            unitOfWork.Links.Add(link);
            unitOfWork.SaveChanges();

            //return CreatedAtRoute("DefaultApi", new { id = room.Id }, room);

            return Ok(room.Id);
        }