コード例 #1
0
        public JsonResult CreateEditGood(Good model)
        {
            if (model.isEdit && model.id == 0)
            {
                throw new Exception("Попытка редактирования товара у которого не задан Id");
            }
            var admin = new OdmenAction();

            if (model.isEdit)
            {
                admin.ChangeGood(model);
            }
            else
            {
                admin.CreateGood(model);
            }
            return(Json(new { result = 0 }, JsonRequestBehavior.AllowGet));
        }
コード例 #2
0
        public void TestCreateGood()
        {
            var odmen   = new OdmenAction();
            var store   = new StoreAction();
            var groupId = store.GetGroups().FirstOrDefault().id;
            var newGood = new Good
            {
                imageUrl = "image" + Guid.NewGuid().ToString(),
                info     = "info" + Guid.NewGuid().ToString(),
                name     = "name" + Guid.NewGuid().ToString().Substring(0, 10),
                discount = 13,
                groupId  = groupId,
                price    = 123.44M,
                fullInfo = Guid.NewGuid().ToString() + Guid.NewGuid().ToString()
            };
            var id       = odmen.CreateGood(newGood);
            var property = new GoodProperty
            {
                goodId = id,
                name   = "name" + Guid.NewGuid(),
                value  = "value" + Guid.NewGuid()
            };
            var properties = new List <GoodProperty> {
                new GoodProperty
                {
                    goodId = id,
                    name   = "name" + Guid.NewGuid(),
                    value  = "value" + Guid.NewGuid()
                }, new GoodProperty
                {
                    goodId = id,
                    name   = "name" + Guid.NewGuid(),
                    value  = "value" + Guid.NewGuid()
                }
            };
            var propertyid = odmen.CreateGoodProperty(property);

            odmen.CreateGoodProperties(properties);
            Assert.IsTrue(id > 0 && propertyid > 0 && property.id > 0 && !properties.Any(s => s.id == 0));
        }