public async Task <IActionResult> AddDesafio(AddDesafioViewModel model) { if (ModelState.IsValid) { try { var profId = _userService.Get_ProfesorId(User.Claims); var res = await _ctrlService .Add_DesafioCurso(profId, model); if (res) { this.SetAlerts("success-alerts", "El desafío se agregó exitosamente"); } else { this.SetAlerts("error-alerts", "No se pudo agregar el desafío"); } } catch (ApplicationServicesException e) { this.SetAlerts("error-alerts", e.Message); } } return(RedirectToAction("Details", "ProfesorCurso", new { idCurso = model.Id })); }
public async Task <bool> Add_DesafioCurso(int profId, AddDesafioViewModel model) { try { if (!await Do_validateProfesor(profId, model.Id)) { return(false); } if (await _data.Exist_Desafio(model.DesafioId, model.Id)) { throw new ApplicationServicesException( "El desafío ya se encuentra en el curso"); } var desafio = await _data.Find_Desafio(model.DesafioId); var profesor = await _data .Find_Profesor(desafio.ProfesorId); _data.AddDesafio(model.Id, desafio); if (profId != profesor.Id) { _data.Do_PushNotification( NotificationType.NotificationDesafioUsado, profesor.UsuarioId, new Dictionary <string, string>() { ["IdDesafio"] = $"{desafio.Id}", ["NombreDesafio"] = $"{desafio.Nombre}" }); } return(await _data.SaveAllAsync()); } catch (Exception e) { Console.WriteLine(e); throw new ApplicationServicesException( "Error en la creación de desafío", e); } }