Пример #1
0
        public void FindByModelQuery_Should_Use_Linq_To_Sort()
        {
            var sort = new ModelQuery<DummyModel>().OrderBy("Id Ascending");
            var found = service.Object.Find(sort);

            Assert.Equal(4, found.Count());
            Assert.Equal(dummy1, found.First());
        }
Пример #2
0
        public void FindByModelQuery_Should_Use_Linq_To_Skip_Items()
        {
            var skip = new ModelQuery<DummyModel> {ItemsToSkip = 2};
            var found = service.Object.Find(skip);

            Assert.Equal(2, found.Count());
            Assert.Contains(dummy3, found);
            Assert.Contains(dummy4, found);
            Assert.DoesNotContain(dummy1, found);
            Assert.DoesNotContain(dummy2, found);
        }
Пример #3
0
        public void GetModelDependencies(string id, string extends, string contents, string expected)
        {
            string[]      expectedDtmis = expected.Split(new[] { "," }, System.StringSplitOptions.RemoveEmptyEntries);
            string        modelContent  = string.Format(_modelTemplate, id, extends, contents);
            ModelMetadata metadata      = new ModelQuery(modelContent).ParseModel();

            IList <string> dependencies = metadata.Dependencies;

            dependencies.Count.Should().Be(expectedDtmis.Length);

            foreach (string dtmi in dependencies)
            {
                expectedDtmis.Should().Contain(dtmi);
            }
        }
Пример #4
0
        public void GetModelDependencies(string id, string extends, string contents, string expected)
        {
            string[]      expectedDtmis = expected.Split(new[] { "," }, System.StringSplitOptions.RemoveEmptyEntries);
            string        modelContent  = string.Format(_modelTemplate, id, extends, contents);
            ModelMetadata metadata      = new ModelQuery(modelContent).GetMetadata();

            IList <string> dependencies = metadata.Dependencies;

            Assert.AreEqual(dependencies.Count, expectedDtmis.Length);

            foreach (string dtmi in dependencies)
            {
                Assert.Contains(dtmi, expectedDtmis);
            }
        }
Пример #5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        PageSize = defaultPageSize;

        if (!IsPostBack)
        {
            ActiveQuery = new ModelQuery()
            {
                SortMode = ModelQuery.ModelSortMode.ModelName, SortDir = ModelQuery.ModelSortDirection.Ascending, Limit = PageSize, Skip = 0, IncludeSampleImages = true
            };
            UpdateSortHeaders(ActiveQuery.SortMode);
        }

        this.Master.SelectedTab = tabID.actMakes;
        this.Title = (string)GetLocalResourceObject("PageResource2.Title");
    }
Пример #6
0
        public ActionResult GetList(ModelQuery modelQuery)
        {
            List <ModelFilter> filters = JsonConvert.DeserializeObject <List <ModelFilter> >(modelQuery.filters);

            modelQuery.filters = JsonConvert.SerializeObject(filters);

            int totalRow       = 0;
            var deptList       = _deptRep.Query(modelQuery, out totalRow);
            var deptViewModels = Mapper.Map <List <department>, List <DeptViewModel> >(deptList);

            GridModel grid = new GridModel();

            grid.total = totalRow;
            grid.rows  = deptViewModels;
            return(Content(JsonConvert.SerializeObject(grid)));
        }
Пример #7
0
        public ActionResult SearchC(ModelQuery obj)
        {
            var productos = (from p in db.producto
                             where p.nombre_producto == obj.nombrePro
                             select new { nombre = p.nombre_producto, foto = p.foto_producto }).ToList();

            List <ModelQuery> mo = new List <ModelQuery>();

            foreach (var item in productos)
            {
                ModelQuery m = new ModelQuery();
                m.nombrePro = item.nombre;
                m.fotoPro   = item.foto;
                mo.Add(m);
            }
            return(View(mo));
        }
        public async Task <IActionResult> GetAll(ModelQuery queryObject)
        {
            try
            {
                var result = await _publicholidaydetailsAppService.GetAll(queryObject);

                return(result.TotalItems > 0 ? Ok(result) : StatusCode(StatusCodes.Status204NoContent, result));
            }
            catch (Exception ex)
            {
                Logger.Error("ERROR: [PublicHolidayDetailsController] -[GetAll]: ExceptionMessage: " + ex.Message +
                             ", InnerException: " + ex.InnerException +
                             ", StackTrace: " + ex.StackTrace);

                return(StatusCode(StatusCodes.Status500InternalServerError, ex.InnerException));
            }
        }
