Пример #1
0
 protected void Decrypt(FormCollection form)
 {
     if (EncryptDecryptService != null)
     {
         EncryptDecryptService.Decrypt(Session, form);
     }
 }
Пример #2
0
        public async Task <IEnumerable <User> > GetUserByCondition(ConditionModel condition)
        {
            IEnumerable <User> data;

            try
            {
                var decrypt    = EncryptDecryptService.DecryptAes(condition.encrypt);
                var _condition = JsonConvert.DeserializeObject <ConditionModel>(decrypt);
                data = db.User;
                // .AsNoTracking()
                // .AsExpandable();
                if (_condition.sid != null && _condition.sid.Any())
                {
                    data = data.Where(u => u.UserID.Equals(_condition.sid));
                }
                if (_condition.Name != null && _condition.Name.Any())
                {
                    data = data.Where(u => u.UserName.ToLower().Contains(_condition.Name.ToLower()));
                }
                if (_condition.Email != null && _condition.Email.Any())
                {
                    data = data.Where(u => u.Email.ToLower().Contains(_condition.Email.ToLower()));
                }

                //*
                //* ตัวอย่างการใช้งานการค้นหาแบบหลายเงื่อนไข
                //* ใช้ function ของ LINQKit
                //*
                // if(mySearchFilter.IsActive)
                //     result = result.Where(p => p.ActiveOnly);

                // if(mySearchFilter.CategoryIds != null && mySearchFilter.CategoryIds.Any())
                //     result = result.Where(p => mySearchFilter.CategoryIds.Contains(p.CategoryId));

                // if(mySearchFilter.Keywords != null && mySearchFilter.Keywords.Any())
                // {
                //     //Crate the builder
                //     var predicate = PredicateBuilder.New();

                //     //Loop through the keywords
                //     foreach(var item in mySearchFilter.Keywords)
                //     {
                //         var currentKeyword = item;
                //         predicate = predicate.Or (p => p.ProductName.Contains (currrentKeyword));
                //         predicate = predicate.Or (p => p.Description.Contains (currrentKeyword));
                //     }
                //     result = result.Where(predicate);
                //*

                data = data.ToList();
                return(await Task.FromResult(data));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #3
0
        public async Task <ActionResult <string> > GetCategotyByCondition(ConditionModel condition)
        {
            var t_ImpCat = Impcat.GetCategotyByCondition(condition);
            await Task.WhenAll(t_ImpCat);

            var _ImpCat = await t_ImpCat;

            if (_ImpCat != null)
            {
                var encryptjson = EncryptDecryptService.EncryptAes(JsonConvert.SerializeObject(_mapper.Map <IEnumerable <CategoryReadDto> >(_ImpCat)));
                condition.clear();
                condition.encrypt = encryptjson;
                return(Ok(condition));
            }
            else
            {
                return(NotFound());
            }
        }
Пример #4
0
        // ใช้สำหรับ
        public async Task <IEnumerable <CategoryModel> > GetCategoryByCondition(CategoryModel cat)
        {
            IEnumerable <CategoryModel> data = null;
            var client = _initapi.Initial();

            try
            {
                if (cat == null)
                {
                    throw new ArgumentNullException(nameof(cat));
                }
                _condition.id          = cat.CategoryID;
                _condition.Name        = cat.CategoryName;
                _condition.Description = cat.Description;
                //var json = JsonConvert.SerializeObject(_condition);
                var encryptjson = EncryptDecryptService.encryptAes(JsonConvert.SerializeObject(_condition));
                _condition.clear();
                _condition.encrypt = encryptjson;
                var                 json = JsonConvert.SerializeObject(_condition);
                HttpContent         c    = new StringContent(json, Encoding.UTF8, "application/json");
                HttpResponseMessage res  = await client.PostAsync(ConfigurationManager.AppSettings["ConditionApiUrl"], c);

                if (res.IsSuccessStatusCode)
                {
                    //var resulte = readdata.Content.ReadAsAsync<IList<CategoryModel>>();
                    var resulte        = res.Content.ReadAsStringAsync().Result;
                    var condition      = JsonConvert.DeserializeObject <ConditionModel>(resulte);
                    var decryptresulte = EncryptDecryptService.DecryptAes(condition.encrypt);

                    data = JsonConvert.DeserializeObject <IEnumerable <CategoryModel> >(decryptresulte);
                }
                return(data);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }