예제 #1
0
        public async Task<HttpResponseMessage> Post(ProjectModel model)
        {
            try
            {
                await CongratUserIfNeeded();
            }
            catch (Exception e)
            {
                Trace.TraceError("Failed to notify user by email: {0}", e);
            }

            ProductType product = _productIdExtractor.Get(UserAgent);

            var project = new DomainProject
            {
                UserId = UserId,
                Name = model.Name,
                Description = model.Description,
                Access = model.Access,
                ProductType = product,
                ProjectType = model.ProjectType,
                ProjectSubtype = model.ProjectSubtype,
                EnableComments = model.EnableComments
            };

            project = await _projectService.AddAsync(project);

            var responseProject = new Project
            {
                Id = project.Id,
                Description = project.Description,
                Access = project.Access,
                Name = project.Name,
                Created = project.Created,
                PublicUrl = _projectUriProvider.GetUri(project.Id),
                ProjectType = project.ProjectType,
                ProjectSubtype = project.ProjectSubtype,
                EnableComments = project.EnableComments
            };

            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, responseProject);
            response.SetLastModifiedDate(project.Modified);

            return response;
        }
예제 #2
0
        public async Task<HttpResponseMessage> Get(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest, ResponseMessages.ProjectInvalidId);
            }

            var project = new DomainProject
            {
                UserId = UserId,
                Id = id
            };

            project = await _projectService.GetAsync(project);

            var responseProject = new Project
            {
                Id = project.Id,
                Description = project.Description,
                Name = project.Name,
                Access = project.Access,
                Created = project.Created,
                PublicUrl = _projectUriProvider.GetUri(project.Id),
                ProjectType = project.ProjectType,
                ProjectSubtype = project.ProjectSubtype,
                EnableComments = project.EnableComments
            };

            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, responseProject);
            response.SetLastModifiedDate(project.Modified);

            return response;
        }
예제 #3
0
        public async Task<HttpResponseMessage> Put(string id, ProjectModel model)
        {
            var project = new DomainProject { Id = id, UserId = UserId };
            DomainProject originalProject = await _projectService.GetAsync(project);

            // updating original project
            originalProject.Name = model.Name;
            originalProject.Description = model.Description;
            originalProject.Access = model.Access;
            originalProject.EnableComments = model.EnableComments;
            project = await _projectService.EditAsync(originalProject);

            var responseProjects = new Project
            {
                Created = project.Created,
                Description = project.Description,
                Id = project.Id,
                Access = project.Access,
                Name = project.Name,
                PublicUrl = _projectUriProvider.GetUri(project.Id),
                ProjectType = project.ProjectType,
                ProjectSubtype = project.ProjectSubtype,
                EnableComments = project.EnableComments
            };

            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, responseProjects);
            response.SetLastModifiedDate(project.Modified);

            return response;
        }
예제 #4
0
        public async Task<HttpResponseMessage> Post(ExternalProjectModel model)
        {
            try
            {
                await CongratUserIfNeeded();
            }
            catch (Exception e)
            {
                Trace.TraceError("Failed to notify user by email: {0}", e);
            }

            // Add project
            ProductType product = _productIdExtractor.Get(UserAgent);

            var project = new DomainProject
            {
                UserId = UserId,
                Name = model.Name,
                Description = model.Description,
                Access = model.Access,
                ProductType = product,
                ProjectType = model.ProjectType,
                ProjectSubtype = model.ProjectSubtype,
                EnableComments = model.EnableComments
            };

            project = await _projectService.AddAsync(project);

            // Add external video
            await _externalVideoService.AddAsync(project.Id, new DomainExternalVideo
            {
                ProductName = model.ProductName,
                VideoUri = model.VideoUri
            });

            // Add avsx file if exists
            if (model.Avsx != null)
            {
                var avsx = new DomainAvsx
                {
                    ContentType = model.Avsx.ContentType,
                    FileName = model.Avsx.Name,
                    FileUri = model.Avsx.Uri,
                    FileLength = model.Avsx.Length
                };

                await _projectAvsxService.AddAsync(project.Id, avsx);
                // For statistics
                Request.Properties.Add("isAvsx", true);
            }

            // Add screenshot file if exists
            if (model.Screenshot != null)
            {
                var screenshot = new DomainScreenshot
                {
                    FileName = model.Screenshot.Name,
                    FileUri = model.Screenshot.Uri,
                    FileId = Guid.NewGuid().ToString(),
                    FileLength = model.Screenshot.Length,
                    ContentType = model.Screenshot.ContentType,
                    Created = DateTime.UtcNow,
                    Modified = DateTime.UtcNow
                };

                await _projectScreenshotService.AddAsync(project.Id, screenshot);
                // For statistics
                Request.Properties.Add("isScreenshot", true);
            }

            var responseProject = new Project
            {
                Id = project.Id,
                Description = project.Description,
                Access = project.Access,
                Name = project.Name,
                Created = project.Created,
                PublicUrl = _projectUriProvider.GetUri(project.Id),
                ProjectType = project.ProjectType,
                ProjectSubtype = project.ProjectSubtype,
                EnableComments = project.EnableComments
            };

            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, responseProject);
            response.SetLastModifiedDate(project.Modified);

            return response;
        }