Пример #9
0
    protected void UpdateFilter()
    {
        ModelQuery mq = ActiveQuery;

        mq.Skip             = 0;
        mq.FullText         = mfbSearchbox.SearchText;
        mq.Model            = txtModel.Text;
        mq.ModelName        = txtModelName.Text;
        mq.TypeName         = txtTypeName.Text;
        mq.ManufacturerName = txtManufacturer.Text;
        mq.CatClass         = txtCatClass.Text;
        ActiveQuery         = mq;

        tblHeaderRow.Visible = true;
        gvMakes.DataSource   = MakeModel.MatchingMakes(mq);
        gvMakes.DataBind();
    }
Пример #10
0
    public static string[] HtmlRowsForMakes(string szRestrict, int skip, int pageSize)
    {
        List <string> lst = new List <string>();

        // We have no Page, so things like Page_Load don't get called.
        // We fix this by faking a page and calling Server.Execute on it.  This sets up the form and - more importantly - causes Page_load to be called on loaded controls.
        using (Page p = new FormlessPage())
        {
            p.Controls.Add(new HtmlForm());
            using (StringWriter sw = new StringWriter(CultureInfo.CurrentCulture))
                HttpContext.Current.Server.Execute(p, sw, false);

            ModelQuery mq = JsonConvert.DeserializeObject <ModelQuery>(szRestrict);
            mq.Skip  = skip;
            mq.Limit = pageSize;

            foreach (MakeModel m in MakeModel.MatchingMakes(mq))
            {
                Controls_mfbMakeListItem mli = (Controls_mfbMakeListItem)p.LoadControl("~/Controls/mfbMakeListItem.ascx");
                HtmlTableRow             tr  = new HtmlTableRow();
                p.Form.Controls.Add(tr);
                HtmlTableCell tc = new HtmlTableCell();
                tr.Cells.Add(tc);
                tc.VAlign = "top";
                tc.Controls.Add(mli);
                // Now, write it out.
                StringBuilder sb = new StringBuilder();
                using (StringWriter sw = new StringWriter(sb, CultureInfo.CurrentCulture))
                    using (HtmlTextWriter htmlTW = new HtmlTextWriter(sw))
                    {
                        try
                        {
                            mli.SortMode = mq.SortMode;
                            mli.Model    = m;
                            mli.ModelLink.NavigateUrl = VirtualPathUtility.ToAbsolute(mli.ModelLink.NavigateUrl);
                            tr.RenderControl(htmlTW);
                            lst.Add(sb.ToString());
                        }
                        catch (ArgumentException) { } // don't write bogus or incomplete HTML
                    }
            }
        }

        return(lst.ToArray());
    }
Пример #11
0
    protected void SetSort(ModelQuery.ModelSortMode sortmode)
    {
        ModelQuery mq = ActiveQuery;

        if (mq.SortMode == sortmode)
        {
            mq.SortDir = (mq.SortDir == ModelQuery.ModelSortDirection.Ascending) ? ModelQuery.ModelSortDirection.Descending : ModelQuery.ModelSortDirection.Ascending;
        }
        else
        {
            mq.SortMode = sortmode;
            mq.SortDir  = ModelQuery.ModelSortDirection.Ascending;
        }
        ActiveQuery = mq;
        UpdateSortHeaders(sortmode);

        UpdateFilter();
    }
