public List <StudentLessonEntity> GetStudentMissedLessons(
            StudentEntity student,
            StreamEntity stream,
            DateTime until
            )
        {
            if (student.Id == default)
            {
                return(new List <StudentLessonEntity>());
            }
            var lessonModels = stream.StreamLessons?.Where
                               (
                lesson =>
                (lesson.StudentLessons?.Any
                 (
                     studentLesson =>
                     studentLesson.Student?.Id == student.Id
                 ) ?? false) &&
                lesson.LessonType < LessonType.Attestation &&
                lesson.Date < until
                               ) ?? new List <LessonEntity>();

            return(lessonModels
                   .Select
                   (
                       lesson => lesson.StudentLessons?.First
                       (
                           studentLesson => studentLesson.Student?.Id == student.Id
                       )
                   )
                   .Where(studentLesson => studentLesson?.IsLessonMissed ?? false)
                   .ToList());
        }
        private static Entity buildEntity(String multipartString)
        {
            byte[] multiPartData = StringHelper.ToUtfBytes(multipartString.ToString());

            Stream multiPartStream = new MemoryStream(multiPartData, 0, multiPartData.Length);

            StreamEntity answer = new StreamEntity(multiPartData.Length, multiPartStream);
            return answer;

        }
        private int dispatch(HttpWebRequest webRequest, Authenticator authenticator, HttpResponseHandler responseHandler)
        {

            HttpWebResponse webResponse;
            try
            {
                webResponse = (HttpWebResponse)webRequest.GetResponse();
            }
            catch (WebException e)
            {
                webResponse = (HttpWebResponse)e.Response;
            }

            Stream entityStream = null;
            try
            {
                entityStream = webResponse.GetResponseStream();

                WebHeaderCollection responseHeaders = webResponse.Headers;
                if (null != authenticator)
                {
                    authenticator.handleHttpResponseHeaders(responseHeaders);
                }

                int statusCode = (int)webResponse.StatusCode;

                if (statusCode >= 200 && statusCode < 300)
                {
                    // all is well
                    if (null == entityStream) // e.g. http 204 
                    {
                        responseHandler.handleResponseEntity(responseHeaders, null);
                    }
                    else
                    {
                        long contentLength = webResponse.ContentLength;
                        log.debug(contentLength, "contentLength");

                        StreamEntity responseEntity = new StreamEntity(contentLength, entityStream);
                        responseHandler.handleResponseEntity(responseHeaders, responseEntity);
                    }
                }
                return statusCode;

            }
            finally
            {
                if (null != entityStream)
                {
                    StreamHelper.close(entityStream, false, this);
                }
            }
        }
