public void UpdatePart(ServiceDetailPartsPoco item) { using (var context = new eBikeContext()) { var ServicePart = context.ServiceDetailParts.Find(item.ServiceDetailPartID); var info = context.Parts.Find(item.PartID); var serviceDetail = context.ServiceDetails.Find(item.ServiceDetailID); if (serviceDetail.Status == "S") { info.QuantityOnHand += ServicePart.Quantity; if (item.Quantity <= info.QuantityOnHand) { ServicePart.Quantity = item.Quantity; info.QuantityOnHand -= item.Quantity; } else { throw new Exception("Not enough parts available"); } } else if (item.Quantity <= info.QuantityOnHand) { ServicePart.Quantity = item.Quantity; info.QuantityOnHand -= item.Quantity; } else { throw new Exception("Not enough parts available"); } context.SaveChanges(); } }
public void AddPart(ServiceDetailPartsPoco item) { using (var context = new eBikeContext()) { ServiceDetailPart newPart = new ServiceDetailPart(); var info = context.Parts.Find(item.PartID); var serviceDetail = context.ServiceDetails.Find(item.ServiceDetailID); if (info == null) { throw new Exception("No part matches that ID"); } newPart.PartID = item.PartID; newPart.ServiceDetailID = item.ServiceDetailID; if (item.Quantity <= info.QuantityOnHand && serviceDetail.Status == "S") { info.QuantityOnHand -= item.Quantity; newPart.Quantity = item.Quantity; } else if (item.Quantity <= info.QuantityOnHand) { newPart.Quantity = item.Quantity; } else { throw new Exception("Not enough parts available"); } newPart.SellingPrice = info.SellingPrice; context.ServiceDetailParts.Add(newPart); context.SaveChanges(); } }
public void DeletePart(ServiceDetailPartsPoco item) { DeletePart(item.PartID, item.ServiceDetailPartID); }