Пример #12
0
        public async Task <QueryResult <GetGroupResource> > GetGroups(ModelQuery queryObj)
        {
            var result = new QueryResult <GetGroupResource>();

            var query = context.Groups.Select(g => new GetGroupResource {
                Id                 = g.Id,
                Name               = g.Name,
                TotalMembers       = context.UserGroups.Where(ug => ug.GroupId == g.Id).Count(),
                TotalAssignTickets = context.TicketsAssign.Where(ta => ta.GroupId == g.Id).Count()
            }).AsQueryable();

            result.TotalItems = await query.CountAsync();

            query = query.ApplyPaging(queryObj);

            result.Items = await query.ToListAsync();

            return(result);
        }
Пример #13
0
        public ActionResult ActionQuery(ModelQuery query, int position)
        {
            if (!CurrentCube.ListCube.ContainsKey(position))
            {
                return(Json(new
                {
                    esQuery = false,
                    result = 0
                }));
            }

            var result = CurrentCube.ListCube[position].QueryCube(query);

            return(Json(new
            {
                esQuery = true,
                result
            }));
        }
Пример #14
0
        public ActionResult GetScoreList(ModelQuery modelQuery)
        {
            List <department>   depts    = _deptRep.GetAll();
            List <exam_subject> subjects = _subjectRep.GetAll();

            List <ModelFilter> filters = JsonConvert.DeserializeObject <List <ModelFilter> >(modelQuery.filters);
            var deptFilter             = filters.Find(f => f.name == "DeptId");

            if (deptFilter != null && deptFilter.value == "-1")
            {
                filters.Remove(deptFilter);
            }
            var subjectFilter = filters.Find(f => f.name == "SubjectId");

            if (subjectFilter != null && subjectFilter.value == "-1")
            {
                filters.Remove(subjectFilter);
            }
            modelQuery.filters   = JsonConvert.SerializeObject(filters);
            modelQuery.ordername = "EndTime";
            modelQuery.order     = "Desc";

            int totalRow;
            var scores          = _examScoreRep.Query(modelQuery, out totalRow);
            var scoreViewModels = Mapper.Map <List <exam_score>, List <ExamScoreViewModel> >(scores);

            //这儿应该用视图的,不应该用这个方法找的,但是数据少,。。。。
            foreach (var viewModel in scoreViewModels)
            {
                var dept = depts.Find(f => f.Id == viewModel.DeptId);
                viewModel.DeptName = dept.DeptName;

                var subject = subjects.Find(f => f.Id == viewModel.SubjectId);
                viewModel.SubjectName = subject.SubjectName;
            }

            GridModel grid = new GridModel();

            grid.total = totalRow;
            grid.rows  = scoreViewModels;
            return(Content(JsonConvert.SerializeObject(grid)));
        }
        public static string[] SuggestFullModels(string prefixText, int count)
        {
            if (String.IsNullOrEmpty(prefixText))
            {
                return(Array.Empty <string>());
            }

            ModelQuery modelQuery = new ModelQuery()
            {
                FullText = prefixText.Replace("-", "*"), PreferModelNameMatch = true, Skip = 0, Limit = count
            };
            List <string> lst = new List <string>();

            foreach (MakeModel mm in MakeModel.MatchingMakes(modelQuery))
            {
                lst.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(String.Format(CultureInfo.CurrentCulture, Resources.LocalizedText.LocalizedJoinWithDash, mm.ManufacturerDisplay, mm.ModelDisplayName), mm.MakeModelID.ToString(CultureInfo.InvariantCulture)));
            }

            return(lst.ToArray());
        }
