コード例 #1
0
ファイル: CategoryService.cs プロジェクト: vitagon/tech-shop
        public async Task <bool> CreateCategoryAsync(Category category)
        {
            category.Id = 0;
            await _techDbContext.Category.AddAsync(category);

            var created = await _techDbContext.SaveChangesAsync();

            return(created > 0);
        }
コード例 #2
0
        public async Task <ActionResult <Order> > PostOrder(Order order)
        {
            _context.ORDS.Add(order);
            await _context.SaveChangesAsync();

            /*this calls GetOrder() to get the order with the given orderId as the order.orderId. The new {orderId}
             * must be named exactly as the parameter in the GetOrder() function called by the "GetOrder" string.
             */
            return(CreatedAtAction("GetOrder", new { orderId = order.ORD_ID }, order));
        }
コード例 #3
0
        public async Task <IActionResult> PutOrderProduct(int orderProductId, OrderProduct orderProduct)
        {
            orderProduct.ORD_PRD_ID = orderProductId;

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OrderProductExists(orderProductId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(NoContent());
        }
コード例 #4
0
        public async Task <IActionResult> PutUser(int id, User user)
        {
            user.USER_ID = id;

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

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