Reference:
Dynamic menu:
http://www.c-sharpcorner.com/UploadFile/4e2862/dynamically-creating-menus-and-submenus-items-to-web-forms/
IRepository.cs
bootstrap Top menu
Shopping cart -
http://elite4share.net/docs/Shopping%20Cart%20Example%20Code%20In%20ASP.NET%20C%23%20VB.pdfDynamic menu:
http://www.c-sharpcorner.com/UploadFile/4e2862/dynamically-creating-menus-and-submenus-items-to-web-forms/
IRepository.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ismapac.hirushan.dataaccess
{
public interface IRepository where T : class
{
IEnumerable GetAll(Func predicate = null);
T Get(Func predicate);
void Add(T entity);
void Attach(T entity);
void Delete(T entity);
}
}
GenericUOW.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ismapac.hirushan.dataaccess
{
public class GenericUnitOfWork : IDisposable
{
private DatabaseEntities entities = null;
public GenericUnitOfWork()
{
entities = new DatabaseEntities();
}
public Dictionary repositories = new Dictionary();
public IRepository Repository() where T : class
{
if (repositories.Keys.Contains( typeof(T)) == true)
{
return repositories[typeof(T)] as IRepository;
}
IRepository repo = new GenericRepository(entities) ;
repositories.Add(typeof(T), repo);
return repo;
}
public void SaveChanges()
{
entities.SaveChanges();
}
private bool disposed = false;
protected virtual void Dispose(bool disposing)
{
if (!this.disposed)
{
if (disposing)
{
entities.Dispose();
}
}
this.disposed = true;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
}
}
GenericRepository.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Entity;
using System.Text;
using System.Threading.Tasks;
namespace ismapac.hirushan.dataaccess
{
class GenericRepository : IRepository where T : class
{
private DatabaseEntities entities = null;
IDbSet _objectSet;
public GenericRepository( DatabaseEntities _entities)
{
entities = _entities;
_objectSet = entities.Set();
}
public IEnumerable GetAll(Func predicate = null)
{
if (predicate != null)
{
return _objectSet.Where(predicate);
}
return _objectSet.AsEnumerable();
}
public T Get(Func predicate)
{
return _objectSet.First(predicate);
}
public void Add(T entity)
{
_objectSet.Add(entity);
}
public void Attach(T entity)
{
_objectSet.Attach(entity);
}
public void Delete(T entity)
{
_objectSet.Remove(entity);
}
}
}
0 Responses so far.
Post a Comment