コード例 #1
0
ファイル: Video.cs プロジェクト: WorkMarketingNet/WMN.Videos
		public Video(TranslatedVideo translatedVideo, IEnumerable<string> cultures) : this()
		{
			Id = translatedVideo.Id;
			YouTubeVideoId = translatedVideo.YouTubeVideoId;
			VotesUp = translatedVideo.VotesUp;
			VotesDown = translatedVideo.VotesDown;
			foreach (var culture in cultures)
			{
				Translations.Add(new VideoTranslation
				{
					Culture = culture,
					VideoId = translatedVideo.Id,
					Title = translatedVideo.Title,
					Description = translatedVideo.Description
				});
			}
		}
コード例 #2
0
		// POST http://localhost:48946/odata/Videos
		// User-Agent: Fiddler
		// Host: localhost:14270
		// Content-type: application/json
		// Accept: application/json
		// Content-Length: 26
		// { id:"jeunesse-global-secret", youTubeVideoId:"8aZTiCHsnVc", title:"Jeunesse Global Secret", description:"Jeunesse Global Secret Are you looking to get involved in the Jeunesse Global home based business opportunity? Do you have an interest anti-aging? Would you like to make a 6 figure income helping others look and feel younger?", votesUp:666, votesDown:34 }
		//[Authorize(Roles = "Admin")]
		public async Task<IHttpActionResult> Post(TranslatedVideo translatedVideo, [ValueProvider(typeof(CultureValueProviderFactory))] string culture = "en-US")
		{
			translatedVideo.Culture = culture;

			if (!ModelState.IsValid)
			{
				return BadRequest(ModelState);
			}

			try
			{
				var video = new Video(translatedVideo, _cultureManager.SupportedCultures);
				var newVideo = _videosManager.Post(video);

				await _videosManager.SaveChanges();
				translatedVideo.Id = newVideo.Id;
				return Created(translatedVideo);
			}
			catch (Exception ex)
			{
				throw;
			}
		}
コード例 #3
0
		// PUT  http://localhost:48946/odata/Videos('jeunesse-global-secret')
		// User-Agent: Fiddler
		// Host: localhost:14270
		// Content-type: application/json
		// Accept: application/json
		// Content-Length: 34
		// { id:"jeunesse-global-secret", youTubeVideoId:"8aZTiCHsnVc", title:"Jeunesse Global Secret [PUT]", description:"Jeunesse Global Secret Are you looking to get involved in the Jeunesse Global home based business opportunity? Do you have an interest anti-aging? Would you like to make a 6 figure income helping others look and feel younger?" }
		//[Authorize(Roles = "Admin")]
		public async Task<IHttpActionResult> Put([FromODataUri] string key, TranslatedVideo updateVideo, [ValueProvider(typeof(CultureValueProviderFactory))] string culture = "en-US")
		{
			updateVideo.Culture = culture;

			if (!ModelState.IsValid)
			{
				return BadRequest(ModelState);
			}

			if (key != updateVideo.Id)
			{
				return BadRequest();
			}

			var video = new Video(updateVideo, new[] { culture });
			var modelVideo = _videosManager.Put(key, video);

			try
			{
				await _videosManager.SaveChanges();
			}
			catch (DbUpdateConcurrencyException)
			{
				if (!_videosManager.Exists(modelVideo.Id))
				{
					return NotFound();
				}
				else
				{
					throw;
				}
			}
			return Updated(modelVideo);

		}
コード例 #4
0
ファイル: Video.cs プロジェクト: WorkMarketingNet/WMN.Videos
		public Video(TranslatedVideo translatedVideo, string culture) : this(translatedVideo, new[] { culture }) { }