コード例 #1
0
 public async Task Put(string id, Dtos.Project dto)
 => await _projects.ReplaceOneAsync(
     Builders <Entities.Project> .Filter.Eq(x => x.Id, id),
     _mapper.Map <Entities.Project>(dto, opts =>
                                    opts.AfterMap((src, dest) => ((Entities.Project)dest).Id = id)),
     new UpdateOptions
 {
     IsUpsert = true
 }
     );
コード例 #2
0
        public async Task <IActionResult> Put(string id, [FromBody] Dtos.Project dto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await _projects.Put(id, dto);

            return(CreatedAtAction("Get", new { id }));
        }
コード例 #3
0
        public async Task <IActionResult> Post([FromBody] Dtos.Project dto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var id = new SlugHelper().GenerateSlug(dto.Name);

            // check if id exists
            if (await _projects.Get(id) != null)
            {
                return(StatusCode(409,
                                  $"A Project with id: {id} already exists. " +
                                  "Specify an explicit id to create a new Project, " +
                                  "or PUT a payload at the id to update the existing Project"));
            }

            await _projects.Put(id, dto);

            return(Created(Url.Action("Get", new { id }), new { id }));
        }