Esempio n. 1
0
        public async Task<Order> UpdateOrder(Order order)
        {
            // Update entity state
            _dbContext.ApplyChanges(order);

            try
            {
                await _dbContext.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException updateEx)
            {
                throw new FaultException(updateEx.Message);
            }

            // Load related entities, accept changes and return updated order
            await _dbContext.LoadRelatedEntitiesAsync(order);
            order.AcceptChanges();
            return order;
        }
Esempio n. 2
0
        public async Task<Order> CreateOrder(Order order)
        {
            // Mark order as added
            order.TrackingState = TrackingState.Added;
            _dbContext.ApplyChanges(order);

            try
            {
                await _dbContext.SaveChangesAsync();
            }
            catch (DbUpdateException updateEx)
            {
                throw new FaultException(updateEx.Message);
            }

            // Load related entities and accept changes
            await _dbContext.LoadRelatedEntitiesAsync(order);
            order.AcceptChanges();
            return order;
        }