Exemplo n.º 1
0
 public CardOfCredit(IBuyOnClick model)
 {
     if (model.InstantBuyKey != null && model.InstantBuyKey != new Guid())
     {
         InstantBuyKey = model.InstantBuyKey;
     }
 }
Exemplo n.º 2
0
        /// <exception cref="InvalidOperationException">Ocorre quando não há itens no pedido</exception>
        public void Buy(IBuyOnClick model)
        {
            var user = _context.UsersInfo.FindOrDefault(model.UserId);
            if (user == null)
                throw new InvalidOperationException("User not found");
            if (!user.InstantBuyKey.HasValue)
                throw new InvalidOperationException("You not have an card configution, you need sends  informations from card of credit");

            Contract.EndContractBlock();

            var request = SaveRequest(model);

            var card = new CardOfCredit(request.User.InstantBuyKey.Value);
            Buy(card, request, false);
        }
Exemplo n.º 3
0
        /// <exception cref="InvalidOperationException">Ocorre quando não há itens no pedido</exception>
        public void Buy(IBuyOnClick model)
        {
            var user = _context.UsersInfo.FindOrDefault(model.UserId);

            if (user == null)
            {
                throw new InvalidOperationException("User not found");
            }
            if (!user.InstantBuyKey.HasValue)
            {
                throw new InvalidOperationException("You not have an card configution, you need sends  informations from card of credit");
            }

            Contract.EndContractBlock();

            var request = SaveRequest(model);

            var card = new CardOfCredit(request.User.InstantBuyKey.Value);

            Buy(card, request, false);
        }
Exemplo n.º 4
0
        /// <exception cref="InvalidOperationException">Ocorre quando não há itens no pedido</exception>
        /// <returns></returns>
        private Request SaveRequest(IBuyOnClick model)
        {
            var noItens = (model == null || model.Itens.IsNullOrEmpty());

            Contract.EnsuresOnThrow <InvalidOperationException>(noItens, "Request need ticket(s)");

            _userFromRequest = _context.UsersInfo.FindOrDefault(model.UserId);
            Contract.EnsuresOnThrow <InvalidOperationException>(_userFromRequest == null, "Not found user selected");

            Contract.EndContractBlock();

            var itens = model.Itens
                        .Select(x => new RequestItem
            {
                EventId         = x.Id,
                PriceForRequest = x.Price,
                NumberOfItens   = x.Qtd
            }).ToArray();

            var request = new Request(itens)
            {
                UserId = model.UserId.ToString()
            };

            try
            {
                request.User = _userFromRequest;
                _context.Requests.Add(request);
                var result = _context.SaveChange();
                return(request);
            }
            catch (Exception ex)
            {
                ex.LogAndThrow();
                throw;
            }
        }
Exemplo n.º 5
0
 /// <summary>makes the purchase of tickets</summary>
 /// <param name="model">Request</param>
 /// <exception cref="InvalidOperationException">Ocorre quando não há itens no pedido</exception>
 public Task BuyAsync(IBuyOnClick model)
 {
     return(Task.Factory.StartNew(() => Buy(model)));
 }
Exemplo n.º 6
0
        /// <summary>makes the purchase of tickets</summary>
        /// <param name="model">Request</param>
        /// <exception cref="InvalidOperationException">Ocorre quando não há itens no pedido</exception>
        public Task BuyAsync(IBuyOnClick model)
        {
            return Task.Factory.StartNew(() => Buy(model));

        }
Exemplo n.º 7
0
        /// <exception cref="InvalidOperationException">Ocorre quando não há itens no pedido</exception>
        /// <returns></returns>
        private Request SaveRequest(IBuyOnClick model)
        {
            var noItens = (model == null || model.Itens.IsNullOrEmpty());
            Contract.EnsuresOnThrow<InvalidOperationException>(noItens, "Request need ticket(s)");

            _userFromRequest = _context.UsersInfo.FindOrDefault(model.UserId);
            Contract.EnsuresOnThrow<InvalidOperationException>(_userFromRequest == null, "Not found user selected");

            Contract.EndContractBlock();

            var itens = model.Itens
                .Select(x => new RequestItem
                {
                    EventId = x.Id,
                    PriceForRequest = x.Price,
                    NumberOfItens = x.Qtd
                }).ToArray();

            var request = new Request(itens) { UserId = model.UserId.ToString() };

            try
            {
                request.User = _userFromRequest;
                _context.Requests.Add(request);
                var result = _context.SaveChange();
                return request;
            }
            catch (Exception ex)
            {
                ex.LogAndThrow();
                throw;
            }
        }