Exemplo n.º 1
0
        public async Task <ServiceObjectResult <Panel> > CreatePanelAsync(Panel model)
        {
            var validationResult = await _validationService.ValidateAsync <CreatePanelValidator, Panel>(model);

            if (!validationResult.IsValid)
            {
                return(ServiceObjectResult <Panel> .Error(validationResult));
            }

            if (model.ProjectId.HasValue)
            {
                var existingProject = await _projectRepository.GetByIdAsync(model.ProjectId.Value);

                model.Project = existingProject;
            }

            if (model is MemePanel panel)
            {
                var memeImage = await _memeImageRepository.GetRandomMemes(1);

                panel.StaticMemeUrl = memeImage.Select(i => i.ImageUrl).FirstOrDefault();
            }

            var r = await _panelRepository.AddAsync(model);

            await _panelRepository.SaveAsync();

            if (model.Project != null)
            {
                BackgroundJob.Enqueue <IProjectService>(s => s.UpdateCiDataForProjectAsync(model.Project.Id));
            }

            return(ServiceObjectResult <Panel> .Ok(r));
        }
Exemplo n.º 2
0
        public async Task <ServiceObjectResult <Panel> > UpdatePanelAsync(Panel updatedPanel)
        {
            var validationResult = await _validationService.ValidateAsync <UpdatePanelValidator, Panel>(updatedPanel);

            if (!validationResult.IsValid)
            {
                return(ServiceObjectResult <Panel> .Error(validationResult));
            }

            var model = await GetPanelByIdAsync(updatedPanel.Id);

            if (model == null)
            {
                return(null);
            }

            if (updatedPanel.Discriminator != model.Discriminator)
            {
                return(null);
            }

            if (updatedPanel.ProjectId.HasValue)
            {
                var project = await _projectRepository.GetByIdAsync(updatedPanel.ProjectId.Value);

                model.Project = project;
            }

            var r = await _panelRepository.UpdateAsync(updatedPanel, model.Id);

            await _panelRepository.SaveAsync();

            return(ServiceObjectResult <Panel> .Ok(r));
        }
Exemplo n.º 3
0
        public async Task <ServiceObjectResult <Project> > UpdateProjectAsync(Project updatedProject)
        {
            var validationResult = await _validationService.ValidateAsync <UpdateProjectValidator, Project>(updatedProject);

            if (!validationResult.IsValid)
            {
                return(ServiceObjectResult <Project> .Error(validationResult));
            }

            var project = await GetProjectByIdAsync(updatedProject.Id);

            //TODO: change when automapper
            project.ProjectTitle               = updatedProject.ProjectTitle;
            project.ApiAuthenticationToken     = updatedProject.ApiAuthenticationToken;
            project.ApiHostUrl                 = updatedProject.ApiHostUrl;
            project.ApiProjectId               = updatedProject.ApiProjectId;
            project.DataProviderName           = updatedProject.DataProviderName;
            project.CiDataUpdateCronExpression = updatedProject.CiDataUpdateCronExpression;

            _cronJobsManager.UpdateCiDataForProject(updatedProject);

            var r = await _projectRepository.UpdateAsync(project, updatedProject.Id);

            await _projectRepository.SaveAsync();

            return(ServiceObjectResult <Project> .Ok(r));
        }
Exemplo n.º 4
0
        public async Task <ServiceObjectResult <Panel> > UpdatePanelPosition(int panelId, PanelPosition position)
        {
            var validationResult = await _validationService.ValidateAsync <PanelPositionValidator, PanelPosition>(position);

            if (!validationResult.IsValid)
            {
                return(ServiceObjectResult <Panel> .Error(validationResult));
            }

            var entity = await GetPanelByIdAsync(panelId);

            if (entity == null)
            {
                return(null);
            }

            //TODO: change when automaper
            entity.Position.Column = position.Column;
            entity.Position.Row    = position.Row;
            entity.Position.Width  = position.Width;
            entity.Position.Height = position.Height;

            var r = await _panelRepository.UpdateAsync(entity, panelId);

            await _panelRepository.SaveAsync();

            return(ServiceObjectResult <Panel> .Ok(r));
        }
Exemplo n.º 5
0
        public async Task <ServiceObjectResult <Project> > CreateProjectAsync(Project project)
        {
            var validationResult = await _validationService.ValidateAsync <CreateProjectValidator, Project>(project);

            if (!validationResult.IsValid)
            {
                return(ServiceObjectResult <Project> .Error(validationResult));
            }

            var r = await _projectRepository.AddAsync(project);

            await _projectRepository.SaveAsync();

            _cronJobsManager.UpdateCiDataForProject(project);

            return(ServiceObjectResult <Project> .Ok(r));
        }