private void Button_ok_Click(object sender, EventArgs e) { //TODO validation SuppToProdViewModel sp = new SuppToProdViewModel(); sp.Product = combobox_product.SelectedItem.ToString(); sp.Supplier = combobox_supplier.SelectedItem.ToString(); sp.Id = _sp.Id; _suppProdService.Create(sp); MessageBox.Show( "Order was added successully!", "OK", MessageBoxButtons.OK, MessageBoxIcon.Information); return; }
public bool Create(SuppToProdViewModel model) { try { SupplierToProduct suppToProd = _mapper.Map <SuppToProdViewModel, SupplierToProduct>(model); Product prod = _unitOfWork.ProductsRepository.Get(new ProductFilter() { Name = model.Product }); SupplierToProduct sup = _unitOfWork.SuppToProdRepository.Get(new SupplierToProductFilter() { ProductId = prod.Id }); sup.SupplierId = _unitOfWork.SuppliersRepository.Get(new SupplierFilter() { Name = model.Supplier }).Id; sup.ProductId = _unitOfWork.ProductsRepository.Get(new ProductFilter() { Name = model.Product }).Id; //sup.ProductId = suppToProd.ProductId; //sup.SupplierId = suppToProd.SupplierId; //_suppToProdDTO.Supplier = _unitOfWork.SuppliersRepository.Get(new SupplierFilter() { Id = suppToProd.SupplierId }); //_suppToProdDTO.Product = _unitOfWork.ProductsRepository.Get(new ProductFilter() { Id = suppToProd.ProductId _unitOfWork.SuppToProdRepository.Update(sup, new SupplierToProductFilter() { Id = sup.Id }); } catch { return(false); } return(true); }
public bool Update(SuppToProdViewModel model) { try { SupplierToProduct suppToProd = _mapper.Map <SuppToProdViewModel, SupplierToProduct>(model); SupplierToProduct sup = _unitOfWork.SuppToProdRepository.Get(new SupplierToProductFilter() { Id = model.Id }); suppToProd.SupplierId = sup.ProductId; //_unitOfWork.UsersRepository.Get(new UserFilter() { Email = model.User }).Id; suppToProd.ProductId = sup.SupplierId; _unitOfWork.SuppToProdRepository.Update(suppToProd, new SupplierToProductFilter() { Id = suppToProd.Id }); } catch { return(false); } return(true); }