public LoadResult <CustomText> Get(CustomTextRequest req, LoadOptions opts)
        {
            if (req.ModifiedOnly)
            {
                var op = opts.GetOptionsFor <CustomText>();
                op.AddFilter(e => e.TenantId == req.TenantId);
                op.AddFilter(e => e.Type == req.Type);
                op.AddFilter(e => e.Locale == req.Locale);
                var data = Unit.CustomTextRepository.Find(op);
                foreach (var x in data.ListT)
                {
                    x.State = "Attached";
                }
                return(data);
            }
            var resx             = loc.LoadForTenant(req, opts);
            List <CustomText> db = Unit.CustomTextRepository.GetBy(req);
            var lst = new List <CustomText>();

            foreach (var item in resx.ListT)
            {
                var ex = db.Where(e => e.Code == item.Code).FirstOrDefault();
                if (ex != null)
                {
                    ex.State = "Attached";
                    lst.Add(ex);
                }
                else
                {
                    lst.Add(item);
                }
            }
            resx.List = lst;
            return(resx);
        }
示例#2
0
        public virtual LoadResult <CustomText> LoadForTenant(CustomTextRequest req, LoadOptions opts)
        {
            string resLang1 = Path.Combine(_paths.LocalizationRoot, "Localization", ((TextTypes)req.Type).ToString() + "." + req.Locale + ".resx");

            ResxXmlReader reader = new ResxXmlReader();
            var           res    = new LoadResult <CustomText>();

            if (reader.TryRead(resLang1, out ResourceContainer cont1))
            {
                var items = cont1.DataItems.ToList();

                if (!string.IsNullOrEmpty(opts.SearchTerm))
                {
                    items = items.Where(e => e.Name.ToLower().Contains(opts.SearchTerm.ToLower()) || e.Value.ToLower().Contains(opts.SearchTerm.ToLower())).ToList();
                }
                res.TotalCount = items.Count();

                IEnumerable <DataItem> q;
                if (opts.Showing > 0)
                {
                    q = items.Skip(opts.Skip).Take(opts.Showing);
                }
                else
                {
                    q = items;
                }

                res.List = q.Select(e => new CustomText
                {
                    Code     = e.Name,
                    Value    = e.Value,
                    TenantId = req.TenantId,
                    State    = "Detached",
                    Locale   = req.Locale,
                    Type     = req.Type
                }).ToList();
            }
            return(res);
        }
 public List <CustomText> GetBy(CustomTextRequest req)
 {
     return(Find(e => e.Locale == req.Locale && e.TenantId == req.TenantId && e.Type == req.Type));
 }
 public IActionResult Get([FromBody] CustomTextRequest req, [FromQuery] LoadOptions opts)
 {
     return(Respond(service.Get(req, opts)));
 }