Example #1
0
        public async Task <IActionResult> Create(
            CreateDesafioViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var profId = _userService.Get_ProfesorId(User.Claims);
                    var res    = await _ctrlService
                                 .Create_Desafio(profId, model);

                    if (res)
                    {
                        this.SetAlerts("sucess-alerts",
                                       "Desafío creado Correctamente");
                        return(RedirectToAction("Index", "ProfesorDesafio"));
                    }
                    this.SetAlerts("error-alerts",
                                   "Error en la creación del desafío");
                }
                catch (ApplicationServicesException e)
                {
                    this.SetAlerts("error-alerts", e.Message);
                }
            }
            return(View(model));
        }
Example #2
0
 public async Task <IActionResult> AddChallenge([FromBody] CreateDesafioViewModel model)
 {
     return(await this.Post(ModelState, async() =>
     {
         var teacherId = _userService.Get_ProfesorId(User.Claims);
         return await _ctrlService.Create_Desafio(teacherId, model);
     }));
 }
Example #3
0
        public async Task <IActionResult> UploadDesafio()
        {
            string fileName
                = "Files/Temp/" + _fileManager.GetFilePath() + ".sb2";
            FormValueProvider formModel;
            var viewModel = new CreateDesafioViewModel();

            using (var stream = System.IO.File.Create(fileName))
            {
                formModel = await Request.StreamFile(stream);

                if (stream.Length > 0)
                {
                    viewModel.DirArchivo = fileName;
                }
            }

            var bindingSuccessful = await TryUpdateModelAsync(viewModel,
                                                              "", formModel);

            if (!bindingSuccessful)
            {
                _fileManager.DeleteFile(fileName);
                return(View("../Desafios/Create", viewModel));
            }
            var profesorId = _userService.Get_ProfesorId(User.Claims);
            var res        = (await _desafioService.Create_Desafio(profesorId,
                                                                   viewModel));

            if (res)
            {
                this.SetAlerts("success-alerts",
                               "El desafío se creó exitosamente");
            }
            else
            {
                this.SetAlerts("error-alerts",
                               "Error al crear el desafío");
            }
            return(RedirectToAction("Index", "ProfesorDesafio"));
        }