コード例 #1
0
 private void ValidatePosition(Employee obj)
 {
     if (obj != null && obj.Position != null)
     {
         using (var ctx = new BuyMoriaContext())
         {
             var positions         = ctx.Employees.Select(e => e.Position).Distinct();
             var IsCurrentPosition = positions.Contains(obj.Position);
             if (!IsCurrentPosition)
             {
                 AddError("Position", "Not a valid position - please use an existing position");
             }
         }
     }
 }
コード例 #2
0
 // GET api/hr/5
 public IEnumerable <object> Get(string term)
 {
     //  A quick WEB API method to bring back all the positions that match
     //  with what the user has typed in so far (autosuggest mode)
     //  returns IEnumerable<anon-type { string label, string value }>
     using (var db = new BuyMoriaContext())
     {
         var positions = db.Employees.
                         Where(e
                               => e.Position.ToLower().Contains(term.ToLower())).
                         Select(e => new
         {
             label = e.Position,
             value = e.Position
         }).
                         Distinct();
         return(positions.ToList());
     }
 }