/// <summary>
        /// Updates the mapping between medicines and groups
        /// Removes the existing mappings and then adds these new ones
        /// Maps the passed groups for a given medicine
        /// </summary>
        /// <param name="Groups">Groups to be mapped against a medicine</param>
        /// <param name="medicine">Medicine to be mapped</param>
        public static void UpdateGroupsOfMedicine(IList<Group> groups, Medicine medicine)
        {
            db.MedicinesGroups.DeleteAllOnSubmit(medicine.GroupsIds);

            List<Medicine_Group> medicine_groups = new List<Medicine_Group>(groups.Count);
            foreach (var group in groups)
                medicine_groups.Add(new Medicine_Group() { GroupId = group.Id, MedicineId = medicine.Id });
            medicine.GroupsIds.Clear();
            medicine.GroupsIds.AddRange(medicine_groups);
        }
 /// <summary>
 /// Gets the existing connection if any for DB
 /// Creates an empty Medicine instance
 /// Used for creating a new medicine as we do not have any ID for it yet
 /// </summary>
 public MedicineViewModel()
 {
     db = App.ViewModel.db;
     db.Refresh(RefreshMode.OverwriteCurrentValues, db.Medicines); // Clear any unsaved changes
     Medicine = new Medicine();
 }
 public ReminderFactory(Medicine _medicine)
 {
     medicine = _medicine;
 }
        /// <summary>
        /// Inserts sample data into the database
        /// </summary>
        /// <param name="db">Database context to use</param>
        private void InsertSampleData(MedicineContext db)
        {
            // Sample Medicines
            Medicine m1 = new Medicine()
            {
                Name = "saridon (sample)",
                MfgDate = DateTime.Now,
                ExpDate = DateTime.Now.AddMonths(3),
                CureFor = "Headache",
                Dosage = "4",
                DosageType = "cups",
                AgeGroup = "18+",
                Price = 20.50F,
                BoughtAddress = "Near Canara bank, Kormangala, Bangalore. Ph: 080-23399239",
                Quantity = 2,
                QuantityType = "pills",
                CreatedAt = DateTime.Now,
                UpdatedAt = DateTime.Now
            };
            db.Medicines.InsertOnSubmit(m1);

            Medicine m2 = new Medicine()
            {
                Name = "nice (sample)",
                MfgDate = DateTime.Now,
                ExpDate = DateTime.Now.AddMonths(3),
                IsUsing = true,
                CureFor = "Fever",
                Dosage = "3",
                DosageType = "spoons",
                AgeGroup = "20+",
                Price = 25.50F,
                BoughtAddress = "Indiranagar, Bangalore. Ph: 080-23399239",
                Quantity = 4,
                QuantityType = "pills",
                CreatedAt = DateTime.Now,
                UpdatedAt = DateTime.Now
            };
            db.Medicines.InsertOnSubmit(m2);

            db.SubmitChanges();

            // Sample Groups
            Group g1 = new Group()
            {
                Name = "Is Using (sample)",
                CreatedAt = DateTime.Now,
                UpdatedAt = DateTime.Now
            };
            db.Groups.InsertOnSubmit(g1);

            Group g2 = new Group()
            {
                Name = "Not Using (sample)",
                CreatedAt = DateTime.Now,
                UpdatedAt = DateTime.Now
            };
            db.Groups.InsertOnSubmit(g2);

            db.SubmitChanges();

            // Sample Associations
            db.MedicinesGroups.InsertOnSubmit(new Medicine_Group()
            {
                Medicine = m1,
                Group = g1
            });

            db.MedicinesGroups.InsertOnSubmit(new Medicine_Group()
            {
                Medicine = m2,
                Group = g2
            });

            db.SubmitChanges();
        }