Exemple #1
0
        public IActionResult GetAllForAdmin([FromBody] College_Dto collegeDto)
        {
            var department     = CollegeService.GetDepartmentsForCollegeId(collegeDto.IdCollege);
            var departmentDtos = Mapper.Map <IList <DepartmentDto> >(department);

            return(Ok(departmentDtos));
        }
        public IActionResult Create([FromBody] College_Dto collegeDto)
        {
            // map dto to entity
            var college = Mapper.Map <College>(collegeDto);

            try
            {
                // save
                Repository.Insert(college);
                return(Ok(college));
            }
            catch (Exception ex)
            {
                // return error message if there was an exception
                return(BadRequest(new { message = ex.Message }));
            }
        }
        public IActionResult Update(int id, [FromBody] College_Dto collegeDto)
        {
            // map dto to entity and set id
            var college = Mapper.Map <College>(collegeDto);

            college.IdCollege = id;

            try
            {
                // save
                Repository.Update(college);
                return(Ok(college));
            }
            catch (Exception ex)
            {
                // return error message if there was an exception
                return(BadRequest(new { message = ex.Message }));
            }
        }