Esempio n. 1
0
 public static void Restock(Int32 pzn, Int32 quantity, DateTime dateOfAction)
 {
     using (PharmacyContainer db = new PharmacyContainer())
     {
         Drug drug = GetDrug(pzn, db);
         drug.Apply(RestockEvent.Create(drug, quantity, dateOfAction));
         db.SaveChanges();
     }
 }
Esempio n. 2
0
 public static void InitiateReplenishment(Int32 pzn, int quantity, PharmacyContainer db)
 {
     Drug drug = DrugService.GetDrug(pzn, db);
     if (HasOpenOrders(drug, db))
     {
         AdjustExistingOrderFor(drug, quantity, db);
     }
     else
     {
         CreatePositionOnOpenOrNewOrder(drug, quantity, db);
     }
     db.SaveChanges();
 }
Esempio n. 3
0
 public static void Cancel(Int32 id)
 {
     using (PharmacyContainer db = new PharmacyContainer())
     {
         ReplenishmentOrder order = GetOrder(id, db);
         order.State = order.State.Cancel();
         foreach (Position p in order.Positions)
         {
             InitiateReplenishment(p.DrugPZN, p.Quantity, db);
         }
         // migrate all positions to new or existing open order
         db.SaveChanges();
     }
 }
Esempio n. 4
0
 public static void ProceedToNextState(Int32 id)
 {
     using (PharmacyContainer db = new PharmacyContainer())
     {
         ReplenishmentOrder order = GetOrder(id, db);
         order.State = order.State.Next();
         if (order.State == OrderState.Finished)
         {
             foreach (Position p in order.Positions)
             {
                 DrugService.Replenish(p.Drug.PZN, p.Quantity, order.ActualDelivery, db);
             }
         }
         db.SaveChanges();
     }
 }
Esempio n. 5
0
 public static void UpdateExpectedDeliveryDate(Int32 id, DateTime expectedDelivery)
 {
     using (PharmacyContainer db = new PharmacyContainer())
     {
         ReplenishmentOrder order = GetOrder(id, db);
         order.ExpectedDelivery = expectedDelivery;
         db.SaveChanges();
     }
 }
Esempio n. 6
0
        public static Drug UpdateDrug(Drug drug, String name, String description, int minimumInventoryLevel, int optimalInventoryLevel)
        {
            Util.ConvertEmptyToNull(ref description);

            using (PharmacyContainer db = new PharmacyContainer())
            {
                Drug attachedDrug = GetDrug(drug.PZN, db);
                attachedDrug.Name = name;
                attachedDrug.Description = description;
                attachedDrug.MinimumInventoryLevel = minimumInventoryLevel;
                attachedDrug.OptimalInventoryLevel = optimalInventoryLevel;
                db.SaveChanges();
                return attachedDrug;
            }
        }
Esempio n. 7
0
 public static void Replenish(Int32 pzn, Int32 quantity, DateTime? dateOfAction, PharmacyContainer db)
 {
     Drug drug = GetDrug(pzn, db);
     drug.Apply(ReplenishEvent.Create(drug, quantity, FailOnNull(dateOfAction)));
     db.SaveChanges();
 }
Esempio n. 8
0
 private static Drug CreateDrug(Drug newDrug)
 {
     using (PharmacyContainer db = new PharmacyContainer())
     {
         var count = (from d in db.DrugSet where d.PZN == newDrug.PZN select d).Count();
         if (count > 0)
             throw new ArgumentException(String.Format("Drug with PZN {0} already exists!", newDrug.PZN));
         db.DrugSet.Add(newDrug);
         db.SaveChanges();
         return newDrug;
     }
 }