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 <bool> Create_Desafio(int profId,
                                         CreateDesafioViewModel model)
 {
     try
     {
         _data.AddDesafio(model.Map(profId));
         return(await _data.SaveAllAsync());
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw new ApplicationServicesException(
                   "Error en la creación de desafío");
     }
 }
Example #4
0
        public async Task <ApiResult <bool> > Create_Desafio(int profId,
                                                             CreateDesafioViewModel model)
        {
            var result = ApiResult <bool> .Initialize(false);

            try
            {
                _data.AddDesafio(model.Map(profId));
                result.Value = await _data.SaveAllAsync();

                result.Success = result.Value;
                return(result);
            }
            catch (Exception e)
            {
                result.AddError("", "Error en la creación de desafío");
                return(result);
            }
        }
Example #5
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"));
        }