Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="register"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public async Task <int> CreateAsync(Product register, CancellationTokenSource token)
        {
            B2CProduct newProduct = register.AdapterProduct();

            newProduct.IsActive = true;
            var result = await Repository.CreateAsync(newProduct, token);

            if (register.Images != null && register.Images.Any())
            {
                await ServiceImage.CreateAsync(register.Images, result, token);
            }
            return(result);
        }
Exemplo n.º 2
0
        public async Task <Boolean> UpdateAsync(B2CProduct entity, CancellationTokenSource token)
        {
            try
            {
                using (var connection = new SqlConnection(ConnectionString).EnsureOpen())
                {
                    var affectedRows = await connection.UpdateAsync("B2CProduct", entity, new QueryField("IdProduct", entity.IdProduct));

                    return(affectedRows > 0);
                }
            }
            catch (Exception exc)
            {
                token.Cancel(true);
                string mensaje = String.Format(MessagesInfraestructure.ErrorGetByKeyAsync, "en Repositorio base");
                throw new InfraestructureExcepcion(mensaje, exc);
            }
        }
Exemplo n.º 3
0
        public async Task <Int32> CreateAsync(B2CProduct entity, CancellationTokenSource cancellationToken)
        {
            try
            {
                using (var connection = new SqlConnection(ConnectionString).EnsureOpen())
                {
                    var id = await connection.InsertAsync <int>("B2CProduct", entity);

                    return(id);
                }
            }
            catch (Exception exc)
            {
                cancellationToken.Cancel(true);
                string mensaje = String.Format(MessagesInfraestructure.ErrorCreateAsync, "en Repositorio base");
                throw new InfraestructureExcepcion(mensaje, exc);
            }
        }
Exemplo n.º 4
0
        public async Task <bool> Update(Product product, CancellationTokenSource token)
        {
            bool exists = await Repository.ExistAsync(product.Id, token);

            if (exists)
            {
                B2CProduct updateProduct = product.AdapterProduct();
                var        result        = await Repository.UpdateAsync(updateProduct, token);

                if (product.Images != null && product.Images.Any())
                {
                    await ServiceImage.UpdateAsync(product.Images, token);
                }
                return(result);
            }
            else
            {
                string msg = String.Format(MessagesApplication.NotFoundCode, product.Id);
                throw new BussinesException(msg, null);
            }
        }
Exemplo n.º 5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="source"></param>
 /// <returns></returns>
 public static Product AdapterProduct(this B2CProduct source)
 {
     if (source == null)
     {
         return(null);
     }
     else
     {
         return new Product()
                {
                    Code        = source.Code,
                    Id          = source.IdProduct,
                    Name        = source.Name,
                    Description = source.Description,
                    IdCategory  = source.IdCategory,
                    IdProducer  = source.IdProducer,
                    IdProvider  = source.IdProvider,
                    ListPrice   = source.ListPrice,
                    IsActive    = source.IsActive,
                    Images      = source.B2CImage?.AsQueryable().AdapterImage().ToList()
                }
     };
 }
Exemplo n.º 6
0
 public void Delete(B2CProduct entity)
 {
     throw new NotImplementedException();
 }