public ActionResult ProjectionWithEntityType_EMS()
        {
            var vm = new QueryResultViewModel <StudentDisplay>();

            try
            {
                var results = db.Students
                              .Select(s => new Student()
                {
                    ID             = s.ID,
                    FirstMidName   = s.FirstMidName,
                    LastName       = s.LastName,
                    EnrollmentDate = s.EnrollmentDate
                });
                vm.Results = results.ToArray().Select(s => new StudentDisplay()
                {
                    ID             = s.ID,
                    FirstMidName   = s.FirstMidName,
                    LastName       = s.LastName,
                    FullName       = s.LastName + ", " + s.FirstMidName,
                    EnrollmentDate = s.EnrollmentDate
                }).ToArray();
                Response.StatusCode = 200;
            }
            catch (Exception ex)
            {
                vm.Results          = null;
                vm.Exception        = ex;
                Response.StatusCode = 500;
            }
            return(View("QueryResult", vm));
        }
        public ActionResult SelectWithReadOnlyProperty_QS()
        {
            var vm = new QueryResultViewModel <StudentDisplay>();

            try
            {
                var results = from s in db.Students
                              select new StudentDisplay()
                {
                    ID             = s.ID,
                    FirstMidName   = s.FirstMidName,
                    LastName       = s.LastName,
                    FullName       = s.FullName,
                    EnrollmentDate = s.EnrollmentDate
                };
                vm.Results          = results.ToArray();
                Response.StatusCode = 200;
            }
            catch (Exception ex)
            {
                vm.Results          = null;
                vm.Exception        = ex;
                Response.StatusCode = 500;
            }
            return(View("QueryResult", vm));
        }
        public ActionResult BadEnrollmentFilter_QS()
        {
            var vm = new QueryResultViewModel <StudentDisplay>();

            try
            {
                Func <Enrollment, bool> predicate = e => e.Grade == Grade.A;
                var results = from s in db.Students
                              where s.Enrollments.Any(predicate)
                              select new StudentDisplay()
                {
                    ID             = s.ID,
                    FirstMidName   = s.FirstMidName,
                    LastName       = s.LastName,
                    FullName       = s.LastName + ", " + s.FirstMidName,
                    EnrollmentDate = s.EnrollmentDate
                };
                vm.Results          = results.ToArray();
                Response.StatusCode = 200;
            }
            catch (Exception ex)
            {
                vm.Results          = null;
                vm.Exception        = ex;
                Response.StatusCode = 500;
            }
            return(View("QueryResult", vm));
        }
        public ActionResult WhereWithInterpolatedString_QS()
        {
            var vm = new QueryResultViewModel <StudentDisplay>();

            try
            {
                string startLetter = "A";
                var    results     = from s in db.Students
                                     where s.LastName.StartsWith($" {startLetter}")
                                     select new StudentDisplay()
                {
                    ID             = s.ID,
                    FirstMidName   = s.FirstMidName,
                    LastName       = s.LastName,
                    FullName       = s.LastName + ", " + s.FirstMidName,
                    EnrollmentDate = s.EnrollmentDate
                };
                vm.Results          = results.ToArray();
                Response.StatusCode = 200;
            }
            catch (Exception ex)
            {
                vm.Results          = null;
                vm.Exception        = ex;
                Response.StatusCode = 500;
            }
            return(View("QueryResult", vm));
        }
        public ActionResult WhereWithReadOnlyProperty_EMS()
        {
            var vm = new QueryResultViewModel <StudentDisplay>();

            try
            {
                var results = db.Students
                              .Where(s => s.FullName.Contains(" A"))
                              .Select(s => new StudentDisplay()
                {
                    ID             = s.ID,
                    FirstMidName   = s.FirstMidName,
                    LastName       = s.LastName,
                    FullName       = s.LastName + ", " + s.FirstMidName,
                    EnrollmentDate = s.EnrollmentDate
                });
                vm.Results          = results.ToArray();
                Response.StatusCode = 200;
            }
            catch (Exception ex)
            {
                vm.Results          = null;
                vm.Exception        = ex;
                Response.StatusCode = 500;
            }
            return(View("QueryResult", vm));
        }
 public ActionResult BadEnrollmentFilter_QS()
 {
     var vm = new QueryResultViewModel<StudentDisplay>();
     try
     {
         Func<Enrollment, bool> predicate = e => e.Grade == Grade.A;
         var results = from s in db.Students
                       where s.Enrollments.Any(predicate)
                       select new StudentDisplay()
                       {
                           ID = s.ID,
                           FirstMidName = s.FirstMidName,
                           LastName = s.LastName,
                           FullName = s.LastName + ", " + s.FirstMidName,
                           EnrollmentDate = s.EnrollmentDate
                       };
         vm.Results = results.ToArray();
         Response.StatusCode = 200;
     }
     catch (Exception ex)
     {
         vm.Results = null;
         vm.Exception = ex;
         Response.StatusCode = 500;
     }
     return View("QueryResult", vm);
 }
