Example #1
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));
        }
Example #2
0
        public static List <SubjectInfoDto> MockAttachedSubjectsOfVideo()
        {
            List <SubjectInfoDto> subjects = new List <SubjectInfoDto>();

            foreach (string videoId in VideoInstances.Keys)
            {
                SubjectInfoDto subject = new SubjectInfoDto();
                subjects.Add(subject);
                subject.Title       = string.Format("{0} Title", videoId);
                subject.Description = string.Format("{0} description, this is very interesting.", videoId);
                subject.UrlAlias    = string.Format("{0}", videoId).ToLower();
                // get imageUrl
                List <DucValueDto> values = VideoInstances[videoId];
                DucValueDto        value  = values.FirstOrDefault(o => object.Equals(o.DucId, BlockRegister.YouTubeVideoBlock.ThumbnailUrl));
                if (value != null)
                {
                    subject.ImageUrl = value.ValueText;
                }
                else
                {
                    subject.ImageUrl = "http://placehold.it/460x230";
                }
            }

            return(subjects);
        }
        public IActionResult Info(int id, [FromForm] SubjectInfoBindingModel subjectInfo)
        {
            SubjectInfoDto subjectInfoDto = Mapper.Map <SubjectInfoDto>(subjectInfo);

            ServiceResult serviceResult = SubjectService.UpdateSubjectInfo(subjectInfoDto, id);

            if (serviceResult.Result == Result.Error)
            {
                foreach (var error in serviceResult.Errors)
                {
                    ModelState.AddModelError(error.Key, error.Message);
                }

                if (!ModelState.IsValid)
                {
                    var subjectInfoViewModel = new SubjectInfoViewModel(subjectInfo, id);
                    return(View(subjectInfoViewModel));
                }
            }
            else if (serviceResult.Result == Result.NotFound)
            {
                return(NotFound());
            }

            int subjectId = serviceResult.Id;

            return(RedirectToSubject(subjectId));
        }
        public IActionResult Info(int id)
        {
            SubjectInfoDto subjectInfoDto = SubjectService.GetSubjectInfo(id);

            if (subjectInfoDto == null)
            {
                return(NotFound());
            }

            SubjectInfoBindingModel subjectInfo = Mapper.Map <SubjectInfoBindingModel>(subjectInfoDto);
            var subjectInfoViewModel            = new SubjectInfoViewModel(subjectInfo, id);

            return(View(subjectInfoViewModel));
        }
Example #5
0
        public static List <(string Key, string Message)> Validate(SubjectInfoDto info)
        {
            var errors = new List <(string, string)>();

            string errorMessage;

            if (string.IsNullOrWhiteSpace(info.Title))
            {
                errorMessage = "Не указано название предмета";
                var pair = (nameof(info.Title), errorMessage);
                errors.Add(pair);
            }

            return(errors);
        }
        public async Task CreateSubjectInfoAsync(SubjectInfoDto subjectInfoDto)
        {
            _logService.LogInfo($"Create subject info {subjectInfoDto.Title}");

            var newSubjectInfo = new SubjectInfo
            {
                Title = subjectInfoDto.Title
            };

            _repository.Add(newSubjectInfo);

            await _repository.SaveContextAsync();

            _logService.LogInfo($"Subject info {subjectInfoDto.Title} created with id {newSubjectInfo.SubjectInfoId}");
        }
        public async Task EditSubjectInfoAsync(SubjectInfoDto subjectInfoDto)
        {
            _logService.LogInfo($"Edit subject info with id {subjectInfoDto.Id}");

            var dbSubject = await _repository.GetAll <SubjectInfo>()
                            .Where(info => info.SubjectInfoId == subjectInfoDto.Id)
                            .SingleOrDefaultAsync()
                            ?? throw new SPCException($"Subject info with id {subjectInfoDto.Id} not exists", 404);

            dbSubject.Title = subjectInfoDto.Title;

            _repository.Update(dbSubject);

            await _repository.SaveContextAsync();

            _logService.LogInfo($"Subject info with id {subjectInfoDto.Id} edited");
        }
Example #8
0
        public static List <SubjectInfoDto> MockAttachedSubjects(int count, string contentType)
        {
            List <SubjectInfoDto> subjects = new List <SubjectInfoDto>();

            for (int i = 1; i <= count; i++)
            {
                SubjectInfoDto subject = new SubjectInfoDto();
                subjects.Add(subject);
                subject.ReferenceId = i;
                subject.TotalCount  = 100;
                subject.Title       = string.Format("{0}{1} Title", contentType, i);
                subject.Description = string.Format("{0}{1} description, this is very interesting.", contentType, i);
                subject.UrlAlias    = string.Format("{0}/{0}-{1}-alias/{2}", contentType, i, i).ToLower();
                subject.ImageUrl    = "http://placehold.it/460x230";
            }

            return(subjects);
        }
Example #9
0
        public SubjectInfoDto GetSubjectInfo(int subjectInfoId)
        {
            SubjectInfoDto subjectInfo = Context.SubjectInfos
                                         .AsNoTracking()
                                         .Select(i => new SubjectInfoDto
            {
                Id                = i.Id,
                Title             = i.Title,
                Teachers          = i.Teachers,
                LectureStartDate  = i.LectureStartDate,
                LectureEndDate    = i.LectureEndDate,
                PracticeStartDate = i.PracticeStartDate,
                PracticeEndDate   = i.PracticeEndDate
            })
                                         .SingleOrDefault(s => s.Id == subjectInfoId);

            return(subjectInfo);
        }
Example #10
0
        public async Task <ActionResult> Edit(SubjectInfoDto subjectDto)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(subjectDto));
                }
                await _subjectInfoService.EditSubjectInfoAsync(subjectDto);

                return(RedirectToAction("Index"));
            }
            catch (SPCException ex)
            {
                return(View("ErrorView", new ErrorDto(ex.Message, ex.StatusCode)));
            }
            catch
            {
                return(View("Error"));
            }
        }