Exemple #4
0
        public static StreamEntity InsertStreamEntity(this Partition partition, int version = 0)
        {
            var entity = new StreamEntity
            {
                PartitionKey = partition.PartitionKey,
                RowKey = Api.StreamRowKey,
                Version = version
            };

            partition.Table.Execute(TableOperation.Insert(entity));
            return entity;
        }
        private void Initialize(StreamEntity stream)
        {
            if (stream == null)
            {
                return;
            }

            this.AvailableCourses.Clear();
            var dropDownItems = Enumerable.Range(1, 5).Select(i => new DropDownItem <int>(i.ToString(), i)).ToList();

            this.AvailableCourses.Add(DefaultCourse);
            this.AvailableCourses.AddRange(dropDownItems);
            this.Disciplines.Clear();
            this.Departments.Clear();
            this.Disciplines.AddRange(_context.Disciplines.ToList());
            this.Departments.Add(DefaultDepartment);
            this.Departments.AddRange(_context.Departments.ToList());

            _entity = stream.Id == default ? stream : _context.Streams.Find(stream.Id) ?? stream;
            this.ChosenGroups.AddRange(_entity.Groups?.ToList() ?? new List <GroupEntity>());
            this.AvailableGroups.AddRange(_context.Groups.ToList()
                                          .Where(groupModel => _entity.Groups?.All(o => groupModel.Id != o.Id) ?? true).ToList());
            this.StreamName     = _entity.Name;
            this.IsActive       = _entity.IsActive;
            this.ExpirationDate = _entity.ExpirationDate ?? DateTime.Today;
            this.SelectedCourse =
                this.AvailableCourses.FirstOrDefault(item => item.Value.Equals(_entity.Course)) ??
                DefaultCourse;
            this.SelectedDiscipline =
                this.Disciplines.FirstOrDefault(discipline => discipline.Id == _entity._DisciplineId) ??
                this.Disciplines.FirstOrDefault();
            this.SelectedDepartment =
                this.Departments.FirstOrDefault(department => department.Id == _entity._DepartmentId) ??
                DefaultDepartment;
            this.LaboratoryCount = _entity.LabCount;
            this.LectureCount    = _entity.LectureCount;
            this.PracticeCount   = _entity.PracticalCount;
            this.Description     = _entity.Description;
        }
        private void OnSelectedStreamUpdate([CanBeNull] StreamEntity stream)
        {
            if (stream == null)
            {
                this.StreamDataVisibility = Visibility.Hidden;
                return;
            }

            this.StreamDataVisibility = Visibility.Visible;
            InterpolateLocalization
            (
                "page.student.view.stream.course",
                stream.Course?.ToString() ?? ""
            );
            InterpolateLocalization
            (
                "page.student.view.discipline.lessons",
                stream.LectureCount,
                stream.PracticalCount,
                stream.LabCount
            );
            var missedLessons   = _context.GetStudentMissedLessons(this.Student, stream, DateTime.Now);
            var missedLectures  = missedLessons.Count(model => model.Lesson.LessonType == LessonType.Lecture);
            var missedPractices = missedLessons.Count(model => model.Lesson.LessonType == LessonType.Practice);
            var missedLabs      = missedLessons.Count(model => model.Lesson.LessonType == LessonType.Laboratory);
            var total           = missedLectures + missedPractices + missedLabs;

            this.StudentMissedLessons = total == 0
                ? Localization["Нет пропущенных занятий"]
                : LocalizationContainer.Interpolate
                                        (
                "page.student.view.missed.lessons",
                total,
                missedLectures,
                missedPractices,
                missedLabs
                                        );
        }
        public async Task CreateFromTestAsync()
        {
            /*
             * Explicit blockchain name test
             */

            // Act
            var expActual = await _wallet.CreateFromAsync(_chainName, UUID.NoHyphens, _address, Entity.Stream, StreamEntity.GetUUID(), true, new { });

            // Assert
            Assert.IsTrue(expActual.IsSuccess());
            Assert.IsInstanceOf <RpcResponse <string> >(expActual);

            /*
             * Inferred blockchain name test
             */

            // Act
            var infActual = await _wallet.CreateFromAsync(_address, Entity.Stream, StreamEntity.GetUUID(), true, new { });

            // Assert
            Assert.IsTrue(expActual.IsSuccess());
            Assert.IsInstanceOf <RpcResponse <string> >(infActual);
        }
        public async Task <IActionResult> SaveEditedProject(ProjectViewModel projectViewModel, bool draft = false,
                                                            bool enableVoting = false, bool enableRegistration = false)
        {
            if (projectViewModel.ProjectUrl == null)
            {
                projectViewModel.ProjectUrl = projectViewModel.Id;
            }

            projectViewModel.Tags = SerializeTags(projectViewModel.Tags);

            projectViewModel.ProjectStatus = projectViewModel.Status.ToString();

            var sanitizer = new HtmlSanitizer();

            projectViewModel.PrizeDescription = sanitizer.Sanitize(projectViewModel.PrizeDescription);
            projectViewModel.Description      = sanitizer.Sanitize(projectViewModel.Description);

            projectViewModel.SkipVoting       = !enableVoting;
            projectViewModel.SkipRegistration = !enableRegistration;
            if (projectViewModel.CompetitionRegistrationDeadline == DateTime.MinValue)
            {
                projectViewModel.CompetitionRegistrationDeadline = DateTime.UtcNow.Date;
            }

            if (projectViewModel.VotingDeadline == DateTime.MinValue)
            {
                projectViewModel.VotingDeadline = DateTime.UtcNow.Date;
            }

            var project = await _projectRepository.GetAsync(projectViewModel.Id);

            if (projectViewModel.AuthorId == null)
            {
                projectViewModel.AuthorId = project.AuthorId;
            }

            if (projectViewModel.AuthorFullName == null)
            {
                projectViewModel.AuthorFullName = project.AuthorFullName;
            }

            if (projectViewModel.AuthorIdentifier == null)
            {
                projectViewModel.AuthorIdentifier = project.AuthorIdentifier;

                var profile = await _personalDataService.FindClientsByEmail(projectViewModel.AuthorId);

                if (profile != null)
                {
                    projectViewModel.AuthorIdentifier = profile.Id;
                }
            }

            project.Status = StatusHelper.GetProjectStatusFromString(project.ProjectStatus);

            var user     = UserModel.GetAuthenticatedUser(User.Identity);
            var userRole = await _userRolesRepository.GetAsync(user.Email.ToLower());

            //Don't let non-admin users edit their draft projects to Initiative status
            if (userRole == null || userRole.Role != "ADMIN")
            {
                if (await IsOkKycStatusAsync(user) && projectViewModel.Status != Status.Draft)
                {
                    return(View("CreateInitiativeClosed"));
                }
            }

            projectViewModel.LastModified = DateTime.UtcNow;

            projectViewModel.UserAgent = HttpContext.Request.Headers["User-Agent"].ToString();

            projectViewModel.ParticipantsCount = project.ParticipantsCount;

            var projectId           = projectViewModel.Id;
            var statusAndUrlChanged = projectViewModel.Status != Status.Draft &&
                                      projectViewModel.ProjectUrl != projectId;

            if (!statusAndUrlChanged)
            {
                var currentProjectIsInStream     = false;
                var currentProjectWasInOldStream = false;
                var streamId = "";

                if (projectViewModel.StreamType == "New")
                {
                    var streamProjects = JsonConvert.DeserializeObject <List <StreamProject> >(projectViewModel.SerializedStream);

                    if (streamProjects.Any())
                    {
                        var newStream = new StreamEntity
                        {
                            Name        = projectViewModel.NewStreamName,
                            AuthorId    = user.Id,
                            AuthorEmail = user.Email,
                            Stream      = projectViewModel.SerializedStream
                        };

                        streamId = await _streamRepository.SaveAsync(newStream);

                        foreach (var proj in streamProjects)
                        {
                            var streamProject = await _projectRepository.GetAsync(proj.ProjectId);

                            streamProject.StreamId = streamId;
                            await _projectRepository.UpdateAsync(streamProject);
                        }

                        currentProjectIsInStream = streamProjects.Any(p => p.ProjectId == projectViewModel.Id);
                    }
                }
                if (projectViewModel.StreamType == "Existing")
                {
                    var existingStream = await _streamRepository.GetAsync(projectViewModel.ExistingStreamId);

                    var oldProjects = JsonConvert.DeserializeObject <List <StreamProject> >(existingStream.Stream);
                    currentProjectWasInOldStream = oldProjects.Any(p => p.ProjectId == projectViewModel.Id);

                    foreach (var oldProj in oldProjects)
                    {
                        var oldProject = await _projectRepository.GetAsync(oldProj.ProjectId);

                        oldProject.StreamId = null;
                        await _projectRepository.UpdateAsync(oldProject);
                    }

                    existingStream.Stream = projectViewModel.SerializedStream;
                    await _streamRepository.UpdateAsync(existingStream);

                    var newProjects = JsonConvert.DeserializeObject <List <StreamProject> >(projectViewModel.SerializedStream);

                    foreach (var newProj in newProjects)
                    {
                        var streamProject = await _projectRepository.GetAsync(newProj.ProjectId);

                        streamProject.StreamId = existingStream.Id;
                        await _projectRepository.UpdateAsync(streamProject);
                    }

                    currentProjectIsInStream = newProjects.Any(p => p.ProjectId == projectViewModel.Id);
                    streamId = existingStream.Id;
                }

                if (currentProjectIsInStream)
                {
                    projectViewModel.StreamId = streamId;
                }
                else if (currentProjectWasInOldStream)
                {
                    projectViewModel.StreamId = null;
                }
                await _projectRepository.UpdateAsync(projectViewModel);
            }


            if (project.Status == Status.Draft && projectViewModel.Status == Status.Initiative)
            {
                await SendProjectCreateNotification(projectViewModel);
            }

            var idValid = false;

            if (!string.IsNullOrEmpty(projectViewModel.ProjectUrl))
            {
                idValid = Regex.IsMatch(projectViewModel.ProjectUrl, @"^[a-z0-9-]+$");
            }
            else
            {
                return(await EditWithProjectUrlError(projectViewModel.Id, "Project Url cannot be empty!"));
            }

            if (!idValid)
            {
                return(await EditWithProjectUrlError(projectViewModel.Id, "Project Url can only contain lowercase letters, numbers and the dash symbol!"));
            }

            if (projectViewModel.ProjectUrl != projectId)
            {
                if (projectViewModel.Status != Status.Draft)
                {
                    var oldProjUrl = projectViewModel.ProjectUrl;
                    projectViewModel = await GetProjectViewModel(projectId);

                    projectViewModel.ProjectUrl        = oldProjUrl;
                    projectViewModel.ProjectCategories = _categoriesRepository.GetCategories();
                    ModelState.AddModelError("Status", "Status cannot be changed while changing Project Url!");
                    return(View("EditProject", projectViewModel));
                }

                if (!string.IsNullOrEmpty(projectViewModel.ProjectUrl))
                {
                    idValid = Regex.IsMatch(projectViewModel.ProjectUrl, @"^[a-z0-9-]+$");
                }
                else
                {
                    return(await EditWithProjectUrlError(projectViewModel.Id, "Project Url cannot be empty!"));
                }

                if (!idValid)
                {
                    return(await EditWithProjectUrlError(projectViewModel.Id, "Project Url can only contain lowercase letters, numbers and the dash symbol!"));
                }

                var projectExists = await _projectRepository.GetAsync(projectViewModel.ProjectUrl);

                if (projectExists != null)
                {
                    return(await EditWithProjectUrlError(projectViewModel.Id, "Project with that Project Url already exists!"));
                }

                projectViewModel.Id      = projectViewModel.ProjectUrl;
                projectViewModel.Created = DateTime.UtcNow;

                await _projectRepository.SaveAsync(projectViewModel);

                await _projectRepository.DeleteAsync(projectId);

                return(RedirectToAction("ProjectDetails", "Project", new { id = projectViewModel.ProjectUrl }));
            }

            if (project.Status != Status.Registration && projectViewModel.Status == Status.Registration)
            {
                await AddCompetitionMailToQueue(project);
            }

            if (project.Status != Status.Submission && projectViewModel.Status == Status.Submission)
            {
                await AddImplementationMailToQueue(project);
            }

            if (project.Status != Status.Voting && projectViewModel.Status == Status.Voting)
            {
                await AddVotingMailToQueue(project);
            }

            if (projectViewModel.Status == Status.Archive)
            {
                if (!project.SkipVoting)
                {
                    await _winnersService.SaveWinners(projectViewModel.Id, projectViewModel.Winners);
                }
                else
                {
                    await _winnersService.SaveCustomWinners(projectViewModel.Id, projectViewModel.Winners);
                }

                await AddArchiveMailToQueue(project);
            }

            await _expertsService.SaveExperts(projectViewModel.Id, projectViewModel.Experts);

            await SaveProjectFile(projectViewModel.File, projectId);

            return(RedirectToAction("ProjectDetails", "Project", new { id = projectViewModel.Id }));
        }