예제 #7
0
 public RootResultViewModel(QueryResultViewModel queryResultView, RegistryViewModel registry, HttpRequest httpContextRequest)
 {
     foreach (var result in queryResultView.Rows)
     {
         if (result != null && result[0].ToString() == "table")
         {
             Tables.Add(new RootTableResultViewModel(result[1].ToString(), registry, httpContextRequest));
         }
     }
 }
예제 #8
0
        public void ResultTest()
        {
            QueryController      target   = new QueryController(); // TODO: Initialize to an appropriate value
            QueryResultViewModel mode     = null;                  // TODO: Initialize to an appropriate value
            ActionResult         expected = null;                  // TODO: Initialize to an appropriate value
            ActionResult         actual;

            actual = target.Result(mode);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
예제 #9
0
        public async Task RunAsync(QueryResultViewModel state, String query)
        {
            if (!String.IsNullOrEmpty(state.Query))
            {
                _queries.Add(state);

                try
                {
                    var result = await Task.Run(() =>
                    {
                        state.Thread = Thread.CurrentThread;
                        return(_parser.Evaluate(query.Replace("\r\n", "\n")));
                    });

                    state.Value = result;
                }
                catch (YAMPParseException ex)
                {
                    var error = ex.Errors.FirstOrDefault();

                    if (error != null)
                    {
                        state.Error = new YAMPException(error.Message);
                    }
                    else
                    {
                        state.Error = ex;
                    }
                }
                catch (YAMPRuntimeException ex)
                {
                    state.Error = ex;
                }
                catch (ThreadAbortException)
                {
                    state.Error = new Exception(Messages.ComputationAborted);
                }
                catch (Exception ex)
                {
                    state.Error = ex;
                    _logger.Error(ex);
                }
                finally
                {
                    _queries.Remove(state);
                }
            }
        }
예제 #10
0
        public ActionResult Execute(QueryRequestModel request)
        {
            try
            {
                var temp = new User
                {
                    Username = "******",
                    Email    = "*****@*****.**"
                };
                var user = DataContext.Users.FirstOrDefault(x => x.Username == temp.Username);
                if (user == null)
                {
                    DataContext.Users.Add(temp);
                    DataContext.SaveChanges();
                }



                var query = new SqlQuery
                {
                    Sql = request.Query
                };
                IQueryResult result = GetUserDataSource().Execute(query);
                var          model  = QueryResultViewModel.Generate(result);

                //var json = JsonResult(model);
                //return json;

                var view = PartialView("_ExecuteResult", model);
                return(view);
            }
            catch (Exception ex)
            {
                return(Error(ex));
            }
        }
 public ActionResult ProjectionWithEntityType_EMS()
 {
     var vm = new QueryResultViewModel<StudentDisplay>();
     try
     {
         var results = db.Students
                         .Select(s => new Student()
                         {
                             ID = s.ID,
                             FirstMidName = s.FirstMidName,
                             LastName = s.LastName,
                             EnrollmentDate = s.EnrollmentDate
                         });
         vm.Results = results.ToArray().Select(s => new StudentDisplay()
         {
             ID = s.ID,
             FirstMidName = s.FirstMidName,
             LastName = s.LastName,
             FullName = s.LastName + ", " + s.FirstMidName,
             EnrollmentDate = s.EnrollmentDate
         }).ToArray();
         Response.StatusCode = 200;
     }
     catch (Exception ex)
     {
         vm.Results = null;
         vm.Exception = ex;
         Response.StatusCode = 500;
     }
     return View("QueryResult", vm);
 }
 public ActionResult WhereWithReadOnlyProperty_QS()
 {
     var vm = new QueryResultViewModel<StudentDisplay>();
     try
     {
         var results = from s in db.Students
                       where s.FullName.Contains(" A")
                       select new StudentDisplay()
                       {
                           ID = s.ID,
                           FirstMidName = s.FirstMidName,
                           LastName = s.LastName,
                           FullName = s.LastName + ", " + s.FirstMidName,
                           EnrollmentDate = s.EnrollmentDate
                       };
         vm.Results = results.ToArray();
         Response.StatusCode = 200;
     }
     catch (Exception ex)
     {
         vm.Results = null;
         vm.Exception = ex;
         Response.StatusCode = 500;
     }
     return View("QueryResult", vm);
 }
 public ActionResult WhereWithInterpolatedString_QS()
 {
     var vm = new QueryResultViewModel<StudentDisplay>();
     try
     {
         string startLetter = "A";
         var results = from s in db.Students
                       where s.LastName.StartsWith($" {startLetter}")
                       select new StudentDisplay()
                       {
                           ID = s.ID,
                           FirstMidName = s.FirstMidName,
                           LastName = s.LastName,
                           FullName = s.LastName + ", " + s.FirstMidName,
                           EnrollmentDate = s.EnrollmentDate
                       };
         vm.Results = results.ToArray();
         Response.StatusCode = 200;
     }
     catch (Exception ex)
     {
         vm.Results = null;
         vm.Exception = ex;
         Response.StatusCode = 500;
     }
     return View("QueryResult", vm);
 }
 public ActionResult SelectWithReadOnlyPropertyExpr_EMS()
 {
     var vm = new QueryResultViewModel<StudentDisplay>();
     try
     {
         var results = db.Students.Select(s => new StudentDisplay()
         {
             ID = s.ID,
             FirstMidName = s.FirstMidName,
             LastName = s.LastName,
             FullName = s.FullNameExpr,
             EnrollmentDate = s.EnrollmentDate
         });
         vm.Results = results.ToArray();
         Response.StatusCode = 200;
     }
     catch (Exception ex)
     {
         vm.Results = null;
         vm.Exception = ex;
         Response.StatusCode = 500;
     }
     return View("QueryResult", vm);
 }
 public ActionResult SelectUseOfUnmappedProperty_QS()
 {
     var vm = new QueryResultViewModel<StudentDisplay>();
     try
     {
         var results = from s in db.Students
                       select new StudentDisplay()
                       {
                           ID = s.ID,
                           FirstMidName = s.FirstMidName,
                           LastName = s.LastName,
                           FullName = s.LastName + ", " + s.FirstMidName + ", " + s.Unmapped,
                           EnrollmentDate = s.EnrollmentDate
                       };
         vm.Results = results.ToArray();
         Response.StatusCode = 200;
     }
     catch (Exception ex)
     {
         vm.Results = null;
         vm.Exception = ex;
         Response.StatusCode = 500;
     }
     return View("QueryResult", vm);
 }
예제 #16
0
        public async Task <ActionResult <MealViewModel[]> > FindMeals([FromQuery] string ingr)
        {
            try
            {
                if (!string.IsNullOrEmpty(ingr))
                {
                    // Find recipes based on ingredients sent in the query string
                    string[] desirableIngredients   = ExtractDesirableIngredientsFromQueryString(ingr);
                    int[]    desirableIngredientIds = await _repository.GetIngredientsByQueryString(desirableIngredients);

                    string[] undesirableIngredients = ExtractUndesirableIngredientsFromQueryString(ingr);

                    // This is for ingredient button implementation
                    string[]             ingredientsFromQueryString = ExtractAllIngredientsFromQueryString(ingr);
                    IEnumerable <string> validIngredients           = await GetValidIngredients(ingredientsFromQueryString);

                    IEnumerable <string> invalidIngredients = await GetInvalidIngredients(ingredientsFromQueryString);

                    // TODO: Create a helper function
                    Meal[] potentialMatchingMeals = await _repository.FindMealsByIngredients(desirableIngredientIds);

                    HashSet <int> potentialMatchingMealHashSets = potentialMatchingMeals
                                                                  .Select(i => i.MealId)
                                                                  .ToHashSet();

                    // Filter recipes based on excluded ingredients
                    if (undesirableIngredients.Count() > 0)
                    {
                        var undesirableIngredientIds = await _repository.GetIngredientsByQueryString(undesirableIngredients);

                        var mealsToRemove = new List <Meal>();

                        foreach (var meal in potentialMatchingMeals)
                        {
                            if (MealContainsAnyIngredients(meal, undesirableIngredientIds))
                            {
                                mealsToRemove.Add(meal);
                            }
                        }
                        HashSet <int> mealsToRemoveHashSet = mealsToRemove
                                                             .Select(mid => mid.MealId)
                                                             .ToHashSet();

                        // Create a hash set of filtered mealIds
                        potentialMatchingMealHashSets.ExceptWith(mealsToRemoveHashSet);
                        // Now we have hash set - we need to filter meal list - linq query may not grab ingredients - this may need another repository interface
                    }
                    IEnumerable <Meal> filteredMeals = await _repository.GetMealByIds(potentialMatchingMealHashSets);

                    // Remove filteredMeals from potentialMatchingMeals here
                    // if true, remove meal

                    var matchingMeals = new List <Meal>();
                    foreach (var meal in filteredMeals)
                    {
                        if (MealContainsAllIngredients(meal, desirableIngredientIds))
                        {
                            matchingMeals.Add(meal);
                            _logger.LogInformation($"Found match: {meal}");
                        }
                    }
                    MealViewModel[] availabeMealsViewModel = _mapper.Map <MealViewModel[]>(matchingMeals);

                    // Instantiate new class, populate with data, and return
                    var QueryResult = new QueryResultViewModel();
                    QueryResult.Meals              = availabeMealsViewModel;
                    QueryResult.TargetIngredients  = validIngredients;
                    QueryResult.InvalidIngredients = invalidIngredients;
                    // TODO: Get list of recognized and unrecognized ingredients
                    return(Ok(QueryResult));
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (Exception exception)
            {
                _logger.LogError($"Could not execute meal search: {exception}");
                return(BadRequest("Could not execute meal search."));
            }
        }
예제 #17
0
 void Initialize()
 {
     Model      = new MainWindowViewModel();
     Connection = new ConnectionViewModel(_settings);
     Query      = new QueryResultViewModel();
 }