Пример #1
0
        public void UpdateManufacture(long id, long manufactureId)
        {
            try
            {
                var product = _productRepo.GetProduct(id);
                if (product == null)
                {
                    throw new Exception("Product not found for product id = " + id);
                }

                var group = _productGroupRepo.Get(manufactureId);
                if (group == null)
                {
                    throw new Exception("Manufacture not found for manufacture id = " + manufactureId);
                }

                if (product.ProductGroupId != manufactureId)
                {
                    product.ProductGroupId = manufactureId;
                    product.ProductGroup   = group;
                    _productRepo.Update(product);
                }
            } catch (Exception e)
            {
                throw new Exception(string.Format("update manufacture for product {0} get error: {1}", id, e.Message));
            }
        }
        /// <summary>
        /// Details view
        /// </summary>
        /// <param name="id">Product Group id</param>
        /// <returns>Details View</returns>
        public async Task <IActionResult> Details(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            try
            {
                var productGroup = await _productGroupRepository.Get(p => p.Id == id);

                if (productGroup == null)
                {
                    return(NotFound());
                }

                productGroup.Children = (List <ProductGroup>) await _productGroupRepository.GetMany(p => p.ParentId == productGroup.Id);

                return(View(productGroup));
            }
            catch (Exception ex)
            {
                _logger.LogCritical(500, ex.Message, ex);

                return(StatusCode(500, ex.Message));
            }
        }
Пример #3
0
        public IHttpActionResult Save(ProductDto product)
        {
            if (product.VatRate.IsNullOrDefault() || product.Price.IsNullOrDefault() || product.PriceWithVat.IsNullOrDefault())
            {
                return(BadRequest("At least two values from these 3 must be entered : Price, VAT Rate, Price With VAT."));
            }

            if (_productGroupRepository.Get(product.ProductGroupId) == null)
            {
                return(BadRequest($"Entered Product Group Id:{product.ProductGroupId} does not exist in Database."));
            }

            var stores = _storeRepository.Get();

            foreach (var store in product.Stores)
            {
                if (!stores.Select(x => x.Id).Contains(store))
                {
                    return(BadRequest($"Store with Id: {store} does not exist in Database"));
                }
            }

            var entity = new Product {
                Id = 0
            };

            Mapper.Map(product, entity);
            var id = _productRepository.Create(entity);

            return(Ok($"New product added to Database, Id: {id}"));
        }
        public IHttpActionResult Get()
        {
            var groups = _productGroupRepository.Get();
            var result = new List <ProductGroupDto>();

            Mapper.Map(groups, result);
            return(Ok(result));
        }
Пример #5
0
        public async Task <IActionResult> GetProductGroupById([FromRoute] Guid id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var productGroup = await _productGroupRepository.Get(p => p.Id == id);

            if (productGroup == null)
            {
                return(NotFound());
            }

            return(Ok(productGroup));
        }
 public async Task <RProductGroup> Get(string id)
 {
     return(await _productGroupRepository.Get(id));
 }
Пример #7
0
 public ProductGroup Get(int id)
 {
     return(_productGroupRepository.Get(id));
 }