コード例 #1
0
        public ActionResult Post(ReservationDto dto)
        {
            var validationMsg = Validator.Validate(dto);

            if (validationMsg != "")
            {
                return(BadRequest(validationMsg));
            }

            var reservation = Mapper.Map(dto);
            var id          = MaîtreD.TryAccept(reservation);

            if (id == null)
            {
                return(StatusCode(
                           StatusCodes.Status500InternalServerError,
                           "Couldn't accept."));
            }
            return(Ok(id.Value));
        }
コード例 #2
0
        public IHttpActionResult Post(ReservationDto reservationDto)
        {
            DateTime requestedDate;

            if (!DateTime.TryParse(reservationDto.Date, out requestedDate))
            {
                return(this.BadRequest("Invalid date."));
            }

            var reservedSeats =
                this.Repository.ReadReservedSeats(requestedDate);

            if (this.Capacity < reservationDto.Quantity + reservedSeats)
            {
                return(this.StatusCode(HttpStatusCode.Forbidden));
            }

            this.Repository.SaveReservation(requestedDate, reservationDto);

            return(this.Ok());
        }
コード例 #3
0
        public virtual void SaveReservation(
            DateTime dateTime,
            ReservationDto reservationDto)
        {
            const string sql = @"
                INSERT INTO [dbo].[Reservations] ([Date], [Name], [Email], [Quantity])
                VALUES (@Date, @Name, @Email, @Quantity)";

            using (var cmd = new SqlCommand(sql, this.lazyConn.Value))
            {
                cmd.Parameters.Add(
                    new SqlParameter("@Date", reservationDto.Date));
                cmd.Parameters.Add(
                    new SqlParameter("@Name", reservationDto.Name));
                cmd.Parameters.Add(
                    new SqlParameter("@Email", reservationDto.Email));
                cmd.Parameters.Add(
                    new SqlParameter("@Quantity", reservationDto.Quantity));

                cmd.ExecuteNonQuery();
            }
        }
コード例 #4
0
        public ActionResult Post(ReservationDto dto)
        {
            var validationMsg = Validator.Validate(dto);

            if (validationMsg != "")
            {
                return(BadRequest(validationMsg));
            }

            var reservation  = Mapper.Map(dto);
            var reservations = Repository.ReadReservations(reservation.Date);

            var accepted = maîtreD.CanAccept(reservations, reservation);

            if (!accepted)
            {
                return(StatusCode(
                           StatusCodes.Status500InternalServerError,
                           "Couldn't accept."));
            }
            var id = Repository.Create(reservation);

            return(Ok(id));
        }