Move channel from Category 1 to Category 2 with roles - discord.js

how do i make the channel move category using roles?
example:
Category 1 (roles 1)
My Channel
Category 2 (roles 2)

as people have pointed out in the comments, this is a really bad question, as stack overflow is for help with issues, not help for writing code. Also try to make your question more descriptive, what have you tried, etc.
It's hard to tell exactly what you mean since the question's less than 20 words long, but moving a channel inside a category should be done like this:
let category = server.channels.cache.find(c => c.name == "My Category" && c.type == "category"),
channel = server.channels.cache.find(c => c.name == "text-channel" && c.type == "text");
if (category && channel) channel.setParent(category.id);

Related

Watson Assistant - How to get size of specific entities

For example I have 3 different entities
#action = eat,run,walk
#person = Michael, John, Fred
#emotion = angry,sad,happy
I want to count user entered action and person entities
If bot recognizes
entities['action'].size() + entities['person'].size() > 2
Any other way to achieve this?
To account for one of the entities not being recognized, you can use ternary operator <Expression> ? <what_to_do_when_true> : <what_to_do_when_false>.
So, in your example the condition would look like this:
((entities['action'] != null ? entities['action'].size() : 0) + (entities['action'] != null ? entities['person'].size() : 0)) > 2
When one of the entity is not recognized (null), the value counted will be 0.

Linq - Query on 2 Lists Optimization

I am having 2 Lists & I am querying on this 2 List. Both the List are populated with huge data. So the query is taking long time.
When I usually face this performance issue, I simply convert SQL queries & run them directly & get the result in a datatable. But this time I cannot do this as these 2 are not tables but Lists of Models.
How to Optimize this Query or what else should i do?
Code :-
List<TempInOut> listTempInOut = new List<TO_TempInOut>();
List<ShiftSchedule> tempShiftSch = new List<TO_TempInOut>();
var data = (from B in tempShiftSch
from C in listTempInOut
where
B.CompanyId == companyId &&
C.CompanyId == companyId &&
B.EmployeeId == C.EmployeeId &&
C.InDate >= StrOutStart &&
C.InDate <= StrOutEnd &&
B.ShiftId == item.ShiftCode &&
B.ShiftDate == tempInputDate
select new
{
C.EmployeeId,
C.InDate,
C.Time_Date1
}).ToList();
Implement an IEqualityComparer for your types, use HashSet for each collection, and use the HashSet.Intersect method to get your output.
You can simplify your query to two stepsand compare time.
I am thinking of something like that.
var listTempInOutResult = listTempInOut.Where(C => C.CompanyId == companyId
&& C.InDate >= StrOutStart
&& C.InDate <= StrOutEnd);
var employessIds = listTempInOutresult.Select(x => x.EmployeeId).ToList();
var data = tempShiftSch.Where(B => employessIds.Contains(B.EmployeeId)
&& B.CompanyId == companyId
&& B.ShiftDate == tempInputDate
&& B.ShiftId == item.ShiftCode)
.Select(C=> new
{
C.EmployeeId,
C.InDate,
C.Time_Date1
}).ToList();
if you are working with iqueryable it would be better to use joins.
see this StackOverflow question

ASP.NET MVC 4 MvcMovie Tutorial Filter query by multiple search criteria

