As I a reward to the total value of each user from the database?

I wants to count the total leaves of each users from the database.
and wants to display it in telerik gridview in Asp.Net MVC-3 (Aspx).

i have a gridview with two columns. first column displays the names of all the employees/users and 2nd column will display the total leaves of that users.

my database is as below

leave_master

leave_id (primary key)
user_id (foreign key with user_id of table user_master)
leave_days

user_master

user_id (primary key)
user_real_name

My Model files are as below

name – LeaveGridview.cs

<pre>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;

namespace ProjectManagementSystem.Models
{
    public class LeaveGridview
    {

        public int user_id { get; set; }

        public string user_name { get; set; }

        public string user_real_name { get; set; }    

        public int leave_id { get; set; }

        public decimal leave_days { get; set; }

    }
}
</pre>

2nd file

name – LeaveGridviewFetch.cs

<pre>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ProjectManagementSystem.Models
{

    public class LeaveGridviewFetch
    {

        public static IList&lt;LeaveGridview&gt; all()
        {
            IList&lt;LeaveGridview&gt; result =
                (IList&lt;LeaveGridview&gt;)HttpContext.Current.Session["leave1"];

            if (result == null)
            {

                HttpContext.Current.Session["leave1"] = result =
                    (from l in new ProjectManagementSystemEntities3().leave_master
                     select new LeaveGridview
                     {
                         user_id = l.user_id,
                         leave_id = l.leave_id,
                         user_real_name = l.user_master.user_real_name,

                     }).ToList();

            }
            return result;
        }
    }
}
</pre>

My contgroller file
name LeaveController.cs

<pre>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ProjectManagementSystem.Models;
using Telerik.Web.Mvc;

namespace LeaveModule.Controllers
{
    public class LeaveController : Controller
    {
        public ProjectManagementSystemEntities3 pb = new ProjectManagementSystemEntities3();

  public ActionResult LeaveShow()
        {
            var leave_master = pb.leave_master.Include("user_master");
            ViewBag.leave_id = new SelectList(pb.user_master, "user_id", "user_real_name");
            return View(leave_master.ToList());
        }

 [GridAction]
        public ActionResult _SelectBatchEditing()
        {
            return View(new GridModel(LeaveGridviewFetch.all()));
        }

}
}

</pre>

my view is

name LeaveShow.ascx

<pre>

&lt;%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %&gt;

&lt;asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"&gt;
    LeaveShow
&lt;/asp:Content&gt;

&lt;asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"&gt;

&lt;%  Html.Telerik().Grid&lt;ProjectManagementSystem.Models.LeaveGridview&gt;()
                       .Name("grid")
                       .DataKeys(keys =&gt;
                       {
                           keys.Add(l =&gt; l.leave_id);
                       })

                       .DataBinding(dataBinding =&gt;
                        dataBinding.Ajax()
                       .Select("_SelectBatchEditing", "Leave") // Leave is controller name
                       )

                        .Columns(columns =&gt;
                       {

                           columns.Bound(l =&gt; l.user_real_name).Width(200); 

                           columns.Bound(l =&gt; l.leave_days).Width(150);

                       })

                       .Groupable()
                       .Pageable()
                       .Filterable()
                       .Render();

                       %&gt;

&lt;/asp:Content&gt;

</pre>

i wanna output like

name—————total_ leaves

abc—————- 10

xyz—————- 12

pqr—————- 06

So how can i do that?

Thanks in advance…

This entry was posted in Codes & Scripts and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>