public IActionResult UpdateWithSpecifications([FromBody] ProductSpecificationsModel model)
        {
            var dao = GetDao();
            var specificationDao = GetDaoManager().SpecificationDao;
            var databaseProduct  = dao.Save(model.Product);

            foreach (var specification in model.Specifications)
            {
                specificationDao.Save(specification);
            }
            return(Ok());
        }
예제 #2
0
        public void UpdateWithSpecificationsTest()
        {
            ProductSpecificationsModel mock   = new ProductSpecificationsModel();
            OkObjectResult             result = (OkObjectResult)Controller.GetWithSpecifications(4);
            Product resultItems = (Product)result.Value;

            Specification[] specifications = resultItems.Specifications.ToArray();
            mock.Product        = resultItems;
            mock.Specifications = specifications;

            OkResult resulttest = (OkResult)Controller.UpdateWithSpecifications(mock);

            Assert.IsInstanceOfType(resulttest, typeof(OkResult));
        }
        public IActionResult CreateWithSpecifications([FromBody] ProductSpecificationsModel model)
        {
            try
            {
                var dao = GetDao();
                var specificationDao = GetDaoManager().SpecificationDao;
                var databaseProduct  = dao.Save(model.Product);
                foreach (var specification in model.Specifications)
                {
                    specification.ProductId = databaseProduct.Id;
                    specificationDao.Save(specification);
                }

                return(Ok());
            }
            catch (MySqlException ex)
            {
                return(LogError(ex));
            }
        }