public async Task <Int32> CreateAsync(Offer offer, CancellationTokenSource token)
        {
            B2COffer newOffer = offer.AdapterOffer();

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

            if (offer.Image != null)
            {
                await ServiceImage.CreateAsync(offer.Image, offer.IdProduct, result, token);
            }

            return(result);
        }
        public async Task <Int32> CreateAsync(B2COffer entity, CancellationTokenSource cancellationToken)
        {
            try
            {
                using (var connection = new SqlConnection(ConnectionString).EnsureOpen())
                {
                    var id = await connection.InsertAsync <int>("B2COffer", entity);

                    return(id);
                }
            }
            catch (Exception exc)
            {
                cancellationToken.Cancel(true);
                string mensaje = String.Format(MessagesInfraestructure.ErrorCreateAsync, "en Repositorio base");
                throw new InfraestructureExcepcion(mensaje, exc);
            }
        }
        public async Task <Boolean> UpdateAsync(B2COffer entity, CancellationTokenSource token)
        {
            try
            {
                using (var connection = new SqlConnection(ConnectionString).EnsureOpen())
                {
                    var affectedRows = await connection.UpdateAsync("B2COffer", entity, new QueryField("IdOffer", entity.IdOffer));

                    return(affectedRows > 0);
                }
            }
            catch (Exception exc)
            {
                token.Cancel(true);
                string mensaje = String.Format(MessagesInfraestructure.ErrorGetByKeyAsync, "en Repositorio base");
                throw new InfraestructureExcepcion(mensaje, exc);
            }
        }
        public async Task <bool> Update(Offer offer, CancellationTokenSource token)
        {
            bool exists = await Repository.ExistAsync(offer.Id, token);

            if (exists)
            {
                B2COffer updateOffer = offer.AdapterOffer();
                var      result      = await Repository.UpdateAsync(updateOffer, token);

                if (offer.Image != null)
                {
                    await ServiceImage.UpdateAsync(offer.Image, token);
                }
                return(result);
            }
            else
            {
                string msg = String.Format(MessagesApplication.NotFoundCode, offer.Id);
                throw new BussinesException(msg, null);
            }
        }
 public static Offer AdapterOffer(this B2COffer origin)
 {
     if (origin == null)
     {
         return(null);
     }
     else
     {
         return new Offer()
                {
                    Id          = origin.IdOffer,
                    IdProduct   = origin.IdProduct,
                    Name        = origin.Name,
                    Description = origin.Description,
                    BeginDate   = origin.BeginDate,
                    EndDate     = origin.EndDate,
                    Discount    = origin.Discount,
                    IsActive    = origin.IsActive,
                    Image       = origin.B2CImage?.AsQueryable().AdapterImage().First()
                }
     };
 }
 public void Delete(B2COffer entity)
 {
     throw new NotImplementedException();
 }