private async Task AddDefects( IEnumerable <MrrSupplierDefect> defects, int mrrSupplierId, bool isCreate ) { if (!isCreate) { var defectsToDelete = await _context.MrrSupplierDefects .Where(x => x.MrrSupplierId == mrrSupplierId) .ToListAsync() .ConfigureAwait(false); await RemoveDefects(defectsToDelete).ConfigureAwait(false); } await using var transaction = await _context.Database .BeginTransactionAsync() .ConfigureAwait(false); try { await _context.MrrSupplierDefects.AddRangeAsync(defects).ConfigureAwait(false); await transaction.CommitAsync().ConfigureAwait(false); await _context.SaveChangesAsync().ConfigureAwait(false); } catch (Exception e) { await transaction.RollbackAsync().ConfigureAwait(false); throw new Exception(e.Message); } }
public async Task <IActionResult> Create([Bind("Id,Surname,Name,Patronymic,Address,PersonalNumber,PhoneNumber,TypeClient,Unn,BothDate,Information")] Client client) { if (ModelState.IsValid) { client.Id = Guid.NewGuid(); _context.Add(client); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(client)); }
public async Task <IActionResult> Create([Bind("Id,IdClient,IdOrder")] ClientOrders clientOrders) { if (ModelState.IsValid) { clientOrders.Id = Guid.NewGuid(); _context.Add(clientOrders); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["IdClient"] = new SelectList(_context.Clients, "Id", "Id", clientOrders.IdClient); ViewData["IdOrder"] = new SelectList(_context.Orders, "Id", "Id", clientOrders.IdOrder); return(View(clientOrders)); }
public async Task <IActionResult> Create(Order order) { if (ModelState.IsValid) { order.Id = Guid.NewGuid(); order.DateReceipt = DateTime.Now; _context.Add(order); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["IdEmployee"] = new SelectList(_context.Employees, "Id", "Id", order.EmployeeId); ViewData["IdOrganization"] = new SelectList(_context.Organizations, "Id", "Id", order.OrganizationId); return(View(order)); }
public async Task <dynamic> AddOrUpdate(MrrProcess parameter) { try { if (parameter.QualityEngineerClosedId is not null) { parameter.MrrClosedTimestamp = DateTime.Now; } var entity = _context.MrrProcesses.Update(parameter); await _context.SaveChangesAsync().ConfigureAwait(false); return(entity.Entity); } catch (Exception e) { throw new Exception(e.Message); } }
public async Task <dynamic> AddOrUpdate(MrrCustomer data) { if (data == null) { throw new ArgumentNullException(nameof(data)); } var id = data.MrrCustomerId; if (data.QualityEngineerClosedId is null) { data.MrrClosedTimestamp = null; } else { data.MrrClosedTimestamp ??= DateTime.Now; } data.DateModified = DateTime.Now; var entity = _context.MrrCustomers.Update(data); await _context.SaveChangesAsync().ConfigureAwait(false); var mrrCustomer = await GetMrrCustomer(entity.Entity.MrrCustomerId) .ConfigureAwait(false); // send on create send to quality team if (id == 0) { await SendReport(mrrCustomer).ConfigureAwait(false); } // send on create send to logistics team if ( id > 0 && mrrCustomer.MrrClosedTimestamp is not null && mrrCustomer.LogisticsReturnPo is null ) { await SendReport(mrrCustomer).ConfigureAwait(false); } // send on create send to finance team if ( id > 0 && mrrCustomer.MrrClosedTimestamp is not null && mrrCustomer.LogisticsReturnPo is not null && mrrCustomer.FinanceCreditMemo is null ) { await SendReport(mrrCustomer).ConfigureAwait(false); } // send to every body if ( id > 0 && mrrCustomer.MrrClosedTimestamp is not null && mrrCustomer.LogisticsReturnPo is not null && mrrCustomer.FinanceCreditMemo is not null ) { await SendReport(mrrCustomer).ConfigureAwait(false); } return(mrrCustomer); }