Click here to Skip to main content
13,901,617 members
Click here to Skip to main content
Articles » Web Development » ASP.NET » General » Downloads

Tagged as

Stats

242.4K views
10.4K downloads
239 bookmarked
Posted 17 Jan 2012
Licenced CPOL

Real time, Asynchronous Web Pages using jTable, SignalR and ASP.NET MVC

, 17 Jan 2012
Real time, asynchronous web pages using jTable, SignalR and ASP.NET MVC
jTableWithSignalR
jTableSampleDatabaseLayer
bin
Release
EntityFramework.dll
jTableSampleDatabaseLayer.dll
jTableSampleDatabaseLayer.pdb
Models
Properties
Repositories
Memory
Sessions
jTableWithSignalR
jTableWithSignalR.suo
bin
SignalR.dll
Content
themes
base
images
ui-bg_flat_0_aaaaaa_40x100.png
ui-bg_flat_75_ffffff_40x100.png
ui-bg_glass_55_fbf9ee_1x400.png
ui-bg_glass_65_ffffff_1x400.png
ui-bg_glass_75_dadada_1x400.png
ui-bg_glass_75_e6e6e6_1x400.png
ui-bg_glass_95_fef1ec_1x400.png
ui-bg_highlight-soft_75_cccccc_1x100.png
ui-icons_222222_256x240.png
ui-icons_2e83ff_256x240.png
ui-icons_454545_256x240.png
ui-icons_888888_256x240.png
ui-icons_cd0a0a_256x240.png
minified
images
ui-bg_flat_0_aaaaaa_40x100.png
ui-bg_flat_75_ffffff_40x100.png
ui-bg_glass_55_fbf9ee_1x400.png
ui-bg_glass_65_ffffff_1x400.png
ui-bg_glass_75_dadada_1x400.png
ui-bg_glass_75_e6e6e6_1x400.png
ui-bg_glass_95_fef1ec_1x400.png
ui-bg_highlight-soft_75_cccccc_1x100.png
ui-icons_222222_256x240.png
ui-icons_2e83ff_256x240.png
ui-icons_454545_256x240.png
ui-icons_888888_256x240.png
ui-icons_cd0a0a_256x240.png
redmond
images
ui-bg_flat_0_aaaaaa_40x100.png
ui-bg_flat_55_fbec88_40x100.png
ui-bg_glass_75_d0e5f5_1x400.png
ui-bg_glass_85_dfeffc_1x400.png
ui-bg_glass_95_fef1ec_1x400.png
ui-bg_gloss-wave_55_5c9ccc_500x100.png
ui-bg_inset-hard_100_f5f8f9_1x100.png
ui-bg_inset-hard_100_fcfdfd_1x100.png
ui-icons_217bc0_256x240.png
ui-icons_2e83ff_256x240.png
ui-icons_469bdd_256x240.png
ui-icons_6da8d5_256x240.png
ui-icons_cd0a0a_256x240.png
ui-icons_d8e7f3_256x240.png
ui-icons_f9bd01_256x240.png
Controllers
jTableWithSignalR.csproj.user
Models
Properties
Scripts
jtable
extensions
external
themes
empty
standard
blue
header-bg.gif
loading.gif
title-bg.png
close.png
column-asc.png
column-desc.png
column-sortable.png
delete.png
edit.png
green
header-bg.gif
loading.gif
title-bg.png
purple
loading.gif
red
header-bg.gif
loading.gif
title-bg.png
Views
Home
Shared
using System.Collections.Generic;
using System.Linq;
using Hik.JTable.Models;
using System;

namespace Hik.JTable.Repositories.Memory
{
    public class MemoryStudentRepository : IStudentRepository
    {
        private readonly MemoryDataSource _dataSource;

        public MemoryStudentRepository(MemoryDataSource dataSource)
        {
            _dataSource = dataSource;
        }

        public List<Student> GetAllStudents()
        {
            return _dataSource.Students.OrderBy(s => s.Name).ToList();
        }

        public List<Student> GetStudents(int startIndex, int count, string sorting)
        {
            IEnumerable<Student> query = _dataSource.Students;

            //Sorting
            //This ugly code is used just for demonstration.
            //Normally, Incoming sorting text can be directly appended to an SQL query.
            if (string.IsNullOrEmpty(sorting) || sorting.Equals("Name ASC"))
            {
                query = query.OrderBy(p => p.Name);
            }
            else if (sorting.Equals("Name DESC"))
            {
                query = query.OrderByDescending(p => p.Name);
            }
            else if (sorting.Equals("Gender ASC"))
            {
                query = query.OrderBy(p => p.Gender);
            }
            else if (sorting.Equals("Gender DESC"))
            {
                query = query.OrderByDescending(p => p.Gender);
            }
            else if (sorting.Equals("CityId ASC"))
            {
                query = query.OrderBy(p => p.CityId);
            }
            else if (sorting.Equals("CityId DESC"))
            {
                query = query.OrderByDescending(p => p.CityId);
            }
            else if (sorting.Equals("BirthDate ASC"))
            {
                query = query.OrderBy(p => p.BirthDate);
            }
            else if (sorting.Equals("BirthDate DESC"))
            {
                query = query.OrderByDescending(p => p.BirthDate);
            }
            else if (sorting.Equals("IsActive ASC"))
            {
                query = query.OrderBy(p => p.IsActive);
            }
            else if (sorting.Equals("IsActive DESC"))
            {
                query = query.OrderByDescending(p => p.IsActive);
            }
            else
            {
                query = query.OrderBy(p => p.Name); //Default!
            }

            return count > 0
                       ? query.Skip(startIndex).Take(count).ToList() //Paging
                       : query.ToList(); //No paging
        }