I was going through the MvcMovie Tutorial and I was trying to modify the SearchIndex() call in the MoviesController to search by multiple criteria. The tutorial shows you how to search by title and genre using the following code:
var movies = from m in db.Movies
select m;
if (!String.IsNullOrEmpty(searchString))
{
movies = movies.Where(s => s.Title.Contains(searchString));
}
if (string.IsNullOrEmpty(movieGenre))
return View(movies);
else
{
return View(movies.Where(x => x.Genre == movieGenre));
}
So if I read this right they return all movies then filter on Genre. That would be fine for a dual case but when you add in a 3rd or 4th search criteria you would then increase the amount of if statement calls by a factor of 2 (to the n) - 1 cases. This would get very unruly if for say you had 10 or so columns to search by.
I tried to use something a little more straight forward like:
var movieQry = from m in db.Movies
where ((m.Title !=null && m.Title == searchString) ||
(m.Rating != null && m.Rating == movieRating) ||
(m.Genre != null && m.Genre == movieGenre))
select m;
but that would not return anything when you first visit the page and only works for a single filter (if I select the Genre - I get good results but not when I select Genre and Rating) and I get nothing returned when I enter a search term for Title.
Is there an easier way to accomplish? (At some point I will need to be able to search on dozens of filters for a project I will be writing... and I have other questions about how to search database for entries but for not this will get me moving in the right direction).
if you want to include the column in the criteria if it is not null then try following:
string Title = Request.QueryString["Title"];
string Rating= Request.QueryString["Rating"];
string Genre = Request.QueryString["Genre"];
var movieQry = from m in db.Movies
where ((string.IsNullOrEmpty(Title) ? true : m.Title == Title ) &&
(string.IsNullOrEmpty(Rating) ? true : m.Rating == Rating ) &&
(string.IsNullOrEmpty(Genre) ? true : m.Genre == Genre ))
select m;
Behnam was kind of on the right track. I modified the code as follows:
var movieQry2 = from m in db.Movies
where ((string.IsNullOrEmpty(searchString) ? true : m.Title.Contains(searchString)) &&
(string.IsNullOrEmpty(movieRating) ? true : m.Rating == movieRating) &&
(string.IsNullOrEmpty(movieGenre) ? true : m.Genre == movieGenre))
select m;
This works and gives good results. Sorry Behnam can't give you an accepted answer but I did tick it up as being useful. Thanks for pointing me in the right direction.
Try this:
var movieQry = db.Movies
.Where(x=> (Title == null || x.Title ==Title)
&& (Rating == null || x.Rating == Rating)
&& (Genre == null || x.Genre == Genre))
.ToList();
For other paging and sorting see MVC multiple field search

SQL to LINQ Expression

I have specific SQL expression :
{
select * from courceMCPD.dbo.Contact c
where c.cID in ( select cId from courceMCPD.dbo.Friend f where f.cId=5)
}
i would like to get LINQ expression that gets the same result.
thank you in advance.
That sounds like it's equivalent to something like:
var friendIds = from friend in db.Friends
where friend.ContactId == 5
select friend.ContactId;
var query = from contact in db.Contacts
where friendIds.Contains(contact.Id)
select contact;
(There are lots of different ways of representing the query, but that's the simplest one I could think of.)
It's pretty odd to perform a join on a particular field and also mandate that that field has to have a particular value though... there's not very much difference between that and:
var query = db.Contacts.Where(c => c.Id == 5);
... the only difference is whether there are any friend entries for that particular contact.
EDIT: Smudge gave another option for the query in a comment, so I'm promoting it into this answer...
var query = db.Contacts.Where(c => c.Friends.Any(f => f.cId == 5))
This assumes you've got an appropriate Friends relationship defined in the Contacts entity.
Using labda expressions:
var query = dc.Contact
.Where(c => dc.Friend.Select(f => f.cId).Contains(i.cID))
.Where(c => c.cId == 5);
User "query" syntax:
var query = from c in dc.Contact
where (from f in dc.Friend select f.cID).Contains(c.cId)
where c.cId == 5
select c;
You haven't specified VB/C# so I'm going for VB =P
Dim results As IEnumerable(Of yourEntities.Contact) =
(From c In yourContextInstance.Contacts Where (From f In yourContextInstance.Friends
Where f.cId = 5 Select f.cId).Contains(c.cID))
Clearly, Jon's answer works, this query (I believe) just resembles your T-SQL Closer.

Filtering data in LINQ

I have an observable collection which would be bound to the silverlight datagrid, where i need to display a particular row based on the data present in the OC
ID Name Status Desc Role
--------------------------------
1 ABC 500 des 50
1 ABC 500 des 55
2 XYZ 502 des 57
in the above table there are duplicate values, i need to filter them in such a way that when (status = 500) i need to pick the row which has role as 50. or if the (status = 501) i need to pick the row which has role as 55. In any instant the status would remain same for a particular ID. My final data should look like the one below.
ID Name Status Desc Role
---------------------------------
1 ABC 500 des 50
2 XYZ 502 des 57
It's not a fun query by any means. There may be a better answer, but this should get you started. The trick here is that you'll need to change your orderby clause to meet your needs. I couldn't tell from your question whether you were trying to pick the min Role value, or were trying to convey something else, but that orderby clause is where your custom logic for picking the right record goes.
var results =
from a in DataVals
group a by new {a.ID, a.Name, a.Status, a.Desc} into g
select new {
g.Key.ID,
g.Key.Name,
g.Key.Status,
g.Key.Desc,
Role = (
from b in DataVals
where b.ID == g.Key.ID
&& b.Name == g.Key.Name
&& b.Status == g.Key.Status
&& b.Desc == g.Key.Desc
orderby b.Role
select b.Role
).Take(1).FirstOrDefault()
};

Resources