示例#1
0
        // Método que inserta una compra

        private void btInsertBuy_Click(object sender, EventArgs e)
        {
            bool isValid = ValidateField();

            if (isValid)
            {
                BuyTicket buyTicket = new BuyTicket()
                {
                    Amount        = Convert.ToDecimal(this.txtInsertAmount.Text),
                    Price         = Convert.ToDecimal(this.txtInsertTotal.Text),
                    BuyTicketDate = DateTime.Parse(this.dtDateIn.Text),
                    BuyTicketId   = Guid.NewGuid(),
                    Products      = _products,
                    SupplierId    = new Guid(this.SupplierId.Text),
                    UserId        = new Guid(this.UserId.Text)
                };

                bool hasBeenInserted = BussinesBuy.InsertTicket(buyTicket);

                if (hasBeenInserted)
                {
                    CleanFieldsInserted();
                    MessageBox.Show("Compra insertada correctamente");
                    this.dtBuyTickets.DataSource = BussinesBuy.GetAllBuyTickets().ToList();
                }
                else
                {
                    MessageBox.Show("Error al insertar compra");
                }
            }
        }
示例#2
0
        public string DispatchCommand(string[] commandParameters)
        {
            string command = commandParameters[0].ToLower();

            string result = "";

            switch (command)
            {
            case "exit": result = ExitCommand.Execute();
                break;

            case "print-info": result = PrintInfo.Execute(commandParameters);
                break;

            case "buy-ticket": result = BuyTicket.Execute(commandParameters);
                break;

            case "publish-review": result = PublishReview.Execute(commandParameters);
                break;

            case "print-reviews": result = PrintReviews.Execute(commandParameters);
                break;

            case "change-trip-status": result = ChangeTripStatus.Execute(commandParameters);
                break;

            default:
                break;
            }

            return(result);
        }
示例#3
0
        // Método privado para confirmar una inserción

        private static bool HasBeenInserted(Guid buyTicketInserted)
        {
            using (Model _context = new Model())
            {
                BuyTicket buyTicket = _context.BuyTickets.Find(buyTicketInserted);
                if (buyTicket != null)
                {
                    return(true);
                }

                return(false);
            }
        }
示例#4
0
        // Método para registrar una nueva compra

        public static bool InsertTicket(BuyTicket buyticket)
        {
            try
            {
                using (Model _context = new Model())
                {
                    var virtualTicket = new BuyTicket
                    {
                        Amount        = buyticket.Amount,
                        BuyTicketDate = buyticket.BuyTicketDate,
                        BuyTicketId   = buyticket.BuyTicketId,
                        Price         = buyticket.Price,
                        SupplierId    = buyticket.SupplierId,
                        UserId        = buyticket.UserId
                    };
                    _context.BuyTickets.Add(virtualTicket);
                    _context.SaveChanges();
                    foreach (var item in buyticket.Products)
                    {
                        _context.Stocks.Add(new Stock {
                            BuyTicketId = buyticket.BuyTicketId, DateIn = buyticket.BuyTicketDate, DateOut = null, ProductId = item.ProductId, SellTicketId = null, StockId = Guid.NewGuid()
                        });
                        Product product = _context.Products.Find(item.ProductId);
                        if (product != null)
                        {
                            product.Quantity++;
                        }
                        _context.SaveChanges();
                    }
                }

                if (HasBeenInserted(buyticket.BuyTicketId))
                {
                    return(true);
                }

                return(false);
            }
            catch (DbEntityValidationException e)
            {
                return(false);

                throw new DbEntityValidationException(e.ToString());
            }
            catch (Exception e)
            {
                return(false);

                throw new Exception(e.ToString());
            }
        }
示例#5
0
        public bool Delete(int?Id)
        {
            var       result       = 0;
            BuyTicket getBuyTicket = Get(Id);

            getBuyTicket.IsDelete   = true;
            getBuyTicket.DeleteDate = DateTimeOffset.Now.LocalDateTime;
            result = myContext.SaveChanges();

            if (result > 0)
            {
                status = true;
            }
            return(status);
        }
