Пример #1
0
 public void SaveOrder(Order order)
 {
     context.AttachRange(order.Lines.Select(c => c.Product));
     if (order.OrderID == 0)
     {
         context.Add(order);
     }
     context.SaveChanges();
 }
Пример #2
0
        public void SaveOrder(Order order)
        {
            OrderEnt orderEnt = ConvertEntity.ConvertToOrderEnt(order);

            context.AttachRange(order.Lines.Select(l => l.Book));
            if (order.OrderId == 0)
            {
                context.Orders.Add(orderEnt);
            }
            context.SaveChanges();
        }
Пример #3
0
        public async Task <IActionResult> Post(Pet pet)
        {
            _logger.LogDebug(
                $"{nameof(PetController)}.{nameof(Post)} method called. Parameters: {nameof(pet)} = {pet}");
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            _db.AttachRange(pet.Type, pet.Owner);
            //_db.Entry(pet.Type).State = EntityState.Unchanged;
            //_db.Entry(pet.Owner).State = EntityState.Unchanged;
            var result = await _db.Pets.AddAsync(pet)
                         .ConfigureAwait(false);

            var affected = await _db.SaveChangesAsync(true).ConfigureAwait(false);

            if (affected == 0)
            {
                NoContent();
            }
            return(Ok(result.Entity));
        }