PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, January 17, 2022

[FIXED] Laravel PHP compact function in .NET Core 3

 January 17, 2022     .net-core, c#, laravel, php     No comments   

Issue

Me and my clients want to move to .NET so I still didn't get it to return more than 1 vars/strings in .NET. How to return something like this in .NET?

    //Verdienst für Heute ausrechnen
    $clicksToCoinsToday = Click::whereIn('short_link_id', $short_link_id)->whereDate('created_at', $today)->sum('click_amount');

    //Verdienst für letzte 7 Tage ausrechnen
    $clicksToCoinsLast7Days = Click::whereIn('short_link_id', $short_link_id)->whereDate('created_at', '>=', $lastweek)->sum('click_amount');

    return view('dashboard.admin.nutzerProfil', compact('nutzerDaten', 'clicksToCoinsYesterday', 'clicksToCoinsToday', 'clicksToCoinsLast7Days', 'allCoins'));

In C#

    public ActionResult GetClicks(List<Click> clicks, string clicksCount)
    {
        clicks =  _context.Clicks.ToList();

        clicksCount = _context.Clicks.Count().ToString();

        return (clicks, clicksCount);
    }

I wanted to get Clicks to List and also count how many of them are in DB.


Solution

There are many ways to do this, I would recommend you should create a custom model representing the data needed for your view.

for example

public class ClicksViewModel
{
    public int ClicksCount{get;set;}
    public List<Clicks> Clicks{get;set;}
}

And then

return View(new ClicksViewModel(){ ClicksCount = clicksCount, Clicks = clicks });

In the view:

Model.ClicksCount;
Model.Clicks;


Answered By - Andy Song
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing