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

            var major = await repository.GetMajor(id);

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

            mapper.Map <MajorResource, Major>(majorResource, major);

            repository.UpdateLecturers(major, majorResource);
            repository.UpdateProjects(major, majorResource);
            repository.UpdateGroups(major, majorResource);
            repository.UpdateStudents(major, majorResource);

            await unitOfWork.Complete();

            var result = mapper.Map <Major, MajorResource>(major);

            return(Ok(result));
        }