Exemplo n.º 1
0
        public async Task <IActionResult> PutAcademicStaff([FromRoute] int id, [FromBody] AcademicStaff academicStaff)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != academicStaff.AcademicStaffId)
            {
                return(BadRequest());
            }

            _context.Entry(academicStaff).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AcademicStaffExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            academicStaff = _context.AcademicStaffs.Include(e => e.Department).FirstOrDefault(e => e.AcademicStaffId == academicStaff.AcademicStaffId);
            return(Ok(academicStaff));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PostAcademicStaff([FromBody] AcademicStaff academicStaff)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.AcademicStaffs.Add(academicStaff);
            await _context.SaveChangesAsync();

            academicStaff = _context.AcademicStaffs.Include(e => e.Department).FirstOrDefault(e => e.AcademicStaffId == academicStaff.AcademicStaffId);
            return(CreatedAtAction("GetAcademicStaff", new { id = academicStaff.AcademicStaffId }, academicStaff));
        }
        /// <summary>
        /// Converts a list from Pure PersonsResponse.Person to CMS AcademicStaff
        /// </summary>
        /// <param name="persons"></param>
        /// <returns></returns>
        static List <AcademicStaff> ConvertPersonsToAcademicStaff(List <PersonsResponse.Person> persons)
        {
            var staff = new List <AcademicStaff>();

            foreach (var person in persons)
            {
                var member = new AcademicStaff
                {
                    Id        = person.Id,
                    Title     = person.Title,
                    FirstName = person.FirstName,
                    LastName  = person.LastName,
                    Email     = person.Email
                };
                staff.Add(member);
            }
            return(staff);
        }