simsenVejle
Well-known member
- Joined
- Feb 14, 2021
- Messages
- 46
- Programming Experience
- Beginner
Hi,
I am starting on a solution, with several projects. ViewModel, Model, Views, DAL and the UI project.
In ViewModel I have made a folder called it Account and the cs file called CategoriViewModel.cs - In this I have a method called LoadCategories. Here I want to get to the DAL layer.
I have made a project reference to the DAL. In the CategoriViewModel.cs file I have made a using DAL.Account;
then in LoadCategories I want to go through DalCategory to get to the method GetCategories by writing DalCategory.GetCategories - vs accept the DalCategory but not the method. When writing the dot I only get to choose between Equals and ReferenceEquals. I have double checked that the GetCategories is public. And it is. Now I do not know what to do - I hope one of you can help me explaining what to do.
Best regards
Simsen
I am starting on a solution, with several projects. ViewModel, Model, Views, DAL and the UI project.
In ViewModel I have made a folder called it Account and the cs file called CategoriViewModel.cs - In this I have a method called LoadCategories. Here I want to get to the DAL layer.
I have made a project reference to the DAL. In the CategoriViewModel.cs file I have made a using DAL.Account;
then in LoadCategories I want to go through DalCategory to get to the method GetCategories by writing DalCategory.GetCategories - vs accept the DalCategory but not the method. When writing the dot I only get to choose between Equals and ReferenceEquals. I have double checked that the GetCategories is public. And it is. Now I do not know what to do - I hope one of you can help me explaining what to do.
Best regards
Simsen
DalCategory.cs:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Model.Account;
using System.ComponentModel;
using Dapper;
using System.Linq;
namespace DAL.Account
{
public class DalCategory
{
#region Get
public List<CategoryModel> GetCategories()
{
try
{
using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Helper.Conn()))
{
var output = connection.Query<CategoryModel>("dbo.Category_GetAll").ToList();
return output;
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
public void GetTest()
{
var test = "Test of methods";
}
#endregion
#region Insert
#endregion
#region Update
#endregion
#region Delte
#endregion
#region PropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
private void RaisePropertyChanged(string property)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
}
#endregion
}
}
CategoryViewModel:
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.ObjectModel;
using Model.Account;
using DAL.Account;
namespace ViewModel.Account
{
public class CategoryViewModel
{
private Category _selectedCategory;
public MyICommand DeleteCommand { get; set; }
public Category SelectedCategory
{
get
{
return _selectedCategory;
}
set
{
_selectedCategory = value;
DeleteCommand.RaiseCanExecuteChanged();
}
}
public CategoryViewModel()
{
LoadCategories();
DeleteCommand = new MyICommand(OnDelete, CanDelete);
}
public ObservableCollection<Category> Categories { get; set; }
public void LoadCategories()
{
var output = new List<CategoryModel>();
ObservableCollection<Category> categories = new ObservableCollection<Category>
{
//Here I try to write
DalCategory.GetCategories.
};
Categories = categories;
}
#region Delete
private void OnDelete()
{
Categories.Remove(SelectedCategory);
}
private bool CanDelete()
{
return SelectedCategory != null;
}
#endregion
}
}