public List <RentRoom> PostNew() { int contractId = 0; var rooms = this.GetAllInclude(); List <RentRoom> checkStatuses = new List <RentRoom>(); foreach (var r in rooms) { if (r.Status == "Có người") { contractId = _unitOfWork.Contracts.Find(c => c.RoomId.Equals(r.RoomId)).LastOrDefault().ContractId; RentRoom checkStatus = new RentRoom(); checkStatus.room = r; checkStatus.contractId = contractId; checkStatuses.Add(checkStatus); contractId = 0; } else { RentRoom checkStatus = new RentRoom(); checkStatus.room = r; checkStatus.contractId = contractId; checkStatuses.Add(checkStatus); } } return(checkStatuses); }
private async void btnUpload_Click(object sender, RoutedEventArgs e) { if (latitude == 0 || altitude == 0) { MessageDialog msgbox = new MessageDialog("Please provide your room's location on map"); await msgbox.ShowAsync(); } else if (storageFile == null) { MessageDialog msgbox = new MessageDialog("Please provide your room's photo"); await msgbox.ShowAsync(); } else if (tbxTitle.Text.Trim() == "") { MessageDialog msgbox = new MessageDialog("Please provide your room's title"); await msgbox.ShowAsync(); } else { try { btnUpload.IsEnabled = false; btnUpload.Content = "Uploading......"; string fileName = ""; bool imageExist = false; string fileAddress = ""; Random r = new Random(); if (!storageFile.Equals(null)) { imageExist = true; // Source: https://azure.microsoft.com/en-us/documentation/articles/mobile-services-javascript-backend-windows-universal-dotnet-upload-data-blob-storage/#test // Part one: upload images to database // Create the connectionstring String StorageConnectionString = "DefaultEndpointsProtocol=https;AccountName=uonlife;AccountKey=LzU9gRoJgvtKtY7rIPE3w1Z7Toc39AfcBO+Y+Q4ZCYoZmXd2KTgpZ5muya6JkxaZRtNAo3ib3FTpw7gAncpOPA=="; // Retrieve storage account from connection string. CloudStorageAccount storageAccount = CloudStorageAccount.Parse(StorageConnectionString); // Create the blob client. CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); // Retrieve a reference to a container. (pictures) CloudBlobContainer container = blobClient.GetContainerReference("images"); await container.CreateIfNotExistsAsync(); string sFileName = img.Source.ToString(); fileName = tbxTitle.Text.Trim() + r.Next(10000000, 99999999).ToString() + ".jpg"; CloudBlockBlob blobFromSASCredential = container.GetBlockBlobReference(fileName); await blobFromSASCredential.UploadFromFileAsync(storageFile); } // Step two: store data into table if (imageExist == true) { fileAddress = "https://uonlife.blob.core.windows.net/images/" + fileName; } RentRoom rentRoom = new RentRoom { roomTitle = tbxTitle.Text, price = tbxPrice.Text, address = tbxAddress.Text, type = tbxType.Text, bedrooms = tbxBedrooms.Text, bathrooms = tbxBathrooms.Text, description = tbxDescription.Text, contact = tbxContact.Text, altitude = this.altitude, latitude = this.latitude, imageAddress = fileAddress, publisher = GlobalVariable.loginUser }; await App.mobileService.GetTable <RentRoom>().InsertAsync(rentRoom); MessageDialog msgbox = new MessageDialog("Upload success"); await msgbox.ShowAsync(); Frame.Navigate(typeof(MainPage)); } catch (Exception ex) { MessageDialog msgbox = new MessageDialog("Error: " + ex.Message); await msgbox.ShowAsync(); btnUpload.IsEnabled = true; btnUpload.Content = "Upload"; } } }