Esempio n. 1
0
		public Message(TranslatedMessage translatedMessage, IEnumerable<string> cultures) : this()
		{
			Id = translatedMessage.Id;
			foreach (var culture in cultures)
			{
				Translations.Add(new MessageTranslation
				{
					Culture = culture,
					MessageId = translatedMessage.Id,
					Title = translatedMessage.Title,
					Description = translatedMessage.Description
				});
			}
		}
		// POST http://localhost:48946/odata/Messages
		// 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(TranslatedMessage translatedMessage, [ValueProvider(typeof(CultureValueProviderFactory))] string culture = "en-US")
		{
			translatedMessage.Culture = culture;

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

			try
			{
				var message = new Message(translatedMessage, _cultureManager.SupportedCultures);
				var newMessage = _messagesManager.Post(message);

				await _messagesManager.SaveChanges();
				translatedMessage.Id = newMessage.Id;
				return Created(translatedMessage);
			}
			catch (Exception ex)
			{
				throw;
			}
		}
Esempio n. 3
0
		public Message(TranslatedMessage translatedMessage, string culture) : this(translatedMessage, new[] { culture }) { }
		// PUT  http://localhost:48946/odata/Messages('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, TranslatedMessage updateMessage, [ValueProvider(typeof(CultureValueProviderFactory))] string culture = "en-US")
		{
			updateMessage.Culture = culture;

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

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

			var message = new Message(updateMessage, new[] { culture });
			var modelAd = _messagesManager.Put(key, message);

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

		}