Exemplo n.º 1
0
        /// <summary>
        /// Zapisuje obiekt w najnowsze wersji
        /// </summary>
        /// <param name="syllabus"></param>
        /// <returns></returns>
        public async Task <Syllabus> Save(Syllabus syllabus, SyllabusManagerUser user)
        {
            Syllabus currentDocument = await _dbSet.Include(s => s.FieldOfStudy)
                                       .Include(s => s.Specialization)
                                       .Include(s => s.Description)
                                       .Include(s => s.SubjectDescriptions)
                                       .ThenInclude(sd => sd.Subject)
                                       .Include(s => s.PointLimits)
                                       .OrderByDescending(s => s.Version)
                                       .FirstOrDefaultAsync(s =>
                                                            s.FieldOfStudy.Code == syllabus.FieldOfStudy.Code &&
                                                            s.Specialization.Code == syllabus.Specialization.Code &&
                                                            s.AcademicYear == syllabus.AcademicYear &&
                                                            !s.IsDeleted);

            if (currentDocument is null)
            {
                syllabus.Version      = NewVersion();
                syllabus.CreationDate = DateTime.Now;
                syllabus.AuthorName   = user.Name;
            }
            else
            {
                if (!AreChanges(currentDocument, syllabus))
                {
                    return(syllabus);
                }
                syllabus.Version = IncreaseVersion(currentDocument.Version);
            }

            syllabus.Id = Guid.NewGuid();

            syllabus.SubjectDescriptions.ForEach(sd =>
            {
                sd.Id = Guid.NewGuid();
                if (sd.Subject != null)
                {
                    Data.Models.Subjects.Subject subj = _dbContext.Subjects.Find(sd.Subject.Id);
                    sd.Subject = subj;
                }
            });

            syllabus.PointLimits.ForEach(pl => pl.Id = Guid.NewGuid());

            syllabus.Description.Id = Guid.NewGuid();

            Data.Models.FieldOfStudies.FieldOfStudy fos = _dbContext.FieldsOfStudies.Find(syllabus.FieldOfStudy.Code);
            syllabus.FieldOfStudy   = fos;
            syllabus.Specialization = _dbContext.Specializations.Find(syllabus.Specialization.Code);

            syllabus.IsDeleted = false;

            await _dbSet.AddAsync(syllabus);

            await _dbContext.SaveChangesAsync();

            return(syllabus);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Zapisuje obiekt w najnowszej wersji ale jako inny obiekt o podanych parametrach
        /// </summary>
        /// <param name="fosCode"></param>
        /// <param name="academicYear"></param>
        /// <param name="learningOutcome"></param>
        /// <returns></returns>
        public async Task <LearningOutcomeDocument> SaveAs(string fosCode, string academicYear, LearningOutcomeDocument learningOutcome)
        {
            Data.Models.FieldOfStudies.FieldOfStudy fos = _dbContext.FieldsOfStudies.Find(fosCode);
            if (fos != null)
            {
                learningOutcome.FieldOfStudy = fos;
            }

            learningOutcome.AcademicYear = academicYear;

            return(await Save(learningOutcome));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Zapisuje obiekt w najnowsze wersji
        /// </summary>
        /// <param name="learningOutcome"></param>
        /// <returns>Zapisany LearningOutcomeDocument</returns>
        public async Task <LearningOutcomeDocument> Save(LearningOutcomeDocument learningOutcome)
        {
            var currentDocument = await _dbSet.AsNoTracking()
                                  .Include(lod => lod.FieldOfStudy)
                                  .ThenInclude(fs => fs.Specializations)
                                  .Include(lod => lod.LearningOutcomes)
                                  .ThenInclude(lo => lo.Specialization)
                                  .Where(lod =>
                                         lod.IsDeleted == false &&
                                         lod.AcademicYear == learningOutcome.AcademicYear &&
                                         lod.FieldOfStudy.Code == learningOutcome.FieldOfStudy.Code &&
                                         !lod.IsDeleted)
                                  .OrderByDescending(lod => lod.Version)
                                  .FirstOrDefaultAsync();

            if (currentDocument is null)
            {
                learningOutcome.Version = NewVersion();
            }
            else
            {
                if (!AreChanges(currentDocument, learningOutcome))
                {
                    return(learningOutcome);
                }
                learningOutcome.Version = IncreaseVersion(currentDocument.Version);
            }

            learningOutcome.Id = Guid.NewGuid();
            learningOutcome.LearningOutcomes.ForEach(lo =>
            {
                lo.Id = Guid.NewGuid();
                if (lo.Specialization != null)
                {
                    Data.Models.FieldOfStudies.Specialization spec = _dbContext.Specializations.Find(lo.Specialization.Code);
                    lo.Specialization = spec;
                }
            });
            Data.Models.FieldOfStudies.FieldOfStudy fos = _dbContext.FieldsOfStudies.Find(learningOutcome.FieldOfStudy.Code);
            learningOutcome.FieldOfStudy = fos;

            await _dbSet.AddAsync(learningOutcome);

            await _dbContext.SaveChangesAsync();

            return(learningOutcome);
        }