简体   繁体   English

ASP.NET Core Linq

[英]ASP.NET Core Linq

There is a request for the following plan: 需要以下计划:

[HttpPost]
    public async Task<IActionResult> Ref(RefModel model)
    {
        var countreward = from c in db.Person
                            join g in db.Referal
                            on c.AccountID equals g.memb___id into gg
                            from ggg in gg.DefaultIfEmpty()

                            where ggg.referal_reward >= 1
                            where c.RCount >= 1


                            orderby c.AccountID == User.Identity.Name

                            select new Person()
                            {
                                AccountID = c.AccountID,
                                Name = c.Name,
                            };
        var reward = countreward.ToList();

        if (ModelState.IsValid)
        {
            if (reward.Count >= 1)
            {
                CSData bonus = db.CSData.First(p => p.AccountID == User.Identity.Name);
                bonus.GP+= 10 * reward.Count;

                db.CSData.Update(bonus);
                await db.SaveChangesAsync();

                ViewBag.Message = "Yes";
            }
            else
            {
                ViewBag.Message = "No";
            }
        }
        return View(model);
    }

After clicking on the button, I get all the referrals I need from the Referal table, compare their login to the required criteria with the Person table and after that I get + = 10 to my login. 单击按钮后,我从“推荐”表中获得了我需要的所有推荐,将他们的登录名与“人”表进行比较以符合所需条件,然后我的登录名获得+ = 10。 How do I send 5 points to those thanks to which I got 10 points? 我如何向那些获得10分的人发送5分? Thank you! 谢谢!

Right before await db.SaveChangesAsync(); 就在await db.SaveChangesAsync(); add: 加:

foreach(var person in reward)
{
    CSData bonus = db.CSData.First(p => p.AccountID == person.AccountID);
    bonus.GP += 5;

    db.CSData.Update(bonus);
}

You should really start studying by reading a book about the basics. 您应该真正通过阅读有关基础知识的书来开始学习。 You don't do yourself any favors when you get stuck on simple things like iterating a list. 当您停留在诸如迭代列表之类的简单事情上时,您不会有任何好处。 Before doing complicated things like accessing databases and communicating over a network, make sure you can do the basics. 在执行诸如访问数据库和通过网络进行通信之类的复杂操作之前,请确保您可以进行基础操作。 Learn to walk before you run. 跑步前学习走路。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM