public async Task <ActionResult <Employees> > PostEmployees(Employees employees) { try { employees.User.Password = encrypt.EncryptData(employees.User.Password, "ffhhgfgh"); _context.Users.Add(employees.User); await _context.SaveChangesAsync(); employees.UserId = _context.Users.Where(u => u.Username == employees.User.Username).Select(a => a.UserId).FirstOrDefault(); _context.Employees.Add(employees); await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (EmployeesExists(employees.EmployeeId)) { return(Conflict()); } else { throw; } } return(CreatedAtAction("GetEmployees", new { id = employees.EmployeeId }, employees)); }
public async Task <ActionResult <LogSingleton> > PostLogSingleton(LogSingleton logSingleton) { _context.LogSingleton.Add(logSingleton); await _context.SaveChangesAsync(); return(CreatedAtAction("GetLogSingleton", new { id = logSingleton.LogId }, logSingleton)); }
public async Task <ActionResult <Customers> > PostCustomer(Customers customer) { try { customer.User.Password = encrypt.EncryptData(customer.User.Password, "ffhhgfgh"); _context.Users.Add(customer.User); await _context.SaveChangesAsync(); customer.UserId = _context.Users.Where(u => u.Username == customer.User.Username).Select(a => a.UserId).FirstOrDefault(); _context.Customers.Add(customer); await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (CustomerExists(customer.CustomerId)) { return(Conflict()); } else { throw; } } return(CreatedAtAction("GetCustomer", new { id = customer.CustomerId }, customer)); }
public async Task <ActionResult <Product> > PostProduct(Product product) { product.IsActive = true; _context.Product.Add(product); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (ProductExists(product.ProductId)) { return(Conflict()); } else { throw; } } return(CreatedAtAction("GetProduct", new { id = product.ProductId }, product)); }
public async Task <ActionResult <Sale> > PostSale(Sale sale) { sale.Product = _context.Product.Where(p => p.ProductId == sale.ProductId).SingleOrDefault(); sale.User = _context.Users.Where(u => u.UserId == sale.UserId).SingleOrDefault(); _context.Sale.Add(sale); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (SaleExists(sale.SaleId)) { return(Conflict()); } else { throw; } } LogSingleton log = new LogSingleton(); LogSingletonsController logController = new LogSingletonsController(_context); log.LogDate = DateTime.Now; log.LogType = "Sale Completed"; log.Product = sale.Product; log.ProductId = sale.ProductId; log.Quantity = sale.Quantity; log.User = sale.User; log.UserId = sale.UserId; await logController.PostLogSingleton(log); return(CreatedAtAction("GetSale", new { id = sale.SaleId }, sale)); }