public async Task <IActionResult> Create([Bind("Id,ProductId,CustomerId,Quantity,Timestamp")] Order order) { var check = new OrderLogic(); var products = new ProductRepo(); if (ModelState.IsValid && check.IsWithinInventory(products.GetInventory(_context, order.ProductId), order.Quantity)) { try { products.UpdateInventory(_context, order.ProductId, order.Quantity); _context.Add(order); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { _logger.LogInformation(ex, "Something in the order wasn't able to be added"); } } ViewData["CustomerId"] = new SelectList(_context.Customers, "Id", "UserName"); var repo = new OrderRepo(); ViewData["ProductInfo"] = repo.ProductList(_context); return(View(order)); }
public async Task <IActionResult> Create([Bind("PermissionID,Title,Description")] Permission permission) { if (ModelState.IsValid) { _context.Add(permission); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(permission)); }
public async Task <Producto> AgregarProducto(Producto producto) { _context.Producto.Add(producto); await _context.SaveChangesAsync(); return(producto); }
public async Task <bool> ActualizarExistencia(Existencia exsitencia, Movimiento movimiento) { _context.Existencia.Where(f => f.IdProducto == exsitencia.IdProducto && f.IdSucursal == exsitencia.IdSucursal).FirstOrDefault().Cantidad = exsitencia.Cantidad; _context.Movimiento.Add(movimiento); // actualizar movimientos return(await _context.SaveChangesAsync() >= 0); }
public async Task <SucursalDto> AgregarTienda(SucursalDto sucursal) { var NewStore = new Sucursal() { Id = Guid.Empty, Nombre = sucursal.Nombre }; var store = _context.Sucursal.Add(NewStore); await _context.SaveChangesAsync(); return(_mapper.Map <Sucursal, SucursalDto>(NewStore)); }
public async Task <IActionResult> Create([Bind("Name,Address,Nationality")] User user, string[] selectedPermissions) { if (selectedPermissions != null) { user.UserPermissions = new List <UserPermission>(); foreach (var perm in selectedPermissions) { var permissionToAdd = new UserPermission { UserID = user.ID, PermissionID = int.Parse(perm) }; user.UserPermissions.Add(permissionToAdd); } } if (ModelState.IsValid) { _context.Add(user); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } PopulateUserPermissionData(user); return(View(user)); }
public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,UserName,Password")] Customer customer) { if (ModelState.IsValid) { try { _context.Add(customer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { _logger.LogInformation(ex, "Wasn't able to create the customer."); } } return(View(customer)); }