public async Task <IHttpActionResult> Post(TicketDTO value)
        {
            using (var dbcontext = unitOfWorkFactory.CreateUnitOfWork())
            {
                try
                {
                    await Task.Run(() => ticketsModel.DeleteTicket(value, dbcontext));
                }
                catch (DbUpdateConcurrencyException)
                {
                    return(Content(HttpStatusCode.Conflict, value));
                }

                return(Ok(value));
            }
        }
示例#2
0
        public void DeleteTicketTest()
        {
            // Arrange
            var  data = unitOfFactory.CreateTransactionalUnitOfWork();
            User user = new User()
            {
                Login    = "******",
                Password = "******",
                Tickets  = "1,2,3:1-14,15,16;1,1,3,3:1-24,25,26,27"
            };

            data.Users.Add(user);
            data.SaveChanges();
            DiscountsController discountController = new DiscountsController(unitOfFactory);
            var discountResult = discountController.GetDiscount(1);
            var discount       = (discountResult.Result as OkNegotiatedContentResult <DiscountDTO>).Content;
            Dictionary <DiscountDTO, int> dict = new Dictionary <DiscountDTO, int>();

            dict.Add(discount, 2);

            ConnectionPathDTO conPath = new ConnectionPathDTO();
            Connection        con     = data.Connections.Find(1);
            ConnectionDTO     conDTO  = Mapper.Map <Connection, ConnectionDTO>(con);
            ConnectionPart    conPart = new ConnectionPart
            {
                Connection = con,
                Id         = 9999999,
                Seats      = "1;2;3",
                FreeSeats  = 3,
                Route      = data.Routes.Find(1),
                StartTime  = DateTime.Now,
                EndTime    = DateTime.Now.AddMinutes(30)
            };

            data.ConnectionParts.Add(conPart);
            data.SaveChanges();
            conPath.ConnectionsParts = new List <ConnectionPartDTO> {
                Mapper.Map <ConnectionPart, ConnectionPartDTO>(conPart)
            };
            UserDTO   userDTO   = Mapper.Map <User, UserDTO>(data.Users.Where(u => u.Login == user.Login).First());
            TicketDTO ticketDTO = new TicketDTO()
            {
                Discounts      = dict,
                User           = userDTO,
                ConnectionPath = conPath,
                Seats          = new List <int[]> {
                    new int[] { 1, 3 }
                }
            };
            TicketsModel ticketsModel = new TicketsModel();

            data.SaveChanges();
            ticketsModel.BuyTicket(ticketDTO, data);

            //Act
            ticketsModel.DeleteTicket(ticketDTO, data);

            // Assert
            Assert.AreEqual("2;1;3", conPart.Seats);
            Assert.AreEqual("1,2,3:1-14,15,16;1,1,3,3:1-24,25,26,27", user.Tickets);
        }