public IHttpActionResult CreateRoom(CreateRoomBindingModel model) { var userId = this.idProvider.GetId(); if (userId == null) { return this.Unauthorized(); } if (!ModelState.IsValid) { return BadRequest(ModelState); } var roomNameExists = this.Data.Rooms.GetAll().Any(r => r.Name == model.Name); if (roomNameExists) { return this.BadRequest("Room name already exists"); } var room = new Room { Name = model.Name }; this.Data.Rooms.Add(room); this.Data.SaveChanges(); return Ok(string.Format("Room with id: {0}, successfully created", room.Id)); }
public IHttpActionResult CreateRoom(CreateRoomBindingModel model) { var userId = this.User.Identity.GetUserId(); if (userId == null) { return this.Unauthorized(); } if (!ModelState.IsValid) { return BadRequest(ModelState); } var room = new Room { Name = model.Name }; this.Data.Rooms.Add(room); this.Data.SaveChanges(); return Ok(string.Format("Room with id: {0}, successfully created", room.Id)); }