Пример #1
0
 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();
     }
 }
Пример #2
0
        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();
            }
        }
Пример #3
0
 public void DeletePart(ServiceDetailPartsPoco item)
 {
     DeletePart(item.PartID, item.ServiceDetailPartID);
 }