public JsonResult Create(CreateParticipant command)
        {
            command.Id = Guid.NewGuid();

            Domain.Dispatcher.SendCommand(command);

            return(Json(command));
        }
        public HttpResponseMessage Put(int agreementId, int establishmentId, [FromBody] AgreementParticipantApiModel model)
        {
            model.AgreementId = agreementId;
            model.EstablishmentId = establishmentId;
            var command = new CreateParticipant(User, agreementId, establishmentId);
            Mapper.Map(model, command);

            _createHandler.Handle(command);

            var response = Request.CreateResponse(HttpStatusCode.OK, "Agreement participant was successfully created.");
            return response;
        }
        public HttpResult Post(CreateParticipant request)
        {
            var participant = new Participant().PopulateWith(request.SanitizeDtoHtml());

            try
            {
                // Check to see if crawler is already part of the leaue
                Get(new FetchParticipantStatus
                {
                    CrawlerId = request.CrawlerId,
                    SeasonId = request.SeasonId
                });

                throw new HttpError(HttpStatusCode.Conflict,
                    new ArgumentException("CrawlerId {0} already belongs to this season. ".Fmt(request.CrawlerId)));
            }
            catch (HttpError ex)
            {
                if (ex.StatusCode != HttpStatusCode.NotFound)
                    throw;
            }

            var crawlerResp = ResolveService<CrawlerService>().Get(new FetchCrawler { Id = request.CrawlerId });
            var seasonResp = ResolveService<SeasonService>().Get(new FetchSeason { Id = request.SeasonId });

            participant.Id = crawlerResp.Crawler.Id;
            participant.DivisionId = crawlerResp.Crawler.DivisionId;

            if (!seasonResp.Season.Active)
                throw new HttpError(HttpStatusCode.BadRequest,
                    new ArgumentException("Season {0} is not currently active.".Fmt(seasonResp.Season.Id)));

            // Validate .rc file for the server
            var serverResp = ResolveService<ServerService>().Get(new FetchServer { Id = crawlerResp.Crawler.ServerId });

            if (!_validator.ValidateRcInit(
                    new Uri(serverResp.Server.PlayerRcUrl(seasonResp.Season.CrawlVersion, crawlerResp.Crawler.UserName))))
                throw new HttpError(HttpStatusCode.Forbidden,
                    new ArgumentException(
                        "UserName {0} does not have a valid .rc file. ".Fmt(crawlerResp.Crawler.UserName)));

            var newId = Db.Insert(participant, selectIdentity: true);

            return
                new HttpResult(new ParticipantStatusResponse
                {
                    ParticipantStatus =
                        Get(new FetchParticipantStatus
                        {
                            CrawlerId = request.CrawlerId,
                            SeasonId = request.SeasonId
                        })
                            .ParticipantStatus
                })
                {
                    StatusCode = HttpStatusCode.Created,
                    Headers =
                    {
                        {HttpHeaders.Location, Request.AbsoluteUri.CombineWith(newId)}
                    }
                };
        }