public async Task CreateLaStrategyMethod(int laId, int strategyMethodId) { var laStrategyMethod = new LastrategyMethod { Laid = laId, StrategyMethodId = strategyMethodId }; context.LastrategyMethod.Add(laStrategyMethod); await context.SaveChangesAsync(); }
public async Task CreateLaTeachingAid(int laId, int teachingAidId, bool?teachingAidUser) { var laTeachingAid = new LateachingAid { Laid = laId, TeachingAidId = teachingAidId, LateachingAidUser = teachingAidUser }; context.LateachingAid.Add(laTeachingAid); await context.SaveChangesAsync(); }
/// <summary> /// Creates a new activity for a scenario with a given id with data /// passed in a learning activity binding model /// </summary> /// <param name="scenarioId"></param> /// <param name="model"></param> /// <returns>Id of newly created learning activity</returns> public async Task <int> CreateActivity(int scenarioId, LaBM model) { var ls = await context.Ls.FindAsync(scenarioId); if (ls == null) { throw new NotFoundException("Learning scenario not found."); } if (ls.UserId.ToString() != httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value) { logger.LogError($"Not authorized to view scenario with id { scenarioId }"); throw new NotAuthorizedException($"You are not authorized to view this resource."); } var la = mapper.Map <La>(model); la.Lsid = ls.Idls; la.Lagrade = ls.Lsgrade; la.Laduration = TimeSpan.FromMinutes(model.LadurationMinute); ls.Lsduration += la.Laduration; context.Update(ls); context.Add(la); await context.SaveChangesAsync(); foreach (var strategyMethod in model.StrategyMethods) { var strategyMethodId = await strategyMethodRepository.CreateStrategyMethod(strategyMethod); await laStrategyMethodRepository.CreateLaStrategyMethod(la.Idla, strategyMethodId); } foreach (var teachingAid in model.LaTeachingAidUser) { var taId = await teachingAidRepository.CreateTeachingAid(teachingAid); await laTeachingAidRepository.CreateLaTeachingAid(la.Idla, taId, true); } foreach (var teachingAid in model.LaTeachingAidTeacher) { var taId = await teachingAidRepository.CreateTeachingAid(teachingAid); await laTeachingAidRepository.CreateLaTeachingAid(la.Idla, taId, false); } await lsLaRepository.CreateLsLa(ls.Idls, la.Idla); return(la.Idla); }
public async Task CreateTeachingCorrelationSubjects(List <int> subjectIds, int lsId) { foreach (var subjectId in subjectIds) { if ((context.LscorrelationInterdisciplinarity.Where(x => x.Lsid == lsId && x.TeachingSubjectId == subjectId) != null)) { var lsCorrelation = new LscorrelationInterdisciplinarity { TeachingSubjectId = subjectId, Lsid = lsId }; context.LscorrelationInterdisciplinarity.Add(lsCorrelation); } } await context.SaveChangesAsync(); }
public async Task <int> CreateLearningOutcomeCts(List <string> loct) { var learningOutcomeCtString = ""; foreach (var lo in loct) { learningOutcomeCtString += lo + "||"; } LearningOutcomeCt learningSubject = null; if ((learningSubject = await curriculumDatabaseContext.LearningOutcomeCt.FirstOrDefaultAsync(x => x.LearningOutcomeCtstatement == learningOutcomeCtString)) == null) { var learningOutcomeCt = new LearningOutcomeCt { LearningOutcomeCtstatement = learningOutcomeCtString }; curriculumDatabaseContext.LearningOutcomeCt.Add(learningOutcomeCt); await curriculumDatabaseContext.SaveChangesAsync(); return(learningOutcomeCt.IdlearningOutcomeCt); } else { return(learningSubject.IdlearningOutcomeCt); } }
/// <summary> /// Creates new Ls (learning scenario) and its corresponding /// objects such as keywords, teachingcorrelationsubjects and learningoutcomes. /// </summary> /// <param name="model"></param> /// <returns>Id of newly created scenario</returns> public async Task <int> CreateScenario(LsBM model) { var ls = mapper.Map <Ls>(model); ls.UserId = httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; ls.LearningOutcomeCtid = await learningOutcomeCtRepository.CreateLearningOutcomeCts(model.LearningOutcomeCts); ls.LearningOutcomeSubjectId = await learningOutcomeSubjectRepository.CreateLearningOutcomeSubject(model.LearningOutcomeSubjects); ls.Lsduration = TimeSpan.Zero; context.Ls.Add(ls); await context.SaveChangesAsync(); await keywordRepository.CreateKeywords(model.Keywords, ls.Idls); await lsCorrelationRepository.CreateTeachingCorrelationSubjects(model.CorrelationSubjectIds, ls.Idls); logger.LogInformation($"Successfully created learning scenario with id { ls.Idls }"); return(ls.Idls); }
public async Task CreateKeywords(List <string> keywords, int lsId) { Keyword kwrd = null; foreach (var keyword in keywords) { if (null != (kwrd = context.Keyword.FirstOrDefault(x => x.KeywordName == keyword))) { } else { kwrd = new Keyword { KeywordName = keyword }; context.Keyword.Add(kwrd); await context.SaveChangesAsync(); } await CreateLsKeyword(kwrd.Idkeyword, lsId); } }
public async Task CreateLsLa(int lsId, int laId) { if (await context.Ls.FindAsync(lsId) == null) { throw new NotFoundException($"Scenario {lsId} does not exist."); } if (await context.La.FindAsync(laId) == null) { throw new NotFoundException($"Activity {laId} does not exist"); } var lsLa = new Lsla { Lsid = lsId, Laid = laId }; await context.Lsla.AddAsync(lsLa); await context.SaveChangesAsync(); }
public async Task <IActionResult> Register([FromBody] RegisterUserBM model) { // username validation if (await userManager.FindByNameAsync(model.Username) != null) { throw new BadRequestException($"A user with username { model.Username } already exists."); } // TO DO: Implement image model.ProfilePicture = null; var user = mapper.Map <User>(model); user.SecurityStamp = Guid.NewGuid().ToString(); user.RegistrationDate = DateTime.Now; var result = await userManager.CreateAsync(user, model.Password); if (result.Succeeded) { await userManager.AddToRoleAsync(user, "korisnik"); } await context.SaveChangesAsync(); return(Ok()); }
public async Task <int> CreateTeachingAid(TeachingAid model) { var teachingAid = await context.TeachingAid.FirstOrDefaultAsync(x => x.TeachingAidName == model.TeachingAidName); if (teachingAid != null) { return(teachingAid.IdteachingAid); } else { teachingAid = mapper.Map <CORE.Entities.TeachingAid>(model); context.TeachingAid.Add(teachingAid); await context.SaveChangesAsync(); return(teachingAid.IdteachingAid); } }
public async Task <int> CreateStrategyMethod(StrategyMethodBM model) { var strategyMethod = await context.StrategyMethod .FirstOrDefaultAsync(x => x.StrategyMethodName == model.StrategyMethodName); if (strategyMethod != null) { return(strategyMethod.IdstrategyMethod); } else { strategyMethod = mapper.Map <StrategyMethod>(model); context.StrategyMethod.Add(strategyMethod); await context.SaveChangesAsync(); } return(strategyMethod.IdstrategyMethod); }