Пример #1
0
        public async Task <IActionResult> PutProduct(int id, Product product)
        {
            if (id != product.ProductId)
            {
                return(BadRequest());
            }

            _context.Entry(product).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #2
0
        public async Task <IActionResult> Create([Bind("CustomerId,NameStyle,Title,FirstName,MiddleName,LastName,Suffix,CompanyName,SalesPerson,EmailAddress,Phone,PasswordHash,PasswordSalt,Rowguid,ModifiedDate")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
Пример #3
0
        public async Task <IActionResult> Create([Bind("ProductId,Name,ProductNumber,Color,StandardCost,ListPrice,Size,Weight,ProductCategoryId,ProductModelId,SellStartDate,SellEndDate,DiscontinuedDate,ThumbNailPhoto,ThumbnailPhotoFileName,Rowguid,ModifiedDate")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductCategoryId"] = new SelectList(_context.ProductCategory, "ProductCategoryId", "Name", product.ProductCategoryId);
            ViewData["ProductModelId"]    = new SelectList(_context.ProductModel, "ProductModelId", "Name", product.ProductModelId);
            return(View(product));
        }
Пример #4
0
        public async Task SaveThumbnail(int id, string fileName, IDataContent content)
        {
            try
            {
                TransactionOptions topts = new TransactionOptions()
                {
                    Timeout = TimeSpan.FromSeconds(60), IsolationLevel = IsolationLevel.Serializable
                };
                using (TransactionScope trxScope = new TransactionScope(TransactionScopeOption.Required, topts, TransactionScopeAsyncFlowOption.Enabled))
                    using (System.Data.Common.DbConnection conn = _connectionFactory.GetRIAppDemoConnection())
                    {
                        DbContextOptionsBuilder <AdventureWorksLT2012Context> dbOptionsBuilder = new DbContextOptionsBuilder <AdventureWorksLT2012Context>();
                        dbOptionsBuilder.UseSqlServer(conn);
                        // Create in the same transaction !!!
                        using (AdventureWorksLT2012Context db = new AdventureWorksLT2012Context(dbOptionsBuilder.Options))
                        {
                            Product product = await db.Product.Where(a => a.ProductId == id).FirstOrDefaultAsync();

                            if (product == null)
                            {
                                throw new Exception(string.Format("Product {0} is Not Found", id));
                            }

                            using (BlobStream blobStream = new BlobStream(conn as SqlConnection, "[SalesLT].[Product]", "ThumbNailPhoto",
                                                                          string.Format("WHERE [ProductID]={0}", id)))
                                using (BufferedStream bufferedStream = new BufferedStream(blobStream, 128 * 1024))
                                {
                                    await blobStream.InitColumnAsync();

                                    blobStream.Open();
                                    Task delayTask     = Task.Delay(TimeSpan.FromSeconds(15));
                                    Task completedTask = await Task.WhenAny(content.CopyToAsync(bufferedStream), delayTask);

                                    if (completedTask == delayTask)
                                    {
                                        throw new Exception("Saving Image took longer than expected");
                                    }

                                    await bufferedStream.FlushAsync();
                                }

                            product.ThumbnailPhotoFileName = fileName;
                            await db.SaveChangesAsync();

                            trxScope.Complete();
                        }
                    }
            }
            catch (Exception ex)
            {
                string msg = "";
                if (ex != null)
                {
                    msg = ex.GetFullMessage();
                }

                _logger.LogError(ex, msg);
                throw;
            }
        }
Пример #5
0
        // public async Task<IActionResult> Create([Bind("SalesOrderId,SalesOrderDetailId,OrderQty,ProductId,UnitPrice,UnitPriceDiscount,LineTotal,Rowguid,ModifiedDate")] SalesOrderDetail salesOrderDetail);
        public async Task <IActionResult> Create([Bind] CreateSO command)
        {
            if (ModelState.IsValid)
            {
                var order = _context.SalesOrderHeader.First(o => o.SalesOrderId == command.SalesOrderId);
                order.SalesOrderDetail.Add(command.ToEntity());

                await _context.SaveChangesAsync();

                //_context.SalesOrderDetail.Add(salesOrderDetail);
                //_context.SaveChanges();
                return(RedirectToAction(nameof(Index)));
                // return RedirectToAction("Index");
            }
            //ViewData["ProductId"] = new SelectList(_context.Product, "ProductId", "Name", salesOrderDetail.ProductId);
            //ViewData["SalesOrderId"] = new SelectList(_context.SalesOrderHeader, "SalesOrderId", "SalesOrderNumber", salesOrderDetail.SalesOrderId);
            //return View(salesOrderDetail);
            return(View(command));
        }