public async Task <IActionResult> Create([FromBody] MaterialResource model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Material material         = _mapper.Map <MaterialResource, Material>(model);
            var      materialResponse = await _materialService.CreateAsync(material, model.Description);

            if (!materialResponse.Success)
            {
                return(BadRequest(materialResponse.Message));
            }

            var simplyResponse = new
            {
                materialResponse.Extra.Id,
                materialResponse.Extra.AnnouncementId,
                materialResponse.Extra.Announcement.Description,
                materialResponse.Extra.GivenClassroomId,
                materialResponse.Extra.Hint,
                materialResponse.Extra.MaterialScale,
                materialType = materialResponse.Extra.MaterialType.Description(),
                materialResponse.Extra.Question
            };

            return(Ok(simplyResponse));
        }
Esempio n. 2
0
        public async Task <IActionResult> CreateMaterial([FromBody] MaterialDTO materialDTO)
        {
            try
            {
                await materialService.CreateAsync(materialDTO);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Esempio n. 3
0
 public async Task <IActionResult> Put([FromBody] MaterialDto material)
 {
     return(Success(await _materialService.CreateAsync(material)));
 }