Exemple #9
0
 /// <summary>
 /// Create stream from an address; Blockchain name is explicit
 /// </summary>
 /// <param name="client"></param>
 /// <param name="blockchainName"></param>
 /// <param name="fromAddress"></param>
 /// <param name="streamEntity"></param>
 /// <returns></returns>
 public static Task <CliResponse <string> > CreateStreamFrom(this IMultiChainCliWallet client, string blockchainName, string fromAddress, StreamEntity streamEntity) =>
 client.CreateFromAsync(blockchainName, fromAddress, streamEntity.EntityType, streamEntity.Name, streamEntity.Restrictions, streamEntity.CustomFields);
Exemple #10
0
        // *** Create Stream extension methods

        /// <summary>
        /// Create stream; Blockchain name is inferred
        /// </summary>
        /// <param name="client"></param>
        /// <param name="streamEntity"></param>
        /// <returns></returns>
        public static Task <CliResponse <string> > CreateStream(this IMultiChainCliWallet client, StreamEntity streamEntity) =>
        client.CreateAsync(streamEntity.EntityType, streamEntity.Name, streamEntity.Restrictions, streamEntity.CustomFields);
Exemple #11
0
 static Stream From(Partition partition, StreamEntity entity)
 {
     return new Stream(partition, entity.ETag, entity.Version, entity.Properties);
 }
 public StreamFormToken(string title, StreamEntity stream) : base(title)
 {
     this.Stream = stream;
 }