Ejemplo n.º 1
0
 /// <inheritdoc />
 public async System.Threading.Tasks.Task <bool> CreateAsync(string projectId, string problemId, Models.Bet.BetNew form)
 {
     return(await Task.FromResult(true));
 }
Ejemplo n.º 2
0
 /// <inheritdoc />
 public System.Threading.Tasks.Task <bool> CreateAsync(string projectId, string problemId, Models.Bet.BetNew form)
 {
     throw new HttpRequestException("Document not found", new System.Exception("Document not found"), System.Net.HttpStatusCode.NotFound);
 }
Ejemplo n.º 3
0
        public async System.Threading.Tasks.Task <ActionResult> PutAsync(string projectId, string problemId, Models.Bet.BetNew form)
        {
            try
            {
                // Checks we have a valid request.
                if (form == null || !ModelState.IsValid)
                {
                    return(this.BadRequest());
                }

                // Gets the problem and checks the project id is valid for it.
                // If the problem cannot be found it will throw a 404 exception.
                var problem = await this._problemService.GetAsync(projectId, problemId);

                if (problem.ProjectId != ProjectSpeedy.Services.Project.PREFIX + projectId)
                {
                    return(this.NotFound());
                }

                // Ensures we dont have a bets with the same name already
                if (problem.Bets.Any(p => p.Name.Trim().ToLower() == form.Name.Trim().ToLower()))
                {
                    return(BadRequest(new ProjectSpeedy.Models.General.BadRequest()
                    {
                        Message = "There is already a bet with the same name."
                    }));
                }

                // Try and add the bet.
                if (await this._betService.CreateAsync(projectId, problemId, form))
                {
                    return(this.Accepted());
                }

                // If we get here something has gone wrong.
                return(this.Problem());
            }
            catch (HttpRequestException e)
            {
                // Can we find the problem.
                if (e.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    return(NotFound());
                }

                // There has been a problem loading or saving data.
                this._logger.LogError(e, e.Message);
                return(this.Problem());
            }
            catch (Exception e)
            {
                this._logger.LogError(e, e.Message);
                return(this.Problem());
            }
        }
Ejemplo n.º 4
0
        /// <inheritdoc />
        public async System.Threading.Tasks.Task <bool> CreateAsync(string projectId, string problemId, Models.Bet.BetNew form)
        {
            // The new project object
            var newBet = new ProjectSpeedy.Models.Bet.Bet()
            {
                Name            = form.Name,
                Description     = form.Description,
                SuccessCriteria = form.SuccessCriteria,
                Created         = DateTime.UtcNow,
                ProjectId       = Project.PREFIX + projectId,
                ProblemId       = Problem.PREFIX + problemId,
                Status          = "Created"
            };

            // Creates the project and checks if the id is returned.
            var newId = await this._serviceBase.DocumentCreate(newBet, Bet.PARTITION);

            return(!string.IsNullOrWhiteSpace(newId));
        }
Ejemplo n.º 5
0
 /// <inheritdoc />
 public System.Threading.Tasks.Task <bool> CreateAsync(string projectId, string problemId, Models.Bet.BetNew form)
 {
     throw new System.Exception("Exception");
 }