public async Task <IActionResult> Edit(int id, [Bind("OrderDetailId,OrderId,ProductId,Quantity,ProductPrice")] ServiceOrderDetail serviceOrderDetail) { if (id != serviceOrderDetail.OrderDetailId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(serviceOrderDetail); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ServiceOrderDetailExists(serviceOrderDetail.OrderDetailId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ProductId"] = new SelectList(_context.Products, "ProductId", "ProductId", serviceOrderDetail.ProductId); return(View(serviceOrderDetail)); }
public async Task <List <ServiceOrderHasProductsDTO> > Handle(GetAllServiceOrdersQuery request, CancellationToken cancellationToken) { List <ServiceOrderHasProducts> serviceOrderList = await _serviceOrderRepository.GetServiceOrders(); List <ServiceOrderHasProductsDTO> listResult = new List <ServiceOrderHasProductsDTO>(); foreach (var item in serviceOrderList) { ServiceOrderDTO serviceOrderDTO = new ServiceOrderDTO(item.ServiceOrder.ServiceOrderId, item.ServiceOrder.CreationDate, item.ServiceOrder.Status); ProductDTO product = new ProductDTO(item.Product.ProductId, item.Product.ProductBrand, item.Product.ProductName, item.Product.ProductPrice); ServiceOrderDetail service = await _serviceOrderRepository.GetDetail(item.ServiceOrder.ServiceOrderId); ServiceOrderDetailDTO serviceOrderDetailDTO = new ServiceOrderDetailDTO(service.ServiceOrderDetailId, (int)service.ServiceType, service.Price, service.Description, service.AlternativeAddress); listResult.Add(new ServiceOrderHasProductsDTO( item.ServiceOrdersHasProductsId, serviceOrderDTO, product, serviceOrderDetailDTO )); } return(listResult); }
public async Task <IActionResult> Create([Bind("OrderDetailId,OrderId,ProductId,Quantity,ProductPrice")] ServiceOrderDetail serviceOrderDetail) { if (ModelState.IsValid) { _context.Add(serviceOrderDetail); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ProductId"] = new SelectList(_context.Products, "ProductId", "ProductId", serviceOrderDetail.ProductId); return(View(serviceOrderDetail)); }
public async Task InsertDetail(ServiceOrderDetail serviceOrderDetail) { await _context.ServiceOrdersDetails.AddAsync(serviceOrderDetail); }
public async Task <ServiceOrderDetail> GetDetail(Guid guid) { ServiceOrderDetail orderDetail = await _context.ServiceOrdersDetails.Where(x => x.ServiceOrder.ServiceOrderId == guid).FirstOrDefaultAsync(); return(orderDetail); }