예제 #1
0
        public IHttpActionResult PostTicket(TicketHelpModel thm)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (thm.Ticket.Name != null && thm.Ticket.Name != "")
            {
                if (thm.Ticket.TicketTypeId != 1)
                {
                    return(Content(HttpStatusCode.BadRequest, "Only signedIn users can buy this type of ticket!"));
                }
            }
            else
            {
                ApplicationUser appu = UserManager.FindById(thm.Ticket.ApplicationUserId);
                if ((appu.Activated == "NOT ACTIVATED" || appu.Activated == "PENDING") && thm.Ticket.TicketTypeId != 1)
                {
                    return(Content(HttpStatusCode.BadRequest, "Only authorized users can buy this type of ticket!"));
                }
            }


            try
            {
                Ticket t = new Ticket();
                t.PurchaseTime   = thm.Ticket.PurchaseTime;
                t.TicketPricesId = unitOfWork.TicketPrices.Get(thm.Ticket.TicketPricesId).Id;

                t.TicketTypeId = unitOfWork.TicketTypes.Get(thm.Ticket.TicketTypeId.GetValueOrDefault()).Id;

                t.PayPalId = unitOfWork.PayPals.GetPayPal(thm.PayementId);

                t.Name = "Karta";
                if (thm.Ticket.ApplicationUserId != null && thm.Ticket.ApplicationUserId != "")
                {
                    t.ApplicationUserId = UserManager.FindById(thm.Ticket.ApplicationUserId).Id;
                }



                unitOfWork.Tickets.Add(t);
                unitOfWork.Complete();
                return(Ok(t.Id));
            }
            catch (Exception ex)
            {
                return(NotFound());
            }
        }
예제 #2
0
        //GET: api/Tickets
        public IEnumerable <TicketHelpModel> GetTicketsForOneUser(string id)
        {
            ApplicationUser ap = UserManager.FindByEmail(id);
            PassengerType   pt = unitOfWork.PassengerTypes.Get((int)ap.PassengerTypeId);

            List <Ticket> lista = unitOfWork.Tickets.getAllTicketsWithUser(id).ToList();

            List <TicketHelpModel> ret = new List <TicketHelpModel>();

            foreach (Ticket t in lista)
            {
                TicketHelpModel st = new TicketHelpModel();
                st.PurchaseTime = t.PurchaseTime;
                double price = unitOfWork.TicketPrices.Get(t.TicketPricesId).Price;
                st.TicketPrice = price - (price * pt.Coefficient);
                st.TicketType  = unitOfWork.TicketTypes.Get((int)t.TicketTypeId).Name;
                DateTime d;
                if (t.TicketTypeId == 1)
                {
                    d = new DateTime(t.PurchaseTime.Value.Year, t.PurchaseTime.Value.Month, t.PurchaseTime.Value.Day,
                                     t.PurchaseTime.Value.Hour + 1, t.PurchaseTime.Value.Minute, 0);
                    st.ExparationTime = d.ToString();
                }
                if (t.TicketTypeId == 2)
                {
                    d = new DateTime(t.PurchaseTime.Value.Year, t.PurchaseTime.Value.Month, t.PurchaseTime.Value.Day + 1,
                                     0, 0, 0);
                    st.ExparationTime = d.ToString();
                }
                if (t.TicketTypeId == 3)
                {
                    if ((t.PurchaseTime.Value.Month < 8 && t.PurchaseTime.Value.Month % 2 == 0) || (t.PurchaseTime.Value.Month >= 8 && t.PurchaseTime.Value.Month % 2 != 0))
                    {
                        if (t.PurchaseTime.Value.Month == 2)
                        {
                            d = new DateTime(t.PurchaseTime.Value.Year, t.PurchaseTime.Value.Month, 28,
                                             0, 0, 0);
                        }
                        else
                        {
                            d = new DateTime(t.PurchaseTime.Value.Year, t.PurchaseTime.Value.Month, 30,
                                             0, 0, 0);
                        }
                    }
                    else
                    {
                        d = new DateTime(t.PurchaseTime.Value.Year, t.PurchaseTime.Value.Month, 31,
                                         0, 0, 0);
                    }
                    st.ExparationTime = d.ToString();
                }
                if (t.TicketTypeId == 4)
                {
                    d = new DateTime(t.PurchaseTime.Value.Year, 12, 31,
                                     0, 0, 0);
                    st.ExparationTime = d.ToString();
                }
                ret.Add(st);
            }
            return(ret);
        }