Пример #16
0
        public void ListToDict()
        {
            string testRepoPath    = TestLocalModelRepository;
            string expandedContent = File.ReadAllText(
                $"{testRepoPath}/dtmi/com/example/temperaturecontroller-1.expanded.json", Encoding.UTF8);
            ModelQuery query = new ModelQuery(expandedContent);
            Dictionary <string, string> transformResult = query.ListToDict();

            // Assert KPIs for TemperatureController;1.
            // Ensure transform of expanded content to dictionary is what we'd expect.
            string[] expectedIds = new string[] {
                "dtmi:azure:DeviceManagement:DeviceInformation;1",
                "dtmi:com:example:Thermostat;1",
                "dtmi:com:example:TemperatureController;1"
            };

            transformResult.Keys.Count.Should().Be(expectedIds.Length);

            foreach (string id in expectedIds)
            {
                transformResult.Should().ContainKey(id);
                ParseRootDtmiFromJson(transformResult[id]).Should().Be(id);
            }
        }
        public async Task ListToDictAsync()
        {
            string testRepoPath    = TestHelpers.TestLocalModelRepository;
            string expandedContent = File.ReadAllText(
                $"{testRepoPath}/dtmi/com/example/temperaturecontroller-1.expanded.json", Encoding.UTF8);
            ModelQuery query = new ModelQuery(expandedContent);
            Dictionary <string, string> transformResult = await query.ListToDictAsync();

            // Assert KPI's for TemperatureController;1.
            // Ensure transform of expanded content to dictionary is what we'd expect.
            string[] expectedIds = new string[] {
                "dtmi:azure:DeviceManagement:DeviceInformation;1",
                "dtmi:com:example:Thermostat;1",
                "dtmi:com:example:TemperatureController;1"
            };

            Assert.True(transformResult.Keys.Count == expectedIds.Length);

            foreach (string id in expectedIds)
            {
                Assert.True(transformResult.ContainsKey(id));
                Assert.True(TestHelpers.ParseRootDtmiFromJson(transformResult[id]).Equals(id, System.StringComparison.Ordinal));
            }
        }
Пример #18
0
 public virtual QueryResult <TModelView> GetModel(ModelQuery query)
 {
     return(RunQuery(_queryRepository, query).MapTo <TModelView>());
 }
Пример #19
0
 public IEnumerable <DummyModel> Find(ModelQuery <DummyModel> query)
 {
     throw new NotImplementedException();
 }
Пример #20
0
 // GET: Model
 public ActionResult Index(ModelQuery query)
 {
     return(View(_getModels.Execute(query)));
 }
Пример #21
0
 public virtual QueryResult <TModelDto> GetModelDto(ModelQuery query)
 {
     return(RunQuery(_queryRepository, query));
 }
Пример #22
0
 public virtual async Task <QueryResult <TModelDto> > GetModelDtoAsync(ModelQuery query)
 {
     return(await RunQueryAsync(_queryRepository, query));
 }
