Beispiel #1
0
 public async Task <IActionResult> AddCourse([FromBody] CreateCursoViewModel model)
 {
     return(await this.Post(ModelState, async() => {
         var teacherId = _userService.Get_ProfesorId(User.Claims);
         return await _ctrlService.Create_Curso(teacherId, model);
     }));
 }
Beispiel #2
0
        public async Task <bool> Create_Curso(int profId,
                                              CreateCursoViewModel model)
        {
            var desafio = await _data
                          .Find_Desafio(model.DesafioId.GetValueOrDefault());

            if (desafio == null)
            {
                throw new ApplicationServicesException(
                          "Error en la creación del curso");
            }

            _data.AddCurso(model.Map(profId, desafio,
                                     _clrService.RandomColor));
            return(await _data.SaveAllAsync());
        }
Beispiel #3
0
        public async Task <ApiResult <bool> > Create_Curso(int profId,
                                                           CreateCursoViewModel model)
        {
            var result = ApiResult <bool> .Initialize(false);

            var desafio = await _data
                          .Find_Desafio(model.DesafioId.GetValueOrDefault());

            if (desafio == null)
            {
                result.AddError("", "Error en la creación del curso");
            }

            _data.AddCurso(model.Map(profId, desafio,
                                     _clrService.RandomColor));
            var res = await _data.SaveAllAsync();

            result.Value   = res;
            result.Success = res;
            return(result);
        }
Beispiel #4
0
        public async Task <IActionResult> Create(CreateCursoViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var profId = _userService.Get_ProfesorId(User.Claims);
                    var res    = await _ctrlService.Create_Curso(profId, model);

                    if (res)
                    {
                        this.SetAlerts("success-alerts",
                                       "El curso se creó exitosamente");
                        return(RedirectToAction("Cursos", "Profesor"));
                    }
                }
                catch (Exception e)
                {
                }
            }
            ModelState.AddModelError("", "Error en la creación del curso");
            return(View(model));
        }