Пример #1
0
        public async Task <ActionResult <CompetenceAreaDto> > CreateCompetenceArea(CompetenceAreaDto vm)
        {
            var competenceArea = mapper.Map <CompetenceArea>(vm);

            competenceArea.Id = Guid.NewGuid().ToString();
            _context.CompetenceAreas.Add(competenceArea);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetCompetenceArea", new { id = competenceArea.Id }, mapper.Map <CompetenceAreaDto>(competenceArea)));
        }
Пример #2
0
        public async Task <IActionResult> UpdateCompetenceArea(string id, CompetenceAreaDto vm)
        {
            if (id != vm.Id)
            {
                return(BadRequest());
            }

            var competenceArea = await _context.CompetenceAreas.FindAsync(id);

            if (competenceArea == null)
            {
                return(NotFound());
            }

            competenceArea = mapper.Map(vm, competenceArea);

            _context.Update(competenceArea);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CompetenceAreaExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }