Example #1
0
        public async Task <ProductDto> CreateAsync(ProductDto productDto)
        {
            var product = _mapper.Map <Product>(productDto);

            if (productDto.SupplierId != null && (await _uow.Suppliers.GetByIdAsync((int)productDto.SupplierId)) == null)
            {
                throw new DbQueryResultNullException("The supplier with current SupplierId doesn't exist");
            }

            if (productDto.BrandId != null && (await _uow.Brands.GetByIdAsync((int)productDto.BrandId)) == null)
            {
                throw new DbQueryResultNullException("The supplier with brand BrandId doesn't exist");
            }

            if (productDto.CategoryId != null && (await _uow.Categories.GetByIdAsync((int)productDto.CategoryId)) == null)
            {
                throw new DbQueryResultNullException("The supplier with current CategoryId doesn't exist");
            }

            await _uow.Products.CreateAsync(product);

            if (!await _uow.SaveChangesAsync())
            {
                throw new DbQueryResultNullException("Changes to products weren't produced");
            }

            return(_mapper.Map <ProductDto>(product));
        }
Example #2
0
        public async Task <CategoryDto> CreateAsync(CategoryDto categoryDto)
        {
            var category = _mapper.Map <Category>(categoryDto);

            await _uow.Categories.CreateAsync(category);

            if (!await _uow.SaveChangesAsync())
            {
                throw new DbQueryResultNullException("Changes to categories weren't produced");
            }

            return(_mapper.Map <CategoryDto>(category));
        }
Example #3
0
        public async Task <SupplierDto> CreateAsync(SupplierDto supplierDto)
        {
            var supplier = _mapper.Map <Supplier>(supplierDto);

            await _uow.Suppliers.CreateAsync(supplier);

            if (!await _uow.SaveChangesAsync())
            {
                throw new DbQueryResultNullException("Changes to suppliers weren't produced");
            }

            return(_mapper.Map <SupplierDto>(supplier));
        }
        public async Task <BrandDto> CreateAsync(BrandDto brandDto)
        {
            var brand = _mapper.Map <Brand>(brandDto);

            await _uow.Brands.CreateAsync(brand);

            if (!await _uow.SaveChangesAsync())
            {
                throw new DbQueryResultNullException("Changes to brands weren't produced");
            }

            return(_mapper.Map <BrandDto>(brand));
        }
        public async Task RegisterUser(NewUserViewModel newUserViewModel, CancellationToken token = default)
        {
            var v = new ValidationContext(newUserViewModel);

            Validator.ValidateObject(newUserViewModel, v);

            var userList = await this.userRepo.ListAsync(new UserExistsQuery(newUserViewModel.Username));

            if (userList.Count > 0)
            {
                throw new ValidationException("This user name already exists");
            }
            else
            {
                var user = newUserViewModel.CreateUser();
                await this.userRepo.AddAsync(user, token);

                await uow.SaveChangesAsync(token);
            }
        }
        public async Task AddUrl(string urlToCheck, string connectionId)
        {
            var url = CheckUrl(urlToCheck);

            if (url == null)
            {
                return;
            }
            var siteMapurl = GetSiteMapUrl(url);
            var list       = GetUriList(siteMapurl);

            var domain = GetDomain(url);
            var tTime  = GeTestTime(domain);

            await _uow.SaveChangesAsync();

            _handler.Domain       = domain;
            _handler.tTime        = tTime;
            _handler.ConnectionId = connectionId;

            if ((list is null) || list.Any())
            {
                await MasureAndSendResponseTimeLinksFromScraping(url);
            }
Example #7
0
 public async Task SaveChangesAsync()
 {
     await _uow.SaveChangesAsync();
 }