c# - how to select assigned job to the user? -


i have mission system in mvc. , give same mission or diffrent mission lot of users. , show title, description, start date , finish date , are/is in mission. these showing view page in grid.mvc. when login can see every mission. dont want every mission want see mission. of course other users see missions.

in controller, split names.

this codes,

controller:

ticketdbcontext db = new ticketdbcontext();      public actionresult index()     {                  var result = db.missions.orderbydescending(x=>x.givendate).tolist();          string ad = string.empty;         foreach (var item in result)         {             if (!string.isnullorempty(item.givenusers))             {                 string[] ids = item.givenusers.split(',');                  (int = 0; < ids.length; i++)                 {                     int id = convert.toint32(ids[i]);                     item.givenusers += db.users.firstordefault(x => x.id == id).name+ " " + db.users.firstordefault(x => x.id == id).surname+ ",";                 }              }                         }          return view(result);      } 

screenshot of grid

enter image description here

firstly, recommend keep assigned users ids in separated table

this can handle case..

var currentuserid = "";// set current userid holding (session,identity etc..) var result = db.missions.orderbydescending(x=>x.givendate).tolist(); result = result.where(x=> x.givenusers.split(',').contains(currentuserid));     foreach (var item in result)     {         if (!string.isnullorempty(item.givenusers))         {             int[] ids = array.convertall(item.givenusers.split(','),                                       delegate(string s) { return int.parse(s); }) ;             string[] names = db.users.where(u => ids.contains(u.id)).select(u => u.name+ " " + u.surname).toarray();             item.givenusers = string.join(",",names);          }                     } 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -