Пример #1
0
 internal void AddNewMedicine()
 {
     if (DisountType == "FixedAmountDiscount")
     {
         Discount = new FixedAmountDiscount {
             Amount = AmountOrPercentage
         };
     }
     else
     {
         Discount = new PercentageDiscount {
             Amount = AmountOrPercentage
         };
     }
     if (Url == null)
     {
         Url = "no-image.png";
     }
     try
     {
         var medicine = new Medicine
         {
             Name        = Name,
             Description = Description,
             Image       = new MedicineImage {
                 Url = Url
             },
             Price         = Price,
             PriceDiscount = Discount
         };
         _medicineService.AddANewMedicine(medicine);
         foreach (string s in CategoriesId)
         {
             int CatId = Convert.ToInt32(s);
             _medicineService.AddMedicineCategory(CatId, medicine);
         }
         Notification = new NotificationModel("Success!",
                                              "Category added successfully.",
                                              Notificationtype.Success);
     }
     catch (InvalidOperationException iex)
     {
         Notification = new NotificationModel("Failed!",
                                              "Failed to add category, please provide valid name.",
                                              Notificationtype.Fail);
     }
 }
Пример #2
0
 internal void EditMedicine()
 {
     if (DisountType == "FixedAmountDiscount")
     {
         Discount = new FixedAmountDiscount {
             Amount = AmountOrPercentage
         };
     }
     else
     {
         Discount = new PercentageDiscount {
             Amount = AmountOrPercentage
         };
     }
     try
     {
         _medicineService.EditMedicine(new Medicine
         {
             Id          = Id,
             Name        = Name,
             Description = Description,
             Image       = new MedicineImage {
                 Url = Url
             },
             Price         = Price,
             PriceDiscount = Discount
         });
         Notification = new NotificationModel("Success!",
                                              "Medicine edited successfully.",
                                              Notificationtype.Success);
     }
     catch (InvalidOperationException iex)
     {
         Notification = new NotificationModel("Failed!",
                                              "Failed to edit medicine, please provide valid name.",
                                              Notificationtype.Fail);
     }
 }