score:1
Accepted answer
[httppost]
public jsonresult checkforexistingreferral(referralviewmodel viewmodel)
{
bool haspreviousrequest = false;
var candidateid = user.identity.getuserid();
// do an outer join between the tables on referralid and select only a new anonymous type that has referrerid
// and status. if no record found in referralinstances then set status to empty.
var result = (from r in _context.referrals
join ri in _context.referralinstances on r.referralid equals ri.referralid into refsinst
where ((ri.candidateid == candidateid) &&
(ri.companyid == viewmodel.companyid) &&
(ri.skillid == viewmodel.skillid))
from rs in refsinst.defaultifempty()
select new {referenceequals = rs.referrerid, status = rs == null ? "":rs.referralstatus})
.tolist();
// this covers third condition
if(result.any(p => p.referrerid != null && p.status == "accepted"))
{
haspreviousrequest = false;
}
// this covers first and second conditions. if nothing found in referralinstances, the status will be empty
if(result.any() && result.all(p => p.status != "accepted"))
{
haspreviousrequest = true;
}
return json(new { haspreviousrequest = haspreviousrequest });
}
Source: stackoverflow.com
Related Query
- How to assign LINQ Query to a variable and then use it later in the code
- How can I check the number of calls to the database in LINQ query when using .NET Core and Code First?
- How to join two arrays in a LINQ query and use the result further in the query?
- How do I use the having clause on an aggregate in a complex group by and join query in LINQ
- How can I order the output of my long LINQ query by a double and then a string?
- How to execute a linq query for each item in a list , use it in the where clause and return a collection from the result of each query?
- How can I convert my LINQ query to use the lambda syntax and is there any advantage to doing this?
- How to use Linq and the IN clause
- Linq query, how to check for a null value and use the value 0 in place of a null?
- How can I write the following code more elegantly using LINQ query syntax?
- How to use expressions to build a LINQ query dynamically when using an interface to get the column name?
- How to use Linq to sort an array by Length and then value
- How to get the value of class properties with Linq query and IEnumerable
- How to: sum all values and assign a percentage of the total in Linq to sql
- LINQ Query How to select Max value between start and end index and the index of the max value
- how to use group by in linq C# and fetch the list of records
- How can I use LINQ and C# to find the oldest date from 3 different files?
- How to store a Linq query and use it later?
- How to use `let` keyword and select ValueTuple in the same LINQ query?
- How do you write a LINQ query that filters a sub table to a specific time period and sums the results of the sub table?
- How to get 0 out of a null linq query value when a condition isn't met and then set it to a ViewBag
- In a Linq Expression body how to use the value of a variable instead of a reference to it?
- How can i change this LINQ query to use my List<int> instead of the hard coded number?
- How to assign multiple LINQ Include() statements to a variable for code re-use?
- How to use a string variable in the linq where clause?
- How can I use a predicate in a crm sdk 2011 linq query when the query contains a join?
- How to dynamically query the database using LINQ and a variable?
- How to use linq to assign two lists and an int to create one list of a new object?
- How can I do a LINQ query joining two entities and select what a Where on one of the entities?
- How to LINQ query with variable where and select?
More Query from same tag
- Linq - Using GroupBy with my own type vs anonymous type
- How do I loop through a collection of LINQ to Entities collection?
- How to return array of data as return type in my linq query?
- How to write join query for two JObjects in mvc c#?
- How to find distinct values from a specific index of a generic list
- Error in downloading a file in ASP.NET MVC
- Lambda expression: Where clause for Include list
- How to Fetch Data By using Two Date Columns in PostgreSQL SQL?
- Is there a way to return different keySelectors to one OrderBy?
- LINQ Query is removing multiple rows instead of a single row
- LINQ perform select and insert in single query
- Linq expression with Join, and conditional OrderBy / OrderByDescending
- how retrieve the value from more than one list at a time using linQ?
- Problem getting XML elements in an SVG file
- Using Linq to do: Compile a list of all lists within a list of objects
- Dynamic Linq Core OrderBy Nullable Child Property
- In linq, how do I take specific parameter out of a list and build new list of different type?
- how to get single value by using entity framework
- IQueryable vs IEnumerable: is IQueryable always better and faster?
- IronPython entity framwork 6 Could not find attribute where
- Can“t read some XML files?
- LINQ returns arrays, not a collection of list object
- Why are my bound parameters all identical (using Linq)?
- Select first unique child
- vb.net removing items from listbox that are in another listbox
- Linq To Entity MVC
- How to avoid Iterator method being restarted?
- In MVC3 how to get a list of models with Linq?
- Handling hierarchical collection with Linq
- Checking if a non-list variable satisfies a predicate expression