/// <summary> /// Add the specified room. /// </summary> /// <param name="model">Model.</param> public void Add(RoomViewModel model) { Rooms room = new Rooms() { Size = model.Size, Available = model.Available ? 1 : 0, How_many_persons = model.HowManyPerson, Price = model.Price }; context.Rooms.Add(room); context.SaveChanges(); }
public HttpResponseMessage Post(RoomViewModel model) { if (ModelState.IsValid) { _repository.Add(model); var response = Request.CreateResponse<RoomViewModel>(HttpStatusCode.Created, model); string uri = Url.Link("DefaultApi", new { id = model.Id }); response.Headers.Location = new Uri(uri); return response; } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }
// nie wiem czy potrzebne /// <summary> /// Update the room with specified id. /// </summary> /// <param name="model">Model.</param> public void Update(RoomViewModel model) { var room = context.Rooms.Single(x => x.Id == model.Id); room.Size = model.Size; room.Available = model.Available ? 1 : 0; room.How_many_persons = model.HowManyPerson; room.Price = model.Price; context.SaveChanges(); }