示例#6
0
        public ActionResult Buy(BuyTicket buyTicket)
        {
            if (buyTicket.TranType == 1)
            {
                buyTicket.TranType = (int)Statuses.TranType.HoldPayment;
            }
            else
            {
                buyTicket.TranType = (int)Statuses.TranType.InstantPayment;
            }
//            buyTicket.UserId = WebSecurity.GetUserId(User.Identity.Name);
            Ticket ticket = unitOfWork.TicketRepository.Get(u => u.TicketId == buyTicket.TicketId).FirstOrDefault();

            if (ModelState.IsValid)
            {
                Ticket newticket = new Ticket()
                {
                    TicketId     = buyTicket.TicketId,
                    TranUserId   = WebSecurity.GetUserId(User.Identity.Name),
                    TranFullName = buyTicket.TranFullName,
                    TranAddress  = buyTicket.TranAddress,
                    TranType     = buyTicket.TranType,
//                    TranStatus = (int)Statuses.Transaction.Unpaid,
                    EventId           = ticket.EventId,
                    UserId            = ticket.UserId,
                    SeriesNumber      = ticket.SeriesNumber,
                    SellPrice         = ticket.SellPrice,
                    ReceiveMoney      = ticket.ReceiveMoney,
                    ShippingCost      = shippingcost, // tien ship minh thu
                    Seat              = ticket.Seat,
                    Status            = ticket.Status,
                    AdminModifiedDate = ticket.AdminModifiedDate,
                    Description       = ticket.Description,
                    CreatedDate       = ticket.CreatedDate,
                    TranCreatedDate   = DateTime.Now,
                    TranModifiedDate  = DateTime.Now,
                    TranDescription   = buyTicket.TranDescription
                };
                this.unitOfWork.TicketRepository.AddOrUpdate(newticket);
                this.unitOfWork.Save();
                return(RedirectToAction("Checkout", "CheckOut", new { Id = newticket.TicketId }));
            }
            return(View(buyTicket));
        }
        // GET: Ticket/Buy/5
        public ActionResult Buy(int id)
        {
            //int sessionId = id;
            Session session = _context.Sessions.Where(x => x.Id == id).FirstOrDefault();
            //Film film = _context.Films.GetById(session.FilmId);
            IEnumerable <Ticket> tickets   = _context.Tickets.Where(x => x.SessionId == id);
            IEnumerable <Seat>   seats     = _context.Seats.Where(x => x.HallId == session.HallId);
            IEnumerable <Seat>   freeSeats = seats.Where(x => !tickets.Select(t => t.SeatId).Contains(x.Id));

            BuyTicket ticket = new BuyTicket()
            {
                Session   = session,
                Film      = session.Film,
                Seats     = seats,
                FreeSeats = freeSeats
            };

            return(View(ticket));
        }
示例#8
0
        private async void Buy_Click(object sender, RoutedEventArgs e)
        {
            if (currentUser == null)
            {
                return;
            }
            if (LvTrip.SelectedItem == null)
            {
                return;
            }
            Trip      selectedTrip    = LvTrip.SelectedItem as Trip;
            BuyTicket buyTicketDialog = new BuyTicket(currentUser, selectedTrip);
            var       result          = await buyTicketDialog.ShowAsync();

            if (result == ContentDialogResult.Primary)
            {
                ClientService.BuyTicket(buyTicketDialog.Ticket);
            }
        }
示例#9
0
        // Método para eliminar una compra

        public static bool DeleteBuyTicket(Guid id)
        {
            try
            {
                using (Model _context = new Model())
                {
                    BuyTicket buyticket = _context.BuyTickets.Find(id);

                    if (buyticket != null)
                    {
                        var stock = _context.Stocks.Where(x => x.BuyTicketId.Equals(id)).ToList();

                        foreach (var item in stock)
                        {
                            _context.Stocks.Attach(item);
                            _context.Stocks.Remove(item);
                            _context.SaveChanges();
                            var product = _context.Products.Find(item.ProductId);
                            if (product != null)
                            {
                                product.Quantity--;
                            }
                        }

                        _context.BuyTickets.Attach(buyticket);
                        _context.BuyTickets.Remove(buyticket);
                        _context.SaveChanges();

                        return(true);
                    }

                    return(false);
                }
            }
            catch (Exception ex)
            {
                return(false);

                throw ex;
            }
        }
示例#10
0
        //Get: /
        public ActionResult Buy(int Id)
        {
            ViewBag.TicketId = Id;
            Ticket    getTicket   = unitOfWork.TicketRepository.GetById(Id);
            User      CurrentUser = unitOfWork.UserRepository.GetById(WebSecurity.CurrentUserId);
            BuyTicket buyTicket   = new BuyTicket()
            {
                TicketId     = getTicket.TicketId,
                UserId       = getTicket.UserId,
                SeriesNumber = getTicket.SeriesNumber,
                SellPrice    = getTicket.SellPrice,
                ReceiveMoney = getTicket.ReceiveMoney,
                ShippingCost = shippingcost,                               // tien ship cua minh lay
                Seat         = getTicket.Seat,
                Description  = getTicket.Description,
                EventName    = getTicket.Event.EventName,
                HoldDate     = getTicket.Event.HoldDate,
                VenueName    = getTicket.Event.Venue.VenueName,
                TranFullName = CurrentUser.FullName,
                TranAddress  = CurrentUser.Address
            };

            return(View(buyTicket));
        }
示例#11
0
 public async Task <IActionResult> Post(BuyTicket command)
 => await SendAsync <BuyTicket>(command.BindId(cmd => cmd.Id)
                                .BindUserIdentity(cmd => cmd.CustomerId, User?.Identity?.Name),
                                resourceId : command.Id, resource : "tickets");