public async Task <IActionResult> CreateBrandCategory(int categoryId, int brandId)
        {
            var category = await _repository.GetCategory(categoryId);

            if (category == null)
            {
                return(BadRequest("Invalid Category Id"));
            }
            var brand = await _repository.GetBrand(brandId);

            if (brand == null)
            {
                return(BadRequest("Invalid Brand Id"));
            }
            var brandCat = new BrandCategory {
                CategoryId = categoryId,
                BrandId    = brandId
            };

            if (await _repository.EntityExists(brandCat))
            {
                return(BadRequest("The Brand Id already belongs to this category"));
            }
            _repository.Add(brandCat);
            if (await _repository.SaveAllChangesAsync())
            {
                return(Ok("Successfully created brand Category"));
            }
            return(BadRequest("An Error occurred while creating brand category"));
        }
示例#2
0
        public async Task <IActionResult> AddManufacturer(Manufacturer manufacturer)
        {
            _repo.Add <Manufacturer>(manufacturer);
            await _repo.SaveAll();

            return(CreatedAtAction("GetManufacturers", new { id = manufacturer.IDManufacturer }, manufacturer));
        }
        public async Task <IActionResult> AddProduct(ProductForCreationDto productForCreationDto)
        {
            var productToCreate = _mapper.Map <Product>(productForCreationDto);

            _repo.Add <Product>(productToCreate);
            await _repo.SaveAll();

            return(CreatedAtAction("GetProducts", new { id = productToCreate.IDProduct }, productToCreate));
        }
        private async Task <bool> SaveOrderStatuses()
        {
            List <OrderStatus> defaultOrderStatuses = new List <OrderStatus>()
            {
                new OrderStatus()
                {
                    Name = OrderStatus._WaitingStock
                },
                new OrderStatus()
                {
                    Name = OrderStatus._WaitingPayment
                },
                new OrderStatus()
                {
                    Name = OrderStatus._Packing
                },
                new OrderStatus()
                {
                    Name = OrderStatus._Delivering
                },
                new OrderStatus()
                {
                    Name = OrderStatus._Delivered
                }
            };

            IEnumerable <OrderStatus> existingOrderStatuses = _shoppingRepo.GetOrderStatuses();

            foreach (OrderStatus orderStatus in defaultOrderStatuses)
            {
                if (!existingOrderStatuses.Any(m => m.Name == orderStatus.Name))
                {
                    _shoppingRepo.Add(orderStatus);
                }
            }

            return(await _shoppingRepo.SaveAllAsync());
        }
        public async Task <IActionResult> CreateMerchant([FromBody] MerchantToCreateDto customerToCreateDto)
        {
            var customerToCreate = _mapper.Map <Merchant>(customerToCreateDto);

            if (await _repository.EntityExists(customerToCreate))
            {
                return(BadRequest("Merchant Name Exists"));
            }
            _repository.Add(customerToCreate);
            if (await _repository.SaveAllChangesAsync())
            {
                return(CreatedAtRoute("GetMerchant", new { id = customerToCreate.Id }, customerToCreate));
            }
            return(BadRequest("An Error occurred while creating the Merchant"));
        }
        public async Task <IActionResult> CreateCategory([FromBody] CategoryToCreateDto categoryToCreateDto)
        {
            var categoryToCreate = _mapper.Map <Category>(categoryToCreateDto);

            if (await _repository.EntityExists(categoryToCreate))
            {
                return(BadRequest("Category Name Exists"));
            }
            _repository.Add(categoryToCreate);
            if (await _repository.SaveAllChangesAsync())
            {
                return(CreatedAtRoute("GetMerchant", new { id = categoryToCreate.Id }, categoryToCreate));
            }
            return(BadRequest("An Error occurred while creating the Category"));
        }
示例#7
0
        public async Task <IActionResult> CreateStore([FromBody] StoreToCreateDto storeToCreateDto)
        {
            var storeToCreate = _mapper.Map <Store>(storeToCreateDto);

            if (await _repository.EntityExists(storeToCreate))
            {
                return(BadRequest("Store with the same name and location exists"));
            }
            _repository.Add(storeToCreate);
            if (await _repository.SaveAllChangesAsync())
            {
                return(CreatedAtRoute("GetStore", new { id = storeToCreate.Id }, storeToCreate));
            }
            return(BadRequest("An Error occurred while creating the store"));
        }
        public async Task <IActionResult> CreateBrand([FromBody] BrandToCreateDto brandToCreateDto)
        {
            var categoryFromRepo = await _repository.GetCategory(brandToCreateDto.CategoryId);

            var brandToCreate = _mapper.Map <Brand>(brandToCreateDto);

            if (await _repository.EntityExists(brandToCreate))
            {
                return(BadRequest("Brand Name Exists"));
            }
            _repository.Add(brandToCreate);
            if (await _repository.SaveAllChangesAsync())
            {
                var brandToReturn = _mapper.Map <BrandToCreateDto>(brandToCreateDto);
                return(CreatedAtRoute("GetBrand", new { id = brandToCreate.Id }, brandToReturn));
            }
            return(BadRequest("An Error occurred while creating the brand"));
        }