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 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();
 }