public async Task <IActionResult> PutDoctor(int id, Doctor doctor) { if (id != doctor.IdDoctor) { return(BadRequest()); } _context.Entry(doctor).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DoctorExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task CommitAsync() { try { await _context.SaveChangesAsync().ConfigureAwait(false); } finally { Dispose(); } }
public async Task <int> createOrder(OrderCreateRequest request) { if (await dbContext.Client.Where(client => client.clientId == request.clientId).SingleOrDefaultAsync() != null) { var order = new Order { creationTime = DateTime.Now, recipientName = request.recipientName, recipientEmail = request.recipientEmail, recipientPhoneNumber = request.recipientPhoneNumber, recipientSurname = request.recipientSurname, deliveryAddress = request.deliveryAddress, deliveryType = request.deliveryType, paymentType = request.paymentType, realizationState = RealizationStateEnum.NotAccepted, clientId = request.clientId }; if (order.paymentType == PaymentTypeEnum.OnlinePayment) { order.realizationState = RealizationStateEnum.Accepted; } await dbContext.Order.AddAsync(order); order.Products = new List <OrderProduct>(); foreach (OrderProductConnection orderProdcut in request.products) { var product = await dbContext.Product.Where(product => product.productId == orderProdcut.productId).SingleOrDefaultAsync(); if (product != null) { order.Products.Add(new OrderProduct { orderId = order.orderId, productId = product.productId, amount = orderProdcut.amount }); } else { throw new ProductNotFoundException("no such user"); } } await dbContext.SaveChangesAsync(); return(order.orderId); } else { throw new UserNotFoundException("no such user"); } }
public async Task CommitAsync() { try { await BeginTransactionAsync(); await _context.SaveChangesAsync(); await _transaction.CommitAsync(); } catch { await RollbackAsync(); throw; } finally { _transaction.Dispose(); Dispose(); } }
public string AddDoctor(Doctor doctor) { context.Add(doctor); context.SaveChangesAsync(); return("Adding complete"); }
public async Task SaveChangesAsync() { await _context.SaveChangesAsync().ConfigureAwait(false); }