public async Task AddRowHouse(int postalCode, string address) { var rowHouse = new RowHouse(postalCode, address); using (var documentClient = CreateDocumentClient()) { await EnsureCollectionIsCreated(documentClient); await documentClient.CreateDocumentAsync(CreateRowHouseCollectionUri(), rowHouse); } }
public async Task <Guid> AddApartment(int postalCode, string rowAddress, string lastName, int apartmentNumber) { Guid apartmentId = Guid.NewGuid(); var apartment = new Apartment { Id = apartmentId, LastName = lastName, ApartmentNumber = apartmentNumber }; using (var documentClient = CreateDocumentClient()) { Document document = GetRowHouse(documentClient, postalCode, rowAddress); RowHouse rowHouse = RowHouse.LoadFrom(document); rowHouse.AddApartment(apartment); await documentClient.ReplaceDocumentAsync(rowHouse.Document); } return(apartmentId); }
private void ChangeBtn_Click(object sender, EventArgs e) { //If no object is chosen if (objectsLView.SelectedItems.Count == 0) { MessageBox.Show("Please choose an object in the list to change"); return; } //Get the ID of the selected object so we can change the corresponding object //in the list int idOfSelected = Int32.Parse(objectsLView.SelectedItems[0].SubItems[0].Text); RealEstateObject objectToAdd; //Create the type of object according to what type of estate it is string typeOfEstate = typeOfEstateCBox.GetItemText(typeOfEstateCBox.SelectedItem); switch (typeOfEstate) { case "WareHouse": objectToAdd = new Warehouse(); if (landSizeTBox.Text.ToString() != "") { Warehouse warehouse = (Warehouse)objectToAdd; warehouse.LandSizeInSquareMeters = Int32.Parse(landSizeTBox.Text); } else { MessageBox.Show("Please enter land size", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } break; case "Store": objectToAdd = new Store(); break; case "Apartment": objectToAdd = new Apartment(); if (floorTBox.Text.ToString() != "") { Apartment apartment = (Apartment)objectToAdd; apartment.Floor = floorTBox.Text; } else { MessageBox.Show("Please enter floor", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } break; case "Villa": objectToAdd = new Villa(); break; case "RowHouse": objectToAdd = new RowHouse(); break; default: MessageBox.Show("Please choose type of estate", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } SetLegalForm(objectToAdd); //Check so the correct fields are filled in, //then add/ replace with the new edited object to the list if (CheckFields()) { MakeObjectToAdd(objectToAdd); } else { MessageBox.Show("Please enter text in all fields", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } objectToAdd.Id = idOfSelected; for (int i = 0; i < estateManager.Count; i++) { if (estateManager.GetAt(i).Id == idOfSelected) { estateManager.ChangeAt(objectToAdd, i); } } ShowAllObjectsInListBox(); }
private void AddBtn_Click(object sender, EventArgs e) { RealEstateObject objectToAdd; //Create the type of object according to what type of estate it is string typeOfEstate = typeOfEstateCBox.GetItemText(typeOfEstateCBox.SelectedItem); switch (typeOfEstate) { case "WareHouse": objectToAdd = new Warehouse(); if (landSizeTBox.Text.ToString() != "") { Warehouse warehouse = (Warehouse)objectToAdd; warehouse.LandSizeInSquareMeters = Int32.Parse(landSizeTBox.Text); } else { MessageBox.Show("Please enter land size", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } break; case "Store": objectToAdd = new Store(); break; case "Apartment": objectToAdd = new Apartment(); if (floorTBox.Text.ToString() != "") { Apartment apartment = (Apartment)objectToAdd; apartment.Floor = floorTBox.Text; } else { MessageBox.Show("Please enter floor", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } break; case "Villa": objectToAdd = new Villa(); break; case "RowHouse": objectToAdd = new RowHouse(); break; default: MessageBox.Show("Please choose type of estate", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } SetLegalForm(objectToAdd); //Check so the correct fields are filled in, //then add the object to the list if (CheckFields()) { MakeObjectToAdd(objectToAdd); } else { MessageBox.Show("Please enter text in all fields", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } objectToAdd.Id = id; estateManager.Add(objectToAdd); ShowAllObjectsInListBox(); ClearFields(); id++; }
//När användaren trycker på knappen Lägg till //Läs all indata från GUI i ett lokalt objekt av fastighet //Gör indata kontroll //Spara objektet i fastighetMngr private void btnAdd_Click(object sender, EventArgs e) { Estate estate; //holder for input - create in ReadInput //Send this object to ReadInput //for filling in values (input) //out tells ReadInput that the variable //is data out. All changes to this object //comes back here. //ReadInput creates all data used for the common fields of all estates. //The special for each are filled in later in the switch case. bool ok = ReadInput(out estate); if (ok) //If all common data (in variable estate) is OK { // Now create a correct estate according to the type combo switch ((EstateType)cmbTyp.SelectedIndex) { case EstateType.WareHouse: { // Use a copy constructor to set a warehouse with common data WareHouse wHouse = new WareHouse(estate); // If more data in GUI to fill in for this estate, do it here //Then send it to the manager for adding to the list estateMngr.Add(wHouse); break; } case EstateType.Villa: { // Same procedure all different types of estates Villa vHouse = new Villa(estate); // But here we need to add landSize size bool landSizeOk = false; vHouse.LandSize = ReadLandSize(out landSizeOk); if (!landSizeOk) return; estateMngr.Add(vHouse); break; } case EstateType.Store: { Store store = new Store(estate); estateMngr.Add(store); break; } case EstateType.RowHouse: { RowHouse rHouse = new RowHouse(estate); // Here we need to add landSize size bool gardenok = false; rHouse.LandSize = ReadLandSize(out gardenok); if (!gardenok) return; estateMngr.Add(rHouse); break; } case EstateType.Apartment: { Apartment apart = new Apartment(estate); // We need to add floor bool floorok = false; apart.Floor = ReadFloor(out floorok); if (!floorok) return; estateMngr.Add(apart); break; } } //Then Update the GUI UpdateResults(); } }