Exemple #1
0
        public ActionResult AttributeList(DataSourceRequest command, string searchValues, IEnumerable <Sort> sort = null)
        {
            var model = BuildAttributeSearchModel();

            if (ModelState.IsValid)
            {
                model.Update(searchValues);

                PagedResult <Attribute> data = _attributeService.GetAttributes(model.ToExpression(), model.ToParameters(), command.Page - 1, command.PageSize, sort);
                var result = data.Result.Select(x => x.ToModel()).ToList();
                foreach (var r in result)
                {
                    r.ControlTypeText = r.ControlType.ToString();
                    r.DataTypeText    = r.DataType.ToString();
                    r.DataSourceText  = r.DataSource.ToString();
                }
                var gridModel = new DataSourceResult
                {
                    Data  = result,
                    Total = data.TotalCount
                };
                return(new JsonResult
                {
                    Data = gridModel
                });
            }
            else
            {
                return(Json(new { Errors = ModelState.SerializeErrors() }));
            }
        }
        public void GetListAttributes_ReturnListWithThreeAttributes()
        {
            // Arrage
            int processed        = 0;
            var listAttributeDto = AttributeServiceData.GetListWithThreeAttributes();

            attributeRepository.GetAll().Returns(listAttributeDto);
            attributeRepository.When(fx => fx.GetAll()).Do(fx => ++ processed);

            // Act
            var listAttributeDtoSpected = attributeService.GetAttributes();

            // Assert
            Assert.IsNotNull(listAttributeDtoSpected);
            Assert.IsTrue(listAttributeDtoSpected.Count == 3);
            Assert.AreEqual(1, processed);
            attributeRepository.Received(1).GetAll();
        }
Exemple #3
0
 public ActionResult GetAttributes()
 {
     try
     {
         var attributes = attributeService.GetAttributes();
         return(new OkObjectResult(attributes));
     }
     catch (Exception ex)
     {
         log.Error($"Ocurrió un error al consultar los atributos: {ex.Message}");
         return(StatusCode(HttpStatusCode.InternalServerError.GetHashCode(), ex.Message));
     }
 }
Exemple #4
0
        public ActionResult List(DataSourceRequest command, string searchValues, IEnumerable <Sort> sort = null)
        {
            var model = _httpContext.Session[SessionKey.AttributeSearchModel] as SearchModel;

            if (model == null)
            {
                model = BuildSearchModel();
            }
            else
            {
                model.ClearValues();
            }
            //validate
            var errorFilters = model.Validate(searchValues);

            foreach (var filter in errorFilters)
            {
                ModelState.AddModelError(filter.Name, _localizationService.GetResource(filter.ResourceKey + ".Required"));
            }
            if (ModelState.IsValid)
            {
                //session update
                model.Update(searchValues);
                _httpContext.Session[SessionKey.AttributeSearchModel] = model;

                PagedResult <Attribute> data = _attributeService.GetAttributes(model.ToExpression(), model.ToParameters(), command.Page - 1, command.PageSize, sort);
                var result = data.Result.Select(x => x.ToModel()).ToList();
                foreach (var r in result)
                {
                    r.ControlTypeText = r.ControlType.ToString();
                    r.DataTypeText    = r.DataType.ToString();
                    r.DataSourceText  = r.DataSource.ToString();
                }
                var gridModel = new DataSourceResult
                {
                    Data  = result,
                    Total = data.TotalCount
                };
                return(new JsonResult
                {
                    Data = gridModel
                });
            }

            return(Json(new { Errors = ModelState.SerializeErrors() }));
        }
        public ActionResult List(DataSourceRequest command, AttributeListModel model)
        {
            var attributes = _attributeService.GetAttributes(keywords: model.Keywords,
                                                             pageIndex: command.Start,
                                                             pageSize: command.Length);

            var jsonData = new DataSourceResult
            {
                data = attributes.Items.Select(a => new
                {
                    Id           = a.Id,
                    Name         = a.Name,
                    DisplayOrder = a.DisplayOrder,
                    WithOrder    = _productAttribtettributeService.GetProductAttributesByAttributeId(a.Id).Count(),
                }).ToList(),
            };

            return(AbpJson(jsonData));
        }
        public override async Task <GetAttributesResponse> Handle(GetAttributesRequest request, CancellationToken cancellationToken)
        {
            var attributes = await _cacheProvider.GetOrSet(CacheType.DistributedMemoryCache, "",
                                                           async(cancellationToken) => await _attributeService.GetAttributes(cancellationToken));

            return(Response.Success <GetAttributesResponse>(attributes));
        }
Exemple #7
0
 public async Task <IEnumerable <Attribute> > GetAttributes(CancellationToken cancellationToken)
 {
     return(await _cacheProvider.GetOrSet(CacheType.DistributedMemoryCache,
                                          CacheConstants.AttributeCache, async(cT) => await _attributeService
                                          .GetAttributes(cT), cancellationToken : cancellationToken));
 }
Exemple #8
0
        public IChatMessage GetResponse(long interactionId, IChatMessage message)
        {
            using (_trace.scope())
            {
                try
                {
                    /* FAIR WARNING
                     * This bot is a fairly bad idea to actually expose to users. It's meant as a testing
                     * bot to test the get/set attribute functionality. Set system attributes at your own risk.
                     */
                    Console.WriteLine("[{0}] - GetResponse ({1})", BotName, interactionId);

                    var textMessage = message as TextChatMessage;
                    if (textMessage == null)
                    {
                        return(null);
                    }

                    var pieces = textMessage.Text.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                    if (pieces.Length == 0)
                    {
                        return(null);
                    }

                    // Check for set
                    if (pieces.Length == 1)
                    {
                        var setData = pieces[0].Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
                        if (setData.Length == 2)
                        {
                            _attributeService.SetAttribute(interactionId, setData[0], setData[1]);
                            return(new TextChatMessage {
                                Text = "Attribute set!"
                            });
                        }

                        // Get attribute
                        var attr = _attributeService.GetAttribute(interactionId, pieces[0]);
                        return(new TextChatMessage {
                            Text = pieces[0] + "=" + attr
                        });
                    }

                    // Get attributes
                    var attrs = _attributeService.GetAttributes(interactionId, pieces);
                    return(new TextChatMessage
                    {
                        Text =
                            attrs.Select(a => a.Key + "=" + a.Value)
                            .Aggregate((a, b) => a + Environment.NewLine + b)
                    });
                }
                catch (Exception ex)
                {
                    _trace.exception(ex);
                    return(new TextChatMessage {
                        Text = "I'm sorry. I failed. Will you give me another chance?"
                    });
                }
            }
        }