Example #1
0
		public Event(TranslatedEvent translatedEvent, IEnumerable<string> cultures) : this()
		{
			Id = translatedEvent.Id;
			foreach (var culture in cultures)
			{
				Translations.Add(new EventTranslation
				{
					Culture = culture,
					EventId = translatedEvent.Id,
					Title = translatedEvent.Title,
					Description = translatedEvent.Description
				});
			}
		}
		// POST http://localhost:49679/odata/Events
		// User-Agent: Fiddler
		// Host: localhost:14270
		// Content-type: application/json
		// Accept: application/json
		// Content-Length: 26
		// { id:"go-pro-recruiting-mastery-2015", title:"Go Pro Recruiting Mastery 2015", description:"Go Pro Recruiting Mastery has become THE annual event for people in our Profession to improve their skills and prepare to make the next 12 months the best of their lives. This year is no exception. In fact, the event will certainly be sold out with a maximum capacity of approximately 8,000 people which will make it the largest event of its kind in Network Marketing history." }
		//[Authorize(Roles = "Admin")]
		public async Task<IHttpActionResult> Post(TranslatedEvent translatedEvent, [ValueProvider(typeof(CultureValueProviderFactory))] string culture = "en-US")
		{
			translatedEvent.Culture = culture;

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

			try
			{
				var @event = new Event(translatedEvent, _cultureManager.SupportedCultures);
				var newEvent = _eventsManager.Post(@event);

				await _eventsManager.SaveChanges();
				translatedEvent.Id = newEvent.Id;
				return Created(translatedEvent);
			}
			catch (Exception ex)
			{
				throw;
			}
		}
Example #3
0
		public Event(TranslatedEvent translatedCompany, string culture) : this(translatedCompany, new[] { culture }) { }
		// PUT  http://localhost:49679/odata/Events('go-pro-recruiting-mastery-2015')
		// User-Agent: Fiddler
		// Host: localhost:14270
		// Content-type: application/json
		// Accept: application/json
		// Content-Length: 34
		// { id:"go-pro-recruiting-mastery-2015", title:"Go Pro Recruiting Mastery 2015 [PUT]", description:"Go Pro Recruiting Mastery has become THE annual event for people in our Profession to improve their skills and prepare to make the next 12 months the best of their lives. This year is no exception. In fact, the event will certainly be sold out with a maximum capacity of approximately 8,000 people which will make it the largest event of its kind in Network Marketing history." }
		//[Authorize(Roles = "Admin")]
		public async Task<IHttpActionResult> Put([FromODataUri] string key, TranslatedEvent updateEvent, [ValueProvider(typeof(CultureValueProviderFactory))] string culture = "en-US")
		{
			updateEvent.Culture = culture;

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

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

			var @event = new Event(updateEvent, new[] { culture });
			var modelEvent = _eventsManager.Put(key, @event);

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

		}