Beispiel #1
0
		public Ad(TranslatedAd translatedAd, IEnumerable<string> cultures) : this()
		{
			Id = translatedAd.Id;
			foreach (var culture in cultures)
			{
				Translations.Add(new AdTranslation
				{
					Culture = culture,
					AdId = translatedAd.Id,
					Title = translatedAd.Title,
					Description = translatedAd.Description
				});
			}
		}
		// POST http://localhost:48946/odata/Ads
		// User-Agent: Fiddler
		// Host: localhost:14270
		// Content-type: application/json
		// Accept: application/json
		// Content-Length: 26
		// { id:"jeunesse-global-secret", 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(TranslatedAd translatedAd, [ValueProvider(typeof(CultureValueProviderFactory))] string culture = "en-US")
		{
			translatedAd.Culture = culture;

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

			try
			{
				var ad = new Ad(translatedAd, _cultureManager.SupportedCultures);
				var newAd = _adsManager.Post(ad);

				await _adsManager.SaveChanges();
				translatedAd.Id = newAd.Id;
				return Created(translatedAd);
			}
			catch (Exception ex)
			{
				throw;
			}
		}
Beispiel #3
0
		public Ad(TranslatedAd translatedAd, string culture) : this(translatedAd, new[] { culture }) { }
		// PUT  http://localhost:48946/odata/Ads('jeunesse-global-secret')
		// User-Agent: Fiddler
		// Host: localhost:14270
		// Content-type: application/json
		// Accept: application/json
		// Content-Length: 34
		// { id:"jeunesse-global-secret", 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, TranslatedAd updateAd, [ValueProvider(typeof(CultureValueProviderFactory))] string culture = "en-US")
		{
			updateAd.Culture = culture;

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

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

			var ad = new Ad(updateAd, new[] { culture });
			var modelAd = _adsManager.Put(key, ad);

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

		}