Ejemplo n.º 1
0
		public TranslatedAd Patch(string id, Ad patch)
		{
			var ad = _db.Ads.Include(c => c.Translations).SingleOrDefault(c => c.Id == id);

			ad.Patch(patch);

			return new TranslatedAd(ad);
		}
Ejemplo n.º 2
0
		public void Patch(Ad patch)
		{
			foreach (var translationPatch in patch.Translations)
			{
				var translation = Translations.FirstOrDefault(t => t.Culture == translationPatch.Culture);
				if (translation == null) { continue; }

				if (translationPatch.Title != null) translation.Title = translationPatch.Title;
				if (translationPatch.Description != null) translation.Description = translationPatch.Description;
			}
		}
Ejemplo n.º 3
0
		public TranslatedAd(Ad ad)
		{
			Id = ad.Id;

			if (ad.Translations != null && ad.Translations.Any())
			{
				var translation = ad.Translations.First();
				Culture = translation.Culture;
				Title = translation.Title;
				Description = translation.Description;
			}
		}
Ejemplo n.º 4
0
		// 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;
			}
		}
Ejemplo n.º 5
0
		public Ad Post(Ad ad)
		{
			_db.Ads.Add(ad);

			return ad;
		}
Ejemplo n.º 6
0
		public TranslatedAd Put(string id, Ad updateAd)
		{
			_db.Entry(updateAd).State = EntityState.Modified;
			_db.Entry(updateAd.Translations.First()).State = EntityState.Modified;
			return new TranslatedAd(updateAd);
		}
Ejemplo n.º 7
0
		public Ad Post(Ad ad)
		{
			return _repository.Post(ad);
		}
Ejemplo n.º 8
0
		public TranslatedAd Put(string id, Ad updateAd)
		{
			return _repository.Put(id, updateAd);
		}
Ejemplo n.º 9
0
		public TranslatedAd Patch(string id, Ad patch)
		{
			return _repository.Patch(id, patch);
		}
Ejemplo n.º 10
0
		// 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);

		}
Ejemplo n.º 11
0
		public async Task<IHttpActionResult> Patch([FromODataUri] string key, Delta<TranslatedAd> delta, [ValueProvider(typeof(CultureValueProviderFactory))] string culture = "en-US")
		{
			var ad = new Ad(delta.GetEntity(), culture);
			var tochange = _adsManager.Patch(key, ad);

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

			return Updated(tochange);

		}