Exemplo n.º 1
0
 public async Task<IHttpActionResult> GetSkill(int id)
 {
     Skill b = await db.Skills.FindAsync(id);
     if (b == null)
     {
         return NotFound();
     }
     SkillDTO skill = new SkillDTO
     {
         skill_id = b.Id,
         skill_name = b.skill
     };
     return Ok(skill);
 }
Exemplo n.º 2
0
        public async Task<IHttpActionResult> PutSkill(SkillDTO skill_data)
        {
            string reg = User.Identity.GetUserId();
            Student student = await db.Students.FirstAsync(b => b.registrationId == reg);
            if (student == null)
            {
                return StatusCode(HttpStatusCode.Forbidden);
            }
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (!SkillExists(skill_data.skill_id))
            {
                return BadRequest();
            }
            Skill skill=  new Skill()
            {
                skill = skill_data.skill_name,
                studentId = student.Id,
                Id = skill_data.skill_id
            };
            db.Entry(skill).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SkillExists(skill_data.skill_id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.OK);
        }