Exemplo n.º 1
0
        public async Task <ActionResult <CategoryPresenter> > Put([FromBody] CategoryParameter category, long categoryCode)
        {
            Category result = await _categoryService.Update(categoryCode, category.ToModel());

            if (result is null)
            {
                return(NotFound());
            }
            return(new CategoryPresenter(result));
        }
Exemplo n.º 2
0
 public bool RemoveParametr(CategoryParameter param)
 {
     try
     {
         _categoryParameterRepository.Delete(param);
         _categoryParameterRepository.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemplo n.º 3
0
        public void parsesMethod1Array1Statement()
        {
            String      statement        = "method printName ( Option[] options ) { print ( value = \"array\" + options ); }";
            OTestParser parser           = new OTestParser(statement);
            ConcreteMethodDeclaration ad = parser.parse_concrete_method_declaration();

            Assert.IsNotNull(ad);
            Assert.AreEqual("printName", ad.GetName());
            Assert.IsNotNull(ad.getParameters());
            IParameter expected = new CategoryParameter(new ListType(new CategoryType("Option")), "options");

            Assert.IsTrue(ad.getParameters().Contains(expected));
            Assert.IsNotNull(ad.getStatements());
            Assert.AreEqual("print(value = \"array\" + options)", generate(ad.getStatements()[0]));
        }
Exemplo n.º 4
0
        public void testMethod1Array1Statement()
        {
            String statement = "define printName as method receiving Option[] options doing:\r\n"
                               + "\tprint with \"array\" + args as value";
            ETestParser parser           = new ETestParser(statement, false);
            ConcreteMethodDeclaration ad = parser.parse_concrete_method_declaration();

            Assert.IsNotNull(ad);
            Assert.AreEqual("printName", ad.GetName());
            Assert.IsNotNull(ad.getParameters());
            IParameter expected = new CategoryParameter(new ListType(new CategoryType("Option")), "options");

            Assert.IsTrue(ad.getParameters().Contains(expected));
            Assert.IsNotNull(ad.getStatements());
            Assert.AreEqual("print with \"array\" + args as value", generate(ad.getStatements()[0]));
        }
Exemplo n.º 5
0
        /// <summary>
        /// 保存商品分类
        /// </summary>
        /// <param name="parameter"></param>
        /// <returns></returns>
        public async Task <ReturnResult> Save(CategoryParameter parameter)
        {
            var result   = new ReturnResult();
            var category = Mapper.Map <Category>(parameter);

            //验证商品分类名称
            category.Name = category.Name?.Trim();
            if (string.IsNullOrEmpty(category.Name))
            {
                return(new ReturnResult(false, "名称不能为空"));
            }
            //编辑商品分类保存
            if (category.Id > 0)
            {
                var oldCategory = await context.Categorys.FirstOrDefaultAsync(c => c.Id == category.Id);

                if (oldCategory == null || oldCategory.IsDel)
                {
                    return(new ReturnResult(false, "分类已删除"));
                }
                var tmp = await GetCategoryEntityByNameAsync(category.Name);

                if (tmp != null && tmp.Id != category.Id)
                {
                    return(new ReturnResult(false, "名称重复"));
                }
                oldCategory.Name   = category.Name;
                oldCategory.Weight = category.Weight;
            }
            //新增商品分类保存
            else
            {
                var tmp = await GetCategoryEntityByNameAsync(category.Name);

                if (tmp != null)
                {
                    return(new ReturnResult(false, "名称重复"));
                }
                await context.Categorys.AddAsync(category);
            }
            await context.SaveChangesAsync();

            return(result);
        }
        public async Task TestaUpdate(long code)
        {
            var category = new CategoryParameter()
            {
                CategoryCode = code,
                Description  = "Teste atualizãção",
                IsActive     = false,
                Name         = "Atualizada"
            };

            var response = await _controller.Put(category, code);

            if (code == 1234)
            {
                Assert.IsType <ActionResult <CategoryPresenter> >(response);
            }
            else
            {
                Assert.IsType <NotFoundResult>(response.Result);
            }
        }
Exemplo n.º 7
0
        public void testAnonymousCategoryType()
        {
            // Root x
            IParameter argument = new CategoryParameter(new CategoryType("Root"), "x");

            argument.register(context);
            IType st = argument.GetIType(context);

            Assert.IsTrue(st is CategoryType);
            Assert.IsFalse(st.isAssignableFrom(context, BooleanType.Instance));
            Assert.IsFalse(st.isAssignableFrom(context, IntegerType.Instance));
            Assert.IsFalse(st.isAssignableFrom(context, DecimalType.Instance));
            Assert.IsFalse(st.isAssignableFrom(context, TextType.Instance));
            Assert.IsFalse(st.isAssignableFrom(context, DateType.Instance));
            Assert.IsFalse(st.isAssignableFrom(context, DateTimeType.Instance));
            Assert.IsFalse(st.isAssignableFrom(context, MissingType.Instance));
            Assert.IsFalse(st.isAssignableFrom(context, AnyType.Instance));                    // any type never compatible
            Assert.IsFalse(st.isAssignableFrom(context, new CategoryType("Simple")));          // since Simple does not extend Root
            Assert.IsTrue(st.isAssignableFrom(context, new CategoryType("Root")));             // since Root is Root
            Assert.IsTrue(st.isAssignableFrom(context, new CategoryType("DerivedWithOther"))); // since DerivedWithOther : Root
            Assert.IsTrue(st.isAssignableFrom(context, new CategoryType("DerivedWithName")));  // since DerivedWithName : Root
        }
Exemplo n.º 8
0
        public void testAnonymousAnyType()
        {
            // any x
            IParameter argument = new CategoryParameter(AnyType.Instance, "x");

            argument.register(context);
            IType st = argument.GetIType(context);

            Assert.IsTrue(st is AnyType);
            Assert.IsTrue(st.isAssignableFrom(context, BooleanType.Instance));
            Assert.IsTrue(st.isAssignableFrom(context, IntegerType.Instance));
            Assert.IsTrue(st.isAssignableFrom(context, DecimalType.Instance));
            Assert.IsTrue(st.isAssignableFrom(context, TextType.Instance));
            Assert.IsTrue(st.isAssignableFrom(context, DateType.Instance));
            Assert.IsTrue(st.isAssignableFrom(context, DateTimeType.Instance));
            Assert.IsTrue(st.isAssignableFrom(context, MissingType.Instance));
            Assert.IsTrue(st.isAssignableFrom(context, AnyType.Instance));
            Assert.IsTrue(st.isAssignableFrom(context, new CategoryType("Simple")));
            Assert.IsTrue(st.isAssignableFrom(context, new CategoryType("Root")));
            Assert.IsTrue(st.isAssignableFrom(context, new CategoryType("DerivedWithOther")));
            Assert.IsTrue(st.isAssignableFrom(context, new CategoryType("DerivedWithName")));
        }
Exemplo n.º 9
0
        public JsonResult AddParametr(int sectionID, string name, string desc)
        {
            if (!Request.IsAjaxRequest())
            {
                throw new InvalidCastException("Not an ajax request");
            }

            try
            {
                var param = new CategoryParameter
                {
                    SectionID   = sectionID,
                    Name        = name,
                    Description = desc
                };
                _shopService.AddParametr(param);
                return(Json(param.ID));
            }
            catch
            {
                return(Json(0));
            }
        }
Exemplo n.º 10
0
        public void testSystemOutPrint()
        {
            ECleverParser   parser = new ECleverParser("System.Console.Write(value);");
            ITokenStream    stream = (ITokenStream)parser.InputStream;
            EIndentingLexer lexer  = (EIndentingLexer)stream.TokenSource;

            lexer.AddLF = false;
            IParseTree      tree    = parser.csharp_statement();
            EPromptoBuilder builder = new EPromptoBuilder(parser);
            ParseTreeWalker walker  = new ParseTreeWalker();

            walker.Walk(builder, tree);
            CSharpStatement statement = builder.GetNodeValue <CSharpStatement>(tree);
            Context         context   = Context.newGlobalsContext();
            IParameter      arg       = new CategoryParameter(TextType.Instance, "value");

            arg.register(context);
            context.setValue("value", new prompto.value.TextValue("test")); // StringLiteral trims enclosing quotes
            Object result = statement.interpret(context, null);

            Assert.IsNull(result);
            Assert.AreEqual("test", Out.read());
        }
Exemplo n.º 11
0
        /// <summary>
        /// 保存商品分类
        /// </summary>
        /// <param name="category"></param>
        /// <returns></returns>
        public async Task <IActionResult> Save(CategoryParameter category)
        {
            var result = await categoryManager.Save(category);

            return(Json(result));
        }