        public List<Student> GetStudentsByFilter(string name, int cityId, int startIndex, int count, string sorting)
        {
            IEnumerable<Student> query = _dataSource.Students;

            //Filters
            if (!string.IsNullOrEmpty(name))
            {
                query = query.Where(p => p.Name.IndexOf(name, StringComparison.OrdinalIgnoreCase) >= 0);
            }

            if (cityId > 0)
            {
                query = query.Where(p => p.CityId == cityId);
            }

            //Sorting
            //This ugly code is used just for demonstration.
            //Normally, Incoming sorting text can be directly appended to an SQL query.
            if (string.IsNullOrEmpty(sorting) || sorting.Equals("Name ASC"))
            {
                query = query.OrderBy(p => p.Name);
            }
            else if (sorting.Equals("Name DESC"))
            {
                query = query.OrderByDescending(p => p.Name);
            }
            else if (sorting.Equals("Gender ASC"))
            {
                query = query.OrderBy(p => p.Gender);
            }
            else if (sorting.Equals("Gender DESC"))
            {
                query = query.OrderByDescending(p => p.Gender);
            }
            else if (sorting.Equals("CityId ASC"))
            {
                query = query.OrderBy(p => p.CityId);
            }
            else if (sorting.Equals("CityId DESC"))
            {
                query = query.OrderByDescending(p => p.CityId);
            }
            else if (sorting.Equals("BirthDate ASC"))
            {
                query = query.OrderBy(p => p.BirthDate);
            }
            else if (sorting.Equals("BirthDate DESC"))
            {
                query = query.OrderByDescending(p => p.BirthDate);
            }
            else if (sorting.Equals("IsActive ASC"))
            {
                query = query.OrderBy(p => p.IsActive);
            }
            else if (sorting.Equals("IsActive DESC"))
            {
                query = query.OrderByDescending(p => p.IsActive);
            }
            else
            {
                query = query.OrderBy(p => p.Name); //Default!
            }

            return count > 0
                       ? query.Skip(startIndex).Take(count).ToList() //Paging
                       : query.ToList(); //No paging
        }

        public Student AddStudent(Student student)
        {
            student.StudentId = _dataSource.Students.Count > 0
                                    ? (_dataSource.Students[_dataSource.Students.Count - 1].StudentId + 1)
                                    : 1;
            _dataSource.Students.Add(student);
            return student;
        }

        public void UpdateStudent(Student student)
        {
            var foundStudent = _dataSource.Students.FirstOrDefault(s => s.StudentId == student.StudentId);
            if (foundStudent == null)
            {
                return;
            }

            foundStudent.Name = student.Name;
            foundStudent.EmailAddress = student.EmailAddress;
            foundStudent.Password = student.Password;
            foundStudent.Gender = student.Gender;
            foundStudent.BirthDate = student.BirthDate;
            foundStudent.CityId = student.CityId;
            foundStudent.About = student.About;
            foundStudent.Education = student.Education;
            foundStudent.IsActive = student.IsActive;
        }

        public void DeleteStudent(int studentId)
        {
            _dataSource.Students.RemoveAll(s => s.StudentId == studentId);
        }

        public int GetStudentCount()
        {
            return _dataSource.Students.Count;
        }


        public int GetStudentCountByFilter(string name, int cityId)
        {
            IEnumerable<Student> query = _dataSource.Students;

            //Filters
            if (!string.IsNullOrEmpty(name))
            {
                query = query.Where(p => p.Name.IndexOf(name, StringComparison.OrdinalIgnoreCase) >= 0);
            }

            if (cityId > 0)
            {
                query = query.Where(p => p.CityId == cityId);
            }

            return query.Count();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Halil ibrahim Kalkan
Founder Volosoft
Turkey Turkey
I have started programming at 14 years old using Pascal as hobby. Then I interested in web development (HTML, JavaScript, ASP...) before university.

I graduated from Sakarya University Computer Engineering. At university, I learned C++, Visual Basic.NET, C#, ASP.NET and Java. I partly implemented ARP, IP and TCP protocols in Java as my final term project.

Now, I am working on Windows and web based software development mostly using Microsoft technologies in my own company.

My open source projects:

* ASP.NET Boilerplate: http://aspnetboilerplate.com
* jTable: http://jtable.org
* Others: https://github.com/hikalkan

My personal web site:

http://www.halilibrahimkalkan.com

You may also be interested in...

Pro
Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01 | 2.8.190306.1 | Last Updated 17 Jan 2012
Article Copyright 2012 by Halil ibrahim Kalkan
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid