Example #1
0
        public bool CreateStore([FromBody] StoreDTO store)
        {
            var  s      = store.ToStore();
            bool exists = _StoreRepository.Add(s);

            return(exists);
        }
Example #2
0
        public async Task <IActionResult> Create([FromBody] StoreDTO storeDTO)
        {
            var store = Store.Create(storeDTO.Name,
                                     storeDTO.Description,
                                     storeDTO.Website);
            await _storesRepository.Add(store);

            return(Ok(store));
        }
Example #3
0
        public IActionResult CreateStore([FromBody] StoresVM storeVm)
        {
            if (storeVm == null || string.IsNullOrEmpty(storeVm.Store_name) || string.IsNullOrEmpty(storeVm.Token))
            {
                return(Ok(new { success = false, message = "Недопустимый формат" }));
            }

            var userId = _userRepository.GetByToken(storeVm.Token);

            var store = new Stores
            {
                UserId      = userId.Id,
                Store_name  = storeVm.Store_name,
                Description = storeVm.Description,
                Type        = storeVm.Type
            };

            _storesRepository.Add(store);
            return(Ok(new { success = true, message = "Новый магазин успешно создан" }));
        }
Example #4
0
        public async Task AddProductCustom(string name, string brand, double quantity, string unitOfMeasurement, string storeName, double price)
        {
            Product product;

            if (!await Exists(name, brand, quantity, unitOfMeasurement))
            {
                Guid storeId;
                if (!await _storesRepository.Exists(storeName))
                {
                    Store store = Store.Create(storeName, "", "");
                    await _storesRepository.Add(store);

                    storeId = store.Id;
                }
                else
                {
                    storeId = (await _storesRepository.GetByName(storeName)).FirstOrDefault().Id;
                }

                int measurementSystem = (int)MeasureSystem.Undefined;
                if (unitOfMeasurementConversion.ContainsKey(unitOfMeasurement))
                {
                    measurementSystem = unitOfMeasurementConversion[unitOfMeasurement].Item2;
                }
                else
                {
                    measurementSystem = (int)MeasureSystem.Undefined;
                }

                product = Product.Create(name, brand, quantity, unitOfMeasurement, measurementSystem);
                await Add(product);

                Guid         productId = product.Id;
                ProductStore productStore;
                productStore = ProductStore.Create(productId, storeId, price);
                await _productStoresRepository.Add(productStore);
            }
        }