Пример #23
0
        private CreditAccountStateDto UpdateFinesAndGetAccountState(int creditAccountId, DateTime specifiedDate)
        {
            var query = new ModelQuery()
            {
                Id = creditAccountId
            };
            var account = _creditAccountQueryRepository.Handle(query);
            var latestCreditAccountStateQuery = new ActualCreditAccountStateQuery()
            {
                Id = account.Id
            };
            var latestCreditAccountState   = _creditAccountQueryRepository.Handle(latestCreditAccountStateQuery);
            var creditAccountPaymentsQuery = new CreditPaymentsQuery()
            {
                CreditAccountId = account.Id
            };
            var latestCreditAccountStateDate = account.AgreementDate.AddMonths(latestCreditAccountState.Month);
            var accountPayments         = _creditAccountQueryRepository.Handle(creditAccountPaymentsQuery);
            var paymentsForLatestPeriod = accountPayments.Where(p => latestCreditAccountStateDate < p.Timestamp);
            var accountCurrency         = account.Currency;
            // S
            var sumPaidForLatestPeriod = paymentsForLatestPeriod.Sum(p => p.PaymentSum.Value);

            if (latestCreditAccountState.RemainDebt.Value <= sumPaidForLatestPeriod)
            {
                return(CloseAccount(account, latestCreditAccountState));
            }

            // Z
            var totalDebtRemaining = latestCreditAccountState.RemainDebt.Value;
            // A
            var debtForMonth = GetDebtForMonth(latestCreditAccountState);

            if (latestCreditAccountState.MainDebtRemain.Value > sumPaidForLatestPeriod)
            {
                var finesForOverdue = latestCreditAccountState.FinesForOverdue;
                finesForOverdue.Value += account.CreditType.FineInterest *
                                         latestCreditAccountState.MainDebtRemain.Value;
                var updateFinesCommand = new UpdateModelCommand <PriceDto>()
                {
                    ModelDto = finesForOverdue
                };
                _priceCommandRepository.Execute(updateFinesCommand);

                var totalDebt = latestCreditAccountState.RemainDebt;
                totalDebt.Value += finesForOverdue.Value;
                var updateTotalDebtCommand = new UpdateModelCommand <PriceDto>()
                {
                    ModelDto = totalDebt
                };
                _priceCommandRepository.Execute(updateTotalDebtCommand);
            }
            if (ShouldAccountUpdate(account, specifiedDate))
            {
                var previousFinesForOverdue = latestCreditAccountState.FinesForOverdue;
                // B
                var interestForMonth     = (decimal)account.CreditType.InterestRate / 12 * totalDebtRemaining;
                var totalInterestNotPaid = latestCreditAccountState.TotalInterestSumNotPaid.Value;

                var newTotalDebtRemaining   = totalDebtRemaining;
                var newTotalInterestNotPaid = totalInterestNotPaid;
                var mainDebtRemain          = latestCreditAccountState.MainDebtRemain.Value;
                if (sumPaidForLatestPeriod < debtForMonth + mainDebtRemain)
                {
                    newTotalDebtRemaining   -= sumPaidForLatestPeriod;
                    newTotalDebtRemaining   += debtForMonth;
                    newTotalInterestNotPaid += interestForMonth;
                    mainDebtRemain           = debtForMonth + mainDebtRemain - sumPaidForLatestPeriod;
                }
                else if (sumPaidForLatestPeriod <
                         debtForMonth + mainDebtRemain + totalInterestNotPaid + interestForMonth)
                {
                    newTotalDebtRemaining   -= debtForMonth + mainDebtRemain;
                    newTotalInterestNotPaid += interestForMonth -
                                               (sumPaidForLatestPeriod - debtForMonth - mainDebtRemain);
                    mainDebtRemain = 0m;
                }
                else
                {
                    newTotalInterestNotPaid = 0m;
                    newTotalDebtRemaining  -= sumPaidForLatestPeriod - interestForMonth - totalInterestNotPaid;
                    mainDebtRemain          = 0m;
                }

                var newCreditAccountState = new CreditAccountStateDto()
                {
                    CreditAccount   = account,
                    Month           = latestCreditAccountState.Month + 1,
                    FinesForOverdue = new PriceDto()
                    {
                        Currency = accountCurrency,
                        Value    = previousFinesForOverdue.Value
                    },
                    InterestCounted = new PriceDto()
                    {
                        Currency = accountCurrency,
                        Value    = interestForMonth
                    },
                    RemainDebt = new PriceDto()
                    {
                        Currency = accountCurrency,
                        Value    = Math.Max(newTotalDebtRemaining + previousFinesForOverdue.Value, 0m)
                    },
                    TotalInterestSumNotPaid = new PriceDto()
                    {
                        Currency = accountCurrency,
                        Value    = newTotalInterestNotPaid
                    },
                    MainDebtRemain = new PriceDto()
                    {
                        Currency = accountCurrency,
                        Value    = mainDebtRemain
                    }
                };
                return(newCreditAccountState);
            }
            return(null);
        }
        public IHttpActionResult Get()
        {
            var result = new ModelQuery().Execute();

            return(Ok(result));
        }
Пример #25
0
 public async Task <TModelDto> HandleAsync(ModelQuery query)
 {
     return(Mapper.Map <TModelDto>(await ModelsDao.FindAsync(query.Id)));
 }
Пример #26
0
 public TModelDto Handle(ModelQuery query)
 {
     return(Mapper.Map <TModelDto>(ModelsDao.Find(query.Id)));
 }
Пример #27
0
 public virtual async Task <QueryResult <TModelView> > GetModelAsync(ModelQuery query)
 {
     return((await RunQueryAsync(_queryRepository, query)).MapTo <TModelView>());
 }