示例#1
0
        public Guid?CreateTour(TourPostDto dto)
        {
            var isTourExist = Session.QueryOver <TourModel>()
                              .Where(Restrictions.InsensitiveLike(Projections.Property <TourModel>(t => t.Name), dto.Name))
                              .Future().Any();
            PlayerModel player = null;

            if (dto.CreatorId != null)
            {
                player = Session.Get <PlayerModel>(dto.CreatorId);
                if (player == null)
                {
                    return(null);
                }
            }
            if (isTourExist)
            {
                return(null);
            }
            var course = Session.Get <CourseModel>(dto.CourseId);

            if (course == null)
            {
                return(null);
            }

            var tour = dto.ToEntity(player, course);

            using (var transaction = Session.BeginTransaction())
            {
                Session.Save(tour);
                transaction.Commit();
            }
            return(tour.Id);
        }
        public IHttpActionResult Post(TourPostDto dto)
        {
            var response = _tourRepository.CreateTour(dto);

            if (response == null)
            {
                return(Created(Request.RequestUri, response));
            }
            return(BadRequest());
        }
示例#3
0
        public static TourModel ToEntity(this TourPostDto dto, PlayerModel creator, CourseModel course)
        {
            var tour = new TourModel
            {
                Name        = dto.Name,
                Description = dto.Description,
                Creator     = creator,
                Games       = dto.Games.Select(g => g.ToEntity(creator, course, new CardModel
                {
                    IsGatheringCard = true
                })).ToList()
            };

            return(tour);
        }