TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
محمد صلاح الدين
NA
75
3.7k
How to sum values from a table in column in mvc5
Dec 30 2018 1:35 PM
hi guys i am trying to sum all values from my table in 2 column how can i do this here example image for my question i wont sum boys and sum girls
here is the code what should i do
public
ActionResult ShowPation()
{
var query1 = from t
in
db.Pations.Include(b => b.Type_Services).ToList()
let Agerange =
(
t.Age >= 0 && t.Age < 1 ?
"Age Under 1 year"
:
t.Age >= 1 && t.Age < 5 ?
"Age from 1 to 4"
:
t.Age >= 5 && t.Age < 15 ?
"Age from 5 to 14"
:
t.Age >= 15 && t.Age < 25 ?
"Age from 15 to 24"
:
t.Age >= 25 && t.Age < 45 ?
"Age from 25 to 46"
:
"age over 47+"
)
let Sex = (t.Sex == 0 ?
"boys"
:
"girls"
)
let Type_S = t.Type_Services.NameService
group
new
{ t.Age, t.Sex, Agerange } by
new
{ t.DateWared.Year, t.DateWared.Month, Agerange,Sex,t.Type_Services.NameService } into g
select g;
var query2 = from g
in
query1
select
new
{ mycount = g.Count(), g.Key.Year, g.Key.Month, g.Key.Agerange,g.Key.Sex ,g.Key.NameService,};
var query3 = from i
in
query2
group i by
new
{ i.Year, i.Month ,i.NameService} into g
select g;
Dictionary> urn =
new
Dictionary>();
foreach
(var item
in
query3)
{
foreach
(var item1
in
item)
{
if
(!urn.ContainsKey(item.Key.Month +
"/"
+ item.Key.Year+ item.Key.NameService))
{
urn[item.Key.Month +
"/"
+ item.Key.Year + item.Key.NameService] =
new
List();
}
urn[item.Key.Month +
"/"
+ item.Key.Year+ item.Key.NameService].Add(
new
UserRange { Count = item1.mycount, AgeRange = item1.Agerange,Gender=item1.Sex});
}
urn[item.Key.Month +
"/"
+ item.Key.Year+ item.Key.NameService] = urn[item.Key.Month +
"/"
+ item.Key.Year+ item.Key.NameService].OrderByDescending(i => i.AgeRange).ToList();
//sort the data according to Agerange
}
return
View(urn);
}
Reply
Answers (
1
)
I wanted to send email of cshtml list data using asp.net MVC
I need to remove sessions in my project