public bool CheckIsCatagoryInUse(Catagory catagory)
 {
     IArtistDao dao = DALFactory.CreateArtistDao(database);
     if(dao.findByProperty(typeof(Artist).GetProperty("Catagory"), catagory).Count() > 0)
     {
         return true;
     }
     return false;
 }
Пример #2
0
 private static void CreateCatagories()
 {
     Console.WriteLine("Insert Catagories ");
     ICatagoryDao catagoryDao = DALFactory.CreateCatagoryDao(DALFactory.CreateDatabase());
     for (int i = 1; i <= 10; i++)
     {
         Catagory c = new Catagory();
         c.Name = "Catagory " + i;
         c.Description = "Catagory Description for " + i;
         catagoryDao.Insert(c);
     }
 }
        public void TestInsert()
        {
            Catagory cat = new Catagory();
            cat.Name = "UNIT-TEST";
            cat.Description = "asdf";

            ICatagoryDao dao = DALFactory.CreateCatagoryDao(DALFactory.CreateDatabase());
            dao.Insert(cat);
            PropertyInfo info = typeof(Catagory).GetProperty("Name");
            Catagory result = dao.findByUniqueProperty(info, "UNIT-TEST");
            Assert.AreEqual(result.Name, cat.Name);
            Assert.AreEqual(result.Description, cat.Description);
        }
Пример #4
0
        public CatagoryVM(Catagory cat, IAdministrationServices service)
        {
            catagory = cat;
            this.service = service;
            SaveCommand = new RelayCommand((c) =>
            {
                if (!Validator.ValidateAll().IsValid)
                {
                    return;
                }
                catagory = service.SaveCatagory(catagory);
                if (catagory != null && catagory.Id > 0)
                {
                    AppMessages.CatagoryChanged.Send(AppMessages.ChangeType.Change);
                    AppMessages.ShowSuccessMessage.Send($"Catagory {catagory.Name} saved");
                    return;
                }
                AppMessages.ShowErrorMessage.Send($"Error while saving Catagory {catagory.Name}");
            });
            DeleteCommand = new RelayCommand((c) =>
            {

                    try {
                        if (service.DelteCatagory(catagory))
                        {
                            AppMessages.CatagoryChanged.Send(AppMessages.ChangeType.Remove);
                            AppMessages.ShowSuccessMessage.Send($"Catagory {catagory.Name} removed");
                            return;
                        }

                    }catch(ElementInUseException e)
                    {
                        AppMessages.ShowErrorMessage.Send(e.Message);
                        return;
                    }
                    AppMessages.ShowErrorMessage.Send($"Error while removing Catagory {catagory.Name}");

            });
            ApplyValidationRules();
        }
 public Catagory SaveCatagory(Catagory catagory)
 {
     ICatagoryDao dao = DALFactory.CreateCatagoryDao(database);
     if(catagory.Id != null && catagory.Id > 0)
     {
         dao.Update(catagory);
         return catagory;
     }
     catagory = dao.Insert(catagory);
     return catagory;
 }
 public bool DelteCatagory(Catagory catagory)
 {
     ICatagoryDao dao = DALFactory.CreateCatagoryDao(database);
     if (this.CheckIsCatagoryInUse(catagory))
     {
         throw new ElementInUseException($"Can't delete catagory {catagory.Name}. Catagory is assigned");
     }
     return dao.Delete(catagory);
 }