private void btnSave_Click(object sender, EventArgs e) { if (txtBookName.Text == "") { lblBook.Visible = true; } else if (txtBookName.Text != "") { lblBook.Visible = false; } if (txtAuthorName.Text == "") { lblAuthorName.Visible = true; } else if (txtAuthorName.Text != "") { lblAuthorName.Visible = false; } if (txtAuthorFname.Text == "") { lblAuthorFname.Visible = true; } else if (txtAuthorFname.Text != "") { lblAuthorFname.Visible = false; } if (lblBook.Visible == false && lblAuthorName.Visible == false && lblAuthorFname.Visible == false) { DateTime date = DateTime.Now; books = new Books() { BookCondition = 0, BookState = 2, AuthorName = txtAuthorName.Text, AuthorFName = txtAuthorFname.Text, Title = txtBookName.Text, Subject = txtSubject.Text, PublishYear = cmbBoxPublishYear.SelectedItem.ToString(), PurchasedTime = date, Price = txtPrice.Text }; booksRepository.AddNewBook(books); } }
public async Task <HttpResponseMessage> PostFormData() { // Parse the connection string and return a reference to the storage account. CloudStorageAccount storageAccount = CloudStorageAccount.Parse( CloudConfigurationManager.GetSetting("BlobStorageConnectionString")); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); if (!Request.Content.IsMimeMultipartContent()) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } try { var provider = new MultipartFormDataStreamProvider(Path.GetTempPath()); await Request.Content.ReadAsMultipartAsync(provider); var fileData = provider.FileData.FirstOrDefault(); var formData = provider.FormData; var containerName = formData["containerName"]; var blobUrl = SaveBlob(fileData, containerName).Url; if (containerName == "books") { booksRepo.AddNewBook(formData, blobUrl, UserId); } else if (containerName == "members") { librariesRepo.AddNewLibraryMember(formData, blobUrl, UserId); } } catch (Exception e) { throw new HttpResponseException(HttpStatusCode.InternalServerError); } return(new HttpResponseMessage(HttpStatusCode.OK)); }