private StockCardViewModel AddStockcardItems(OrderDetailViewModel entity, tbl_PurchaseOrderDetail order) { return(new StockCardViewModel { dateRecieved = DateTime.Now, quantityRecieved = order.Quantity, //quantityRemaining = data.quantityRemaining, stockId = context.tbl_Stock.FirstOrDefault(s => s.ProductId == entity.productId).StockId, createdOn = DateTime.Now, //createdBy = order.CreatedBy, lastDateUpdated = DateTime.Now }); //Card.AddStockCarda(stockCard); }
public bool UpdatePurchaseOrder(PurchaseOrderViewModel entity) { var data = (from d in context.tbl_PurchaseOrder where d.PurchaseOrderId == entity.purchaseOrderId select d).SingleOrDefault(); if (data != null) { data.PurchaseOrderId = entity.purchaseOrderId; data.PurchaseOrderCode = entity.purchaseOrderCode; data.OrderedDate = entity.orderedDate; data.VendorId = entity.vendorId; data.IsActive = entity.isActive; data.ModifiedOn = DateTime.Now; data.ModifiedBy = "admin"; } ; var dDatails = context.tbl_PurchaseOrderDetail.Where(p => p.PurchaseOrderId == data.PurchaseOrderId); context.tbl_PurchaseOrderDetail.RemoveRange(dDatails); List <tbl_PurchaseOrderDetail> lstdetails = new List <tbl_PurchaseOrderDetail>();; foreach (var item in entity.details) { if (item.quantity > 0) { var details = new tbl_PurchaseOrderDetail { CostPrice = item.costPrice, Quantity = item.quantity, PurchaseOrderId = data.PurchaseOrderId, ProductId = item.productId, ModifiedBy = entity.createdBy, ModifiedOn = DateTime.Now, }; lstdetails.Add(details); } } context.tbl_PurchaseOrderDetail.AddRange(lstdetails); return(context.SaveChanges() > 0); }
private StockViewModel AddStockItems(OrderDetailViewModel entity, tbl_PurchaseOrderDetail order) { return(new StockViewModel { branchId = 14, supplyDate = DateTime.Now, productName = order.tbl_Product.ProductName, sellingPrice = (decimal)entity.sellingPrice, productId = order.ProductId, isSoldOut = false, isActive = true, costPerItem = order.CostPrice, quantitySupplied = entity.quantity, deliveryDate = DateTime.Now, createdBy = "admin", createdOn = DateTime.Now, purchaseOrderDetailId = order.PurchaseOrderDetailId, purchaseOrderId = order.PurchaseOrderId, stockCode = reference.ConfirmReferenceNo((int)ReferenceTypesEnum.Stock, 1) }); }
public PurchaseOrderViewModel AddPurchaseOrder(PurchaseOrderViewModel entity) { var data = new tbl_PurchaseOrder { PurchaseOrderId = entity.purchaseOrderId, PurchaseOrderCode = reference.ConfirmReferenceNo((int)ReferenceTypesEnum.PurchaseOrder, 1), OrderedDate = DateTime.Now, VendorId = entity.vendorId, IsActive = entity.isActive, CreatedOn = DateTime.Now, CreatedBy = "admin", ModifiedOn = DateTime.Now, ModifiedBy = "admin" }; context.tbl_PurchaseOrder.Add(data); List <tbl_PurchaseOrderDetail> lstdetails = new List <tbl_PurchaseOrderDetail>();; foreach (var item in entity.details) { if (item.quantity > 0) { var details = new tbl_PurchaseOrderDetail { CostPrice = item.costPrice, Quantity = item.quantity, PurchaseOrderId = data.PurchaseOrderId, ProductId = item.productId, ModifiedBy = entity.createdBy, ModifiedOn = DateTime.Now, PurchaseOrderDetailId = item.purchaseOrderDetailId, }; lstdetails.Add(details); } } context.tbl_PurchaseOrderDetail.AddRange(lstdetails); //foreach (var items in entity.details) //{ //var duplicate = context.tbl_PurchaseOrderDetail.Where(c => c.PurchaseOrderDetailId >= 1).SingleOrDefault(); //if (lstdetails != null) { // //var duplicate = from c in context.tbl_PurchaseOrderDetail // // join d in context.tbl_Stock on c.PurchaseOrderDetailId equals d.PurchaseOrderDetailId // // where c.PurchaseOrderDetailId == d.PurchaseOrderDetailId // // select new tbl_Stock // // { // // ProductId = c.ProductId, // // QuantitySupplied = c.Quantity, // // SellingPrice = c.CostPrice // // }; // //var duplicate = context.tbl_PurchaseOrderDetail.Where(c => c.PurchaseOrderDetailId >= 1).SingleOrDefault(); // var ven = new tbl_Stock // { // ProductId = duplicate.ProductId, // PurchaseOrderDetailId = duplicate.PurchaseOrderDetailId, // QuantitySupplied = duplicate.Quantity, // //SellingPrice // }; // context.tbl_Stock.Add(ven); //} ////} context.SaveChanges(); return(entity); }
private static OrderDetailViewModel SetOrderDetails(OrderDetailViewModel entity, tbl_PurchaseOrderDetail order) { var result = new OrderDetailViewModel { costPrice = order.CostPrice, sellingPrice = entity.sellingPrice, IsRecieved = order.IsRecieved, productId = order.ProductId, productName = order.tbl_Product.ProductName, purchaseOrderDetailId = order.PurchaseOrderDetailId, purchaseOrderId = order.PurchaseOrderId, quantity = order.Quantity, }; return(result); }