Note that there are some explanatory texts on larger screens.

plurals
  1. POGood repository pattern for asp.net mvc
    primarykey
    data
    text
    <p>I have implemented a repository pattern in my asp.net mvc web application... But i want to know is this a good repository pattern or still can i improve it more... </p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; using TaxiMVC.BusinessObjects; namespace TaxiMVC.Models { public class ClientRepository { private TaxiDataContext taxidb = new TaxiDataContext(); Client cli = new Client(); //Get all Clients public IQueryable&lt;ClientBO&gt; FindAllClients(int userId) { var client = from c in taxidb.Clients where c.CreatedBy == userId &amp;&amp; c.IsDeleted == 0 select new ClientBO() { ClientId = c.ClientId, ClientName= c.ClientName, ClientMobNo= Convert.ToString(c.ClientMobNo), ClientAddress= c.ClientAddress }; return client; } //Get Client By Id public ClientBO FindClientById(int userId,int clientId) { return (from c in taxidb.Clients where c.CreatedBy == userId &amp;&amp; c.ClientId == clientId &amp;&amp; c.IsDeleted == 0 select new ClientBO() { ClientId = c.ClientId, ClientName= c.ClientName, ClientMobNo= Convert.ToString(c.ClientMobNo), ClientAddress= c.ClientAddress }).FirstOrDefault(); } //Insert a new client public bool ClientInsert(ClientBO clientBO) { cli.ClientName = clientBO.ClientName; cli.ClientMobNo = Convert.ToInt64(clientBO.ClientMobNo); cli.ClientAddress = clientBO.ClientAddress; cli.CreatedDate = clientBO.CreatedDate; cli.IsDeleted = clientBO.IsDeleted; cli.CreatedBy = clientBO.CreatedBy; if (!taxidb.Clients.Where(c =&gt; c.ClientMobNo == cli.ClientMobNo).Any()) { taxidb.Clients.InsertOnSubmit(cli); taxidb.SubmitChanges(); return true; } else return false; } //Client Update public ClientBO updateClient(ClientBO clientBO) { var table = taxidb.GetTable&lt;Client&gt;(); var cli = table.SingleOrDefault(c =&gt; c.ClientId == clientBO.ClientId &amp;&amp; c.CreatedBy==clientBO.CreatedBy); cli.ClientName = clientBO.ClientName; cli.ClientMobNo = Convert.ToInt64(clientBO.ClientMobNo); cli.ClientAddress = clientBO.ClientAddress; taxidb.SubmitChanges(); return clientBO; } //Delete Clients public bool deleteClients(string Ids, int userId) { var idsToDelete = Ids.Split(',').Select(c =&gt; Convert.ToInt32(c)); var clientsToDelete = taxidb.Clients.Where(c =&gt; idsToDelete.Contains(c.ClientId)); foreach (var client in clientsToDelete) { client.IsDeleted = Convert.ToByte(1); } taxidb.SubmitChanges(); return true; } } } </code></pre> <p>and my ClientBo.cs,</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace TaxiMVC.BusinessObjects { public class ClientBO { public int ClientId { get; set; } public string ClientName { get; set; } public string ClientMobNo { get; set; } public string ClientAddress { get; set; } public DateTime CreatedDate { get; set; } public byte IsDeleted { get; set; } public int CreatedBy { get; set; } } } </code></pre> <p>I Didn't implement an IRepository here... Should i ve to implement it or should my repository can still be improved... Any suggestion....</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload