Beispiel #1
0
        /// <inheritdoc />
        public async Task <bool> CreateAsync(Models.Project.ProjectNew form)
        {
            // The new project object
            var newProject = new ProjectSpeedy.Models.Project.ProjectNew()
            {
                Name        = form.Name,
                Created     = DateTime.UtcNow,
                Description = form.Description
            };

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

            return(!string.IsNullOrWhiteSpace(newId));
        }
        public async System.Threading.Tasks.Task <ActionResult> PutAsync(Models.Project.ProjectNew form)
        {
            try
            {
                // Checks we have a valid request.
                if (form == null || !ModelState.IsValid)
                {
                    return(BadRequest(new ProjectSpeedy.Models.General.BadRequest()
                    {
                        Message = "You are trying to submit an invalid form."
                    }));
                }

                // Gets all projects and checks that there is not one with the same name
                var projects = await this._projectServices.GetAll();

                if (projects.rows.Any(p => p.Name.Trim().ToLower() == form.Name.Trim().ToLower()))
                {
                    return(BadRequest(new ProjectSpeedy.Models.General.BadRequest()
                    {
                        Message = "There is already a project with the same name."
                    }));
                }

                // Try and add the project.
                if (await this._projectServices.CreateAsync(form))
                {
                    return(this.Accepted());
                }

                return(this.Problem());
            }
            catch (Exception e)
            {
                this._logger.LogError(e, e.Message);
                return(this.Problem());
            }
        }
Beispiel #3
0
 /// <inheritdoc />
 public async Task <bool> CreateAsync(Models.Project.ProjectNew form)
 {
     return(await Task.FromResult(true));
 }
Beispiel #4
0
 /// <inheritdoc />
 public Task <bool> CreateAsync(Models.Project.ProjectNew form)
 {
     throw new HttpRequestException("Document not found", new System.Exception("Document not found"), System.Net.HttpStatusCode.NotFound);
 }
 /// <inheritdoc />
 public Task <bool> CreateAsync(Models.Project.ProjectNew form)
 {
     return(Task.FromResult(false));
 }
 /// <inheritdoc />
 public Task <bool> CreateAsync(Models.Project.ProjectNew form)
 {
     throw new System.Exception("Exception");
 }