public ShopItem NewWatch(NewWatchForm watchForm) { byte[] byteArray = Guid.NewGuid().ToByteArray(); BigInteger guid = new BigInteger(byteArray, true); this.setupWatchContractCall(guid.ToString()); UserInfo vendor = this.ValidateUserWithDualAuthCode(watchForm.UserName, watchForm.DualAuthCode); var receiptForFunctionCall = watchContractService.CreateWatchRequestAndWaitForReceiptAsync(new CreateWatchFunction() { VendorAddress = vendor.BlockchainAddress, GUID = guid, WatchType = watchForm.WatchName, GasPrice = 0 }).GetAwaiter().GetResult(); ShopItem shopItem = new ShopItem() { Cost = watchForm.Cost, GUID = guid.ToString(), isAvailable = false, isSold = false, longDescription = watchForm.LongDescription, shortDescription = watchForm.ShortDescription, Title = watchForm.WatchName }; var watchNumber = new Random().Next(1, 5); shopItem.PictureUrl = $"/images/watch{watchNumber}.jpg"; this.context.ShopItems.Add(shopItem); this.context.SaveChanges(); return(shopItem); }
public ShopItem NewWatch(NewWatchForm watchForm) { if (ModelState.IsValid) { return(this.ContractService.NewWatch(watchForm)); } else { throw new ArgumentException("invalid submission"); } }