Beispiel #1
0
        private SubjectEntity MapOneSubject(SubjectModel subjectModel)
        {
            string subjectJson = TimetableSerializer.SerializeToJson(subjectModel);
            string subjectHash = HashCoder.GetSha256Hash(subjectJson);

            var info = new SubjectInfoEntity
            {
                Title             = subjectModel.Title,
                Teachers          = subjectModel.Teachers,
                LectureStartDate  = subjectModel.LectureStartDate,
                LectureEndDate    = subjectModel.LectureEndDate,
                PracticeStartDate = subjectModel.PracticeStartDate,
                PracticeEndDate   = subjectModel.PracticeEndDate
            };

            string infoJson = TimetableSerializer.SerializeToJson(info);
            string infoHash = HashCoder.GetSha256Hash(infoJson);

            info.Hash = infoHash;

            string daysJson = TimetableSerializer.SerializeToJson(subjectModel.Days);
            string daysHash = HashCoder.GetSha256Hash(daysJson);

            SubjectEntity entity = new SubjectEntity
            {
                Info     = info,
                Days     = MapSchoolDays(subjectModel.Days),
                HashDays = daysHash,
                Hash     = subjectHash
            };

            return(entity);
        }
Beispiel #2
0
        public ServiceResult UpdateSubjectInfo(SubjectInfoDto subjectInfoDto, int subjectInfoId)
        {
            var errors = SubjectInfoValidator.Validate(subjectInfoDto);

            if (errors.Any())
            {
                var result = new ServiceResult(Result.Error);
                result.Errors.AddRange(errors);
                return(result);
            }

            SubjectInfoEntity info = Context.SubjectInfos.SingleOrDefault(i => i.Id == subjectInfoId);

            info.Title             = subjectInfoDto.Title;
            info.Teachers          = subjectInfoDto.Teachers;
            info.LectureStartDate  = subjectInfoDto.LectureStartDate;
            info.LectureEndDate    = subjectInfoDto.LectureEndDate;
            info.PracticeStartDate = subjectInfoDto.PracticeStartDate;
            info.PracticeEndDate   = subjectInfoDto.PracticeEndDate;
            info.IsApproved        = true;

            Context.SaveChanges();

            UpdateApprovedStatus(info.SubjectId);

            return(new ServiceResult(Result.OK, info.SubjectId));
        }
 private void UpdateSubjectInfo(SubjectInfoEntity info, SubjectInfoEntity newInfo)
 {
     info.Hash              = newInfo.Hash;
     info.Title             = newInfo.Title;
     info.Teachers          = newInfo.Teachers;
     info.LectureStartDate  = newInfo.LectureStartDate;
     info.LectureEndDate    = newInfo.LectureEndDate;
     info.PracticeStartDate = newInfo.PracticeStartDate;
     info.PracticeEndDate   = newInfo.PracticeEndDate;
     info.IsApproved        = false;
 }
Beispiel #4
0
        public ServiceResult ApproveSubjectInfo(int subjectInfoId)
        {
            SubjectInfoEntity subjectInfo = Context.SubjectInfos
                                            .SingleOrDefault(s => s.Id == subjectInfoId);

            if (subjectInfo == null)
            {
                return(new ServiceResult(Result.NotFound));
            }

            subjectInfo.IsApproved = true;

            Context.SaveChanges();

            UpdateApprovedStatus(subjectInfo.SubjectId);

            return(new ServiceResult(Result.OK, subjectInfo.SubjectId));
        }