コード例 #1
0
        public Models.TicketPurchase CreateTicketPurchase(TicketPurchaseDto ticketPurchaseDto)
        {
            var person = _person.GetPersonByFirstNameLastNameAndAge(ticketPurchaseDto.FirstName,
                                                                    ticketPurchaseDto.LastName, ticketPurchaseDto.Age);
            var personId = new int();

            if (person == null)
            {
                var personDto = new PersonDto()
                {
                    FirstName = ticketPurchaseDto.FirstName,
                    LastName  = ticketPurchaseDto.LastName,
                    Age       = ticketPurchaseDto.Age
                };
                var newPerson = _person.CreatePerson(personDto);
                personId = newPerson.Id;
            }

            if (person != null)
            {
                personId = person.Id;
            }

            const string sql =
                "INSERT INTO SkiTickets.TicketPurchase VALUES (@ticketId, @personId, @sellingPointId, @date)" +
                "SELECT * FROM SkiTickets.TicketPurchase WHERE id = SCOPE_IDENTITY()";

            return(TransformDaoToBusinessLogicTicketPurchase(_database.QueryFirstOrDefault <TicketPurchaseDao>(sql, new
            {
                ticketId = ticketPurchaseDto.TicketId,
                personId = personId,
                sellingPointId = ticketPurchaseDto.SellingPointId,
                date = DateTime.Now
            })));
        }
コード例 #2
0
 public ActionResult <Models.TicketPurchase> CreateTicketPurchase(TicketPurchaseDto ticketPurchaseDto)
 {
     try
     {
         return(Created("https://localhost:5001/TicketPurchase", new OkResponse <Models.TicketPurchase>(_ticketPurchase.CreateTicketPurchase(ticketPurchaseDto))));
     }
     catch (NoCapacity e)
     {
         return(BadRequest());
     }
     catch (AgesNotMatchingException e)
     {
         return(BadRequest(new ErrorResponse(e.Message, new List <string>()
         {
             "age"
         })));
     }
     catch (SellingPointNotFoundException e)
     {
         return(BadRequest(new ErrorResponse(e.Message, new List <string>()
         {
             "sellingPoint"
         })));
     }
     catch (Exception e)
     {
         return(BadRequest(new ErrorResponse(e.Message, new List <string>()
         {
             "ticketPurchase"
         })));
     }
 }