예제 #1
0
        public Task <ExistProduct> AddAsync(NewProduct product, CancellationToken cancellationToken = default)
        {
            var existProduct = new ExistProduct(
                _GetFreeId(),
                product.Name,
                product.Description
                );

            _db.Add(existProduct.Id, existProduct);
            return(Task.FromResult(existProduct));
        }
예제 #2
0
        public async Task <ExistProduct> AddAsync(NewProduct product, CancellationToken cancellationToken)
        {
            var uri = this._filePathFactory.Invoke();
            var db  = await _reader.Invoke(uri, cancellationToken) ?? new List <ExistProduct>();

            var nextId = db.Any() ? db.Max(v => v.Id) + 1 : 1;
            var pr     = new ExistProduct(nextId, product.Name, product.Description);

            db.Add(pr);
            await _writer(uri, db, cancellationToken);

            return(pr);
        }