Ejemplo n.º 1
0
        public IHttpActionResult Put([FromBody] TicketGames.API.Models.Order.Cart cart)
        {
            try
            {
                ClaimsPrincipal principal = Request.GetRequestContext().Principal as ClaimsPrincipal;

                long.TryParse(principal.Claims.Where(c => c.Type == "participant_Id").Single().Value, out this.participantId);

                Domain.Model.Cart domainCart = null;

                var key = string.Concat("Participant:Id:", this.participantId.ToString(), ":Cart");

                domainCart = CacheManager.GetObject <Domain.Model.Cart>(key);

                if (domainCart != null)
                {
                    var cartItem = domainCart.CartItems.Where(i => i.ProductId == cart.ProductId).First();

                    if (cart.Quantity > 0)
                    {
                        cartItem.Quantity = cart.Quantity;

                        CacheManager.StoreObject(key, domainCart, LifetimeProfile.Long);
                    }
                }

                return(Ok("Carrinho atualizado!"));
            }
            catch (Exception ex)
            {
                return(NotFound());
            }
        }
Ejemplo n.º 2
0
        public IHttpActionResult Get()
        {
            try
            {
                ClaimsPrincipal principal = Request.GetRequestContext().Principal as ClaimsPrincipal;

                long.TryParse(principal.Claims.Where(c => c.Type == "participant_Id").Single().Value, out this.participantId);

                if (participantId > 0)
                {
                    Domain.Model.Cart domainCart = null;

                    var key = string.Concat("Participant:Id:", this.participantId.ToString(), ":Cart");

                    domainCart = CacheManager.GetObject <Domain.Model.Cart>(key);

                    var cart = new List <TicketGames.API.Models.Order.Cart>();

                    if (domainCart != null)
                    {
                        cart = new TicketGames.API.Models.Order.Cart().CreateCart(domainCart);
                    }
                    else
                    {
                        domainCart = this._cartService.Get(this.participantId);

                        if (domainCart.Id > 0)
                        {
                            cart = new TicketGames.API.Models.Order.Cart().CreateCart(domainCart);

                            CacheManager.StoreObject(key, domainCart, LifetimeProfile.Long);
                        }
                    }

                    return(Ok(cart));
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (Exception ex)
            {
                return(NotFound());
            }
        }
Ejemplo n.º 3
0
        public IHttpActionResult Redemption(Order order)
        {
            try
            {
                #region Declarations of variables and objects

                long              orderId     = 0;
                string            session     = null;
                float             total       = 0;
                ClaimsPrincipal   principal   = Request.GetRequestContext().Principal as ClaimsPrincipal;
                Participant       participant = null;
                Domain.Model.Cart domainCart  = null;
                var     carts       = new List <TicketGames.API.Models.Order.Cart>();
                Account account     = new Account();
                var     transaction = new Domain.Model.Transaction();
                var     orderDomain = new Domain.Model.Order();


                #endregion

                long.TryParse(principal.Claims.Where(c => c.Type == "participant_Id").Single().Value, out participantId);

                if (this.participantId > 0)
                {
                    #region Get Participant

                    var participantKey = string.Concat("Participant:Id:", this.participantId.ToString(), ":Register");

                    participant = CacheManager.GetObject <Participant>(participantKey);

                    if (participant == null)
                    {
                        var result = this._participantService.GetParticipant(this.participantId);

                        participant = new Participant(result);
                    }


                    var domainParticipant = participant.MappingDomain();


                    #endregion

                    #region Get Cart

                    var cartKey = string.Concat("Participant:Id:", this.participantId.ToString(), ":Cart");

                    domainCart = CacheManager.GetObject <Domain.Model.Cart>(cartKey);

                    if (domainCart == null)
                    {
                        domainCart = this._cartService.Get(this.participantId);
                    }

                    var deliveryAddressResult = this._cartService.Get(this.participantId, domainCart.Id);

                    carts = new TicketGames.API.Models.Order.Cart().CreateCart(domainCart);

                    #endregion

                    #region Get Balance

                    var transactions = this._transactionService.GetTransactions(participantId);

                    if (transactions.Count > 0)
                    {
                        account = new Account().Balances(transactions);
                    }

                    #endregion

                    #region Get Session

                    var key = string.Concat("Participant:Id:", participantId.ToString(), ":Session");

                    session = CacheManager.GetObject <string>(key);

                    #endregion


                    #region Get Settings

                    var settingsKey = "Settings:Configuration";
                    List <Domain.Model.Configuration> settings = null;
                    settings = CacheManager.GetObject <List <Domain.Model.Configuration> >(settingsKey);

                    if (settings == null)
                    {
                        settings = this._configurationService.GetSettings();

                        if (settings != null && settings.Count > 0)
                        {
                            CacheManager.StoreObject(settingsKey, settings, LifetimeProfile.Longest);
                        }
                    }

                    #endregion

                    carts.ForEach(c =>
                                  total += c.Price * c.Quantity
                                  );

                    orderDomain.ParticipantId = this.participantId;

                    //Status de pedido criado
                    orderDomain.OrderStatusId = 4;

                    orderDomain.OrderHistory.Add(new Domain.Model.OrderHistory()
                    {
                        OrderStatusId = 4
                    });

                    orderDomain.Value = total;

                    orderDomain.Money = Convert.ToSingle(total - account.Balance);

                    foreach (var cart in carts)
                    {
                        orderDomain.OrderItems.Add(new Domain.Model.OrderItem()
                        {
                            ProductId = cart.ProductId,
                            RaffleId  = cart.RaffleId,
                            Value     = cart.Price,
                            Quantity  = cart.Quantity
                        });

                        orderDomain.CartId = cart.CartId;
                    }

                    switch (order.PaymentType)
                    {
                    case PaymentType.Point:
                    {
                        break;
                    }

                    case PaymentType.Billet:
                    {
                        orderDomain.PaymentType = "Billet";

                        if (account.Balance > 0)
                        {
                            transaction.ParticipantId     = this.participantId;
                            transaction.TransactionTypeId = 2;
                            transaction.Description       = "Fechamento do pedido {0}";
                            transaction.Value             = account.Balance;

                            orderDomain.Point       = account.Balance;
                            orderDomain.PaymentType = "Point + Billet";
                        }

                        var billet = new Domain.Model.Billet();

                        billet.Name       = participant.Name;
                        billet.CPF        = participant.CPF;
                        billet.SenderHash = order.SenderHash;
                        billet.Session    = session;

                        billet.Value = orderDomain.Money;

                        var paymentBillet = order.MappingBillet(domainParticipant, deliveryAddressResult, billet);

                        orderId = this._orderService.Redemption(paymentBillet, transaction, orderDomain, settings);

                        break;
                    }

                    case PaymentType.Credit:
                    {
                        orderDomain.PaymentType = "Credit";

                        if (account.Balance > 0)
                        {
                            transaction.ParticipantId     = this.participantId;
                            transaction.TransactionTypeId = 2;
                            transaction.Description       = "Fechamento do pedido {0}";
                            transaction.Value             = account.Balance;

                            orderDomain.Point       = account.Balance;
                            orderDomain.PaymentType = "Point + Credit";
                        }

                        var credit = new Domain.Model.Credit();

                        credit.Owner           = order.Card.Owner;
                        credit.SenderHash      = order.SenderHash;
                        credit.Brand           = order.Card.Brand;
                        credit.CreditCardToken = order.Card.CreditCardToken;
                        credit.Session         = session;

                        credit.Parcel = order.Card.Parcel.Quantity;
                        credit.Value  = order.Card.Parcel.Value;

                        var paymentCredit = order.MappingCredit(domainParticipant, domainCart, deliveryAddressResult, credit);

                        orderId = this._orderService.Redemption(paymentCredit, transaction, orderDomain);

                        break;
                    }

                    default: break;
                    }

                    if (orderId > 0)
                    {
                        CacheManager.KeyDelete(cartKey);
                    }


                    var pedido = order;
                }

                return(Ok(orderId));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Ejemplo n.º 4
0
        public IHttpActionResult GetInstallments(string brand)
        {
            try
            {
                ClaimsPrincipal principal = Request.GetRequestContext().Principal as ClaimsPrincipal;

                long.TryParse(principal.Claims.Where(c => c.Type == "participant_Id").Single().Value, out participantId);

                if (this.participantId > 0)
                {
                    #region Get Balance

                    Account account = new Account();

                    var result = this._transactionService.GetTransactions(participantId);

                    if (result.Count > 0)
                    {
                        account = new Account().Balances(result);
                    }

                    #endregion

                    #region Get Cart

                    Domain.Model.Cart domainCart = null;

                    var key = string.Concat("Participant:Id:", this.participantId.ToString(), ":Cart");

                    domainCart = CacheManager.GetObject <Domain.Model.Cart>(key);

                    if (domainCart == null)
                    {
                        domainCart = this._cartService.Get(this.participantId);
                    }

                    var carts = new List <TicketGames.API.Models.Order.Cart>();

                    carts = new TicketGames.API.Models.Order.Cart().CreateCart(domainCart);

                    #endregion

                    float total = 0;

                    carts.ForEach(c =>
                                  total += c.Price * c.Quantity
                                  );

                    Decimal money = Convert.ToDecimal(total - account.Balance);

                    var installments = this._orderService.Installments(money, brand, 12);

                    return(Ok(installments));
                }
                else
                {
                    return(BadRequest("Precisa está logado!"));
                }
            }
            catch (Exception ex)
            {
                return(NotFound());
            }
        }
Ejemplo n.º 5
0
        public IHttpActionResult Post([FromBody] TicketGames.API.Models.Order.Cart cart, bool addCart)
        {
            try
            {
                long cartId = 0;

                ClaimsPrincipal principal = Request.GetRequestContext().Principal as ClaimsPrincipal;

                long.TryParse(principal.Claims.Where(c => c.Type == "participant_Id").Single().Value, out this.participantId);

                Domain.Model.Cart domainCart = null;

                var key = string.Concat("Participant:Id:", this.participantId.ToString(), ":Cart");

                domainCart = CacheManager.GetObject <Domain.Model.Cart>(key);

                if (!addCart)
                {
                    if (domainCart != null)
                    {
                        domainCart.ParticipantId = this.participantId;

                        var cartItem = domainCart.CartItems.Where(x => x.ProductId == cart.ProductId);

                        if (cartItem.Count() > 0)
                        {
                            var item = cartItem.First();

                            if (cart.Quantity >= item.Quantity)
                            {
                                item.Quantity = cart.Quantity == item.Quantity ? item.Quantity + 1 : cart.Quantity + item.Quantity;
                            }
                            else if (cart.Quantity >= 0 && cart.Quantity < item.Quantity)
                            {
                                item.Quantity++;
                            }
                            else
                            {
                                item.Quantity++;
                            }
                        }
                        else
                        {
                            Domain.Model.CartItem item = new Domain.Model.CartItem();

                            var raffle = this._raffleService.GetRaffle(cart.ProductId);
                            item.ProductId = cart.ProductId;
                            item.Product   = raffle.Product;

                            raffle.Product = null;

                            item.RaffleId = raffle.Id;
                            item.Raffle   = raffle;
                            item.Quantity = cart.Quantity <= 0 ? 1 : cart.Quantity;

                            domainCart.CartItems.Add(item);
                        }

                        CacheManager.StoreObject(key, domainCart, LifetimeProfile.Long);
                    }
                    else
                    {
                        domainCart = new Domain.Model.Cart();

                        var raffle = this._raffleService.GetRaffle(cart.ProductId);

                        domainCart.ParticipantId = this.participantId;
                        domainCart.CartStatusId  = 2;
                        Domain.Model.CartItem cartItem = new Domain.Model.CartItem();

                        cartItem.ProductId = cart.ProductId;
                        cartItem.Product   = raffle.Product;

                        raffle.Product = null;

                        cartItem.RaffleId = raffle.Id;
                        cartItem.Raffle   = raffle;
                        cartItem.Quantity = cart.Quantity;

                        domainCart.CartItems.Add(cartItem);

                        CacheManager.StoreObject(key, domainCart, LifetimeProfile.Long);
                    }
                }
                else
                {
                    domainCart = this._cartService.Add(domainCart);

                    domainCart = this._cartService.Get(this.participantId);

                    foreach (var item in domainCart.CartItems)
                    {
                        item.Cart = null;
                        item.Product.CartItems = null;
                    }

                    cartId = domainCart.Id;

                    CacheManager.StoreObject(key, domainCart, LifetimeProfile.Long);
                }

                return(Ok(cartId));
            }
            catch (Exception ex)
            {
                return(NotFound());
            }
        }