/// <summary> /// /// </summary> public static bool CheckList(TagReadDataEventArgs e) { //Check dt if EPC already exist. if (BookListing.getBookList().Any(p => p.EPC == e.TagReadData.EpcString)) { return(false); } if (UnknownList.Any(p => p.EPC == e.TagReadData.EpcString)) { var list = UnknownList.First(f => f.EPC == e.TagReadData.EpcString); var index = UnknownList.IndexOf(list); UnknownList[index].timeStamp = e.TagReadData.Time.ToString(); UnknownList[index].RSSI = e.TagReadData.Rssi.ToString(); // double distance = Math.Pow((-30 - Double.Parse(UnknownList[index].RSSI)) / (10 * 2), 10); // UnknownList[index].RSSI = distance.ToString(); Console.WriteLine("[Update Unknown Tag] " + e.TagReadData.EpcString + e.TagReadData.Time.ToString() + " - " + e.TagReadData.Rssi); return(true); } else { addUnknownRFIDItem(e.TagReadData.EpcString, e.TagReadData.Time.ToString(), e.TagReadData.Rssi.ToString()); return(false); } }
public void ProcessImage(Stream imageStream, BookListing listing) { var imageName = Guid.NewGuid().ToString(); this.UploadImageToStorage(imageStream, imageName); this.SubmitImageForProcessing(listing.Id, imageName); }
public void SaveNewListing(BookListing newListing) { string connectionString = ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString; CloudStorageAccount account = CloudStorageAccount.Parse(connectionString); CloudTableClient tableClient = account.CreateCloudTableClient(); // Create table CloudTable table = tableClient.GetTableReference("books"); table.CreateIfNotExists(); //Create entity to insert BookListingTableEntity entity = new BookListingTableEntity(newListing.Id); entity.Description = newListing.Description; entity.ImageId = newListing.ImageId; entity.Price = newListing.Price; entity.PublishedOn = newListing.PublishedOn; entity.Title = newListing.Title; // Create table operation TableOperation insertOperation = TableOperation.Insert(entity); // Execute operation table.Execute(insertOperation); //var listingsPath = this.GetListingsPath(); //var filePath = listingsPath + newListing.Id + ".json"; //Directory.CreateDirectory(listingsPath); //var json = JsonConvert.SerializeObject(newListing); //File.WriteAllText(filePath, json); }
private IEnumerable <BookListing> GetBookListings() { var listings = new List <BookListing>(); // Connect string connectionString = ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString; CloudStorageAccount account = CloudStorageAccount.Parse(connectionString); CloudTableClient tableClient = account.CreateCloudTableClient(); // Get table CloudTable table = tableClient.GetTableReference("books"); table.CreateIfNotExists(); // Generate query TableQuery <BookListingTableEntity> query = new TableQuery <BookListingTableEntity>() .Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "books")); var listingsEntity = table.ExecuteQuery(query); foreach (var listingEntity in listingsEntity) { BookListing listing = new BookListing(listingEntity.RowKey, listingEntity.Title, listingEntity.Description, listingEntity.Price, listingEntity.PublishedOn, listingEntity.ImageId); listings.Add(listing); } return(listings); }
private static string GetImageUrlForListing(BookListing listing, string containerUrl, string suffix) { if (listing.ImageId == null) { return("/Content/images/no-image.png"); } return(containerUrl + listing.ImageId + suffix); }
public void SaveNewListing(BookListing newListing) { var filePath = this.listingFolder + newListing.Id + ".json"; Directory.CreateDirectory(this.listingFolder); var json = JsonConvert.SerializeObject(newListing); File.WriteAllText(filePath, json); }
public static BookListingModel FromListing(BookListing listing) { var viewModel = new BookListingModel(); viewModel.BookDescription = listing.Description; viewModel.BookId = listing.Id; viewModel.BookTitle = listing.Title; viewModel.Price = Math.Round(listing.Price, 2); return(viewModel); }
private void btn_SubmitNewItem_Click(object sender, RoutedEventArgs e) { if (CheckInput() == true) { // UnknownRFIDList.RemoveUnknownRFIDItem(selectedItem); //Add new ItemBook object //CheckInput DBHelper.addBookQuery(selectedItem.EPC, selectedItem.timeStamp, selectedItem.RSSI, tbox_BookTitle.Text, tbox_Autor.Text, cbox_Genre.Text, imageData); BookListing.addBookItem(selectedItem.EPC, selectedItem.timeStamp, selectedItem.RSSI, tbox_BookTitle.Text, tbox_Autor.Text, cbox_Genre.Text, imageData); this.Close(); //Close this window when done. } }
private BookViewModel BookViewModelFromEntity(BookListing entity, string imageContainerUrl) { var viewModel = new BookViewModel() { BookDescription = entity.Description, BookId = entity.Id, BookTitle = entity.Title, Price = entity.Price, ImageFullUrl = GetImageUrlForListing(entity, imageContainerUrl, ".jpg"), ImageThumbnailUrl = GetImageUrlForListing(entity, imageContainerUrl, "_thumb.jpg") }; return(viewModel); }
public async Task <ActionResult> Listing(EditListingViewModel viewModel) { if (ModelState.IsValid) { ApplicationUser user = await usrCtx.GetUserAsync(HttpContext.User); BookListing newListing = new BookListing(); newListing.ApplicationUserID = user.Id; if (Request.Form["listingTradeCheckBox"] == "on") { newListing.AskingPrice = -1; } else { newListing.AskingPrice = viewModel.price; } newListing.Condition = viewModel.condition; newListing.BookID = viewModel.book.ID; newListing.Type = SELL; if (!viewModel.newCourse)// if they picked a course from the dropdown { newListing.CourseID = viewModel.courseID; } else // if they created a new course { Course newCourse = new Course(); newCourse.Dept = viewModel.courseDept; newCourse.CourseNum = Int16.Parse(viewModel.courseNum); newCourse.Name = viewModel.courseName; newCourse.SchoolID = user.SchoolID; //newCourse.BookToCourses.Add(); ctx.Courses.Add(newCourse); newListing.Course = newCourse; } ctx.BookListings.Add(newListing); ctx.SaveChanges(); return(RedirectToAction("Index", "Profile")); } else { viewModel.book = ctx.Books.Where(a => a.ID == viewModel.book.ID).FirstOrDefault(); viewModel.courses = ctx.Courses.ToList(); return(View(viewModel)); } }
private IEnumerable <BookListing> GetBookListings() { var table = this.GetListingsTable(); var query = new TableQuery <BookListingTableEntity>(); var listings = new List <BookListing>(); foreach (BookListingTableEntity entity in table.ExecuteQuery(query)) { var bookListing = new BookListing(entity.RowKey, entity.Title, entity.Description, entity.Price, entity.PublishedOn); bookListing.SetImage(entity.ImageId); listings.Add(bookListing); } return(listings); }
public void ProcessImage(Stream imageStream, BookListing listing) { // Resize images var thumbnailBytes = this.ResizeImageForThumbnail(imageStream); var newImageBytes = this.ResizeImageForFullImage(imageStream); var imageName = Guid.NewGuid().ToString(); var imagePath = this.GetImagesPath() + imageName + ".jpg"; var thumbnailPath = this.GetImagesPath() + imageName + "_thumb.jpg"; // Write images to disk Directory.CreateDirectory(this.GetImagesPath()); File.WriteAllBytes(imagePath, newImageBytes); File.WriteAllBytes(thumbnailPath, thumbnailBytes); // Update BookListing with image name listing.SetImage(imageName); }
public ActionResult SubmitPost(BookListingSubmissionModel model) { if (!this.ModelState.IsValid) { return(this.View(model)); } var bookService = new BookListingService(this.listingsFolder, this.imagesFolder); var newListing = BookListing.New(model.BookTitle, model.BookDescription, model.Price); if (model.BookImage != null) { var imageService = new ImageProcessingService(this.imagesFolder); imageService.ProcessImage(model.BookImage.OpenReadStream(), newListing); } bookService.SaveNewListing(newListing); return(this.RedirectToAction("Index", "Books")); }
public ActionResult SubmitPost(SubmitBookViewModel model) { if (!this.ModelState.IsValid) { return(this.View(model)); } var bookService = new BookListingService(this.Server); var newListing = BookListing.New(model.BookTitle, model.BookDescription, model.Price); bookService.SaveNewListing(newListing); if (model.BookImage != null) { var imageService = new ImageProcessingService(this.Server); imageService.ProcessImage(model.BookImage.InputStream, newListing); } return(this.RedirectToAction("Index", "Books")); }
public MainWindow() { //Create WPF componects InitializeComponent(); //Attempt connection with DB. DBHelper.EstablishConnection(); //Setup both datagrids UnregisteredDataGrid.ItemsSource = UnknownRFIDList.getUnknownRFIDList(); dg_BookTable.ItemsSource = BookListing.getBookList(); //Load all books with the DB loadBook(); // Test data // DateTime TodayDates = DateTime.Now; // UnknownRFIDList.addUnknownRFIDItem("2313213123213222", TodayDates.ToString(), "-24"); //Setup UI updateConnectiveStatus(); }
public void ProcessImage(Stream imageStream, BookListing listing) { // Resize images var thumbnailBytes = this.ResizeImageForThumbnail(imageStream); var newImageBytes = this.ResizeImageForFullImage(imageStream); var imageName = Guid.NewGuid().ToString(); //var imagePath = this.GetImagesPath() + imageName + ".jpg"; //var thumbnailPath = this.GetImagesPath() + imageName + "_thumb.jpg"; // Write images to disk //Directory.CreateDirectory(this.GetImagesPath()); //File.WriteAllBytes(imagePath, newImageBytes); //File.WriteAllBytes(thumbnailPath, thumbnailBytes); string connectionString = ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString; CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); // Create container CloudBlobContainer container = blobClient.GetContainerReference("images"); container.CreateIfNotExists(); // Change access to Blob BlobContainerPermissions permissions = new BlobContainerPermissions() { PublicAccess = BlobContainerPublicAccessType.Blob }; // Get blob reference CloudBlockBlob thumnailBlob = container.GetBlockBlobReference(imageName + "_thumb.jpg"); CloudBlockBlob imageBlob = container.GetBlockBlobReference(imageName + ".jpg"); // Read image bytes thumnailBlob.UploadFromByteArray(thumbnailBytes, 0, thumbnailBytes.Length); imageBlob.UploadFromByteArray(newImageBytes, 0, newImageBytes.Length); // Update BookListing with image name listing.SetImage(imageName); }
/// <summary> /// /// </summary> private void OnTagRead(Object sender, TagReadDataEventArgs e) { bool check_Unknown = false; bool check_Book = false; try { Application.Current.Dispatcher.BeginInvoke( DispatcherPriority.Background, new Action(() => { if (toggelReader == false) { Console.WriteLine("Read Booklisting End"); reader.StopReading(); return; } check_Unknown = UnknownRFIDList.CheckList(e); UpdateUnkownRFID_DG(check_Unknown); })); Application.Current.Dispatcher.BeginInvoke( DispatcherPriority.Background, new Action(() => { if (toggelReader == false) { Console.WriteLine("Read Booklisting End"); reader.StopReading(); return; } check_Book = BookListing.CheckList(e); UpdateBook_DG(check_Book); })); } catch (Exception ex) { Console.WriteLine(ex); } }
/// <summary> /// /// </summary> public static void loadBook() { DataTable booksDT = new DataTable(); DBHelper.UpdateBookTable(); booksDT = DBHelper.GetDT(); Itembook book = new Itembook(); BookList.Clear(); foreach (DataRow row in booksDT.Rows) { book.Title = row["Book_Title"].ToString(); book.Autor = row["Book_Autor"].ToString(); book.Genre = row["Book_Genre"].ToString(); book.Image = (byte[])row["Book_Image"]; book.EPC = row["Book_RFID_EPC"].ToString(); book.timeStamp = row["Book_RFID_TimeStamp"].ToString(); book.RSSI = row["Book_RFID_RSSI"].ToString(); BookListing.addBookItem(book.EPC, book.timeStamp, book.RSSI, book.Title, book.Autor, book.Genre, book.Image); } }
public void SaveNewListing(BookListing newListing) { var tableEntity = BookListingTableEntity.FromEntity(newListing); StoreBookListingEntity(tableEntity); }
public async Task <ActionResult> WishList(EditListingViewModel viewModel) { if (ModelState.IsValid) { ApplicationUser user = await usrCtx.GetUserAsync(HttpContext.User); Course newCourse = new Course(); BookListing newListing = new BookListing(); newListing.ApplicationUserID = user.Id; newListing.Condition = viewModel.condition; newListing.BookID = viewModel.book.ID; newListing.CourseID = viewModel.courseID; newListing.AskingPrice = viewModel.price; newListing.Type = WISHLIST; // If they created a new course, add the course to the database. if (viewModel.newCourse) { newCourse.Dept = viewModel.courseDept; newCourse.CourseNum = viewModel.courseID; newCourse.Name = viewModel.courseName; newCourse.SchoolID = user.SchoolID; ctx.Courses.Add(newCourse); newListing.Course = newCourse; } else { // Connect the book and the pre-existing course if it doesn't already exist. if (!ctx.BookToCourses.Where(a => a.BookID == viewModel.book.ID && a.CourseID == viewModel.courseID).Any()) { BookToCourse bookToCourse = new BookToCourse(); bookToCourse.BookID = viewModel.book.ID; bookToCourse.CourseID = viewModel.courseID; ctx.BookToCourses.Add(bookToCourse); } } ctx.BookListings.Add(newListing); ctx.SaveChanges(); // Put it after the new course is added and saved into the database so it receives an ID. if (viewModel.newCourse) { // Connect the book and the new course if it doesn't already exist. if (!ctx.BookToCourses.Where(a => a.BookID == viewModel.book.ID && a.CourseID == newCourse.ID).Any()) { BookToCourse bookToCourse = new BookToCourse(); bookToCourse.BookID = viewModel.book.ID; bookToCourse.CourseID = newCourse.ID; ctx.BookToCourses.Add(bookToCourse); ctx.SaveChanges(); } } return(RedirectToAction("Index", "Profile")); } else { viewModel.book = ctx.Books.Where(a => a.ID == viewModel.book.ID).FirstOrDefault(); viewModel.courses = ctx.Courses.ToList(); return(View(viewModel)); } }