public TranslatedEvent Patch(string id, Event patch)
		{
			var @event = _db.Events.Include(c => c.Translations).SingleOrDefault(c => c.Id == id);

			@event.Patch(patch);

			return new TranslatedEvent(@event);
		}
예제 #2
0
		public void Patch(Event 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;
			}
		}
		public TranslatedEvent(Event @event)
		{
			Id = @event.Id;

			if (@event.Translations != null && @event.Translations.Any())
			{
				var translation = @event.Translations.First();
				Culture = translation.Culture;
				Title = translation.Title;
				Description = translation.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;
			}
		}
		public Event Post(Event @event)
		{
			_db.Events.Add(@event);

			return @event;
		}
		public TranslatedEvent Put(string id, Event updateEvent)
		{
			_db.Entry(updateEvent).State = EntityState.Modified;
			_db.Entry(updateEvent.Translations.First()).State = EntityState.Modified;
			return new TranslatedEvent(updateEvent);
		}
		// 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);

		}
		public async Task<IHttpActionResult> Patch([FromODataUri] string key, Delta<TranslatedEvent> delta, [ValueProvider(typeof(CultureValueProviderFactory))] string culture = "en-US")
		{
			var @event = new Event(delta.GetEntity(), culture);
			var tochange = _eventsManager.Patch(key, @event);

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

			return Updated(tochange);

		}
예제 #9
0
		public Event Post(Event @event)
		{
			return _repository.Post(@event);
		}
예제 #10
0
		public TranslatedEvent Put(string id, Event updateEvent)
		{
			return _repository.Put(id, updateEvent);
		}
예제 #11
0
		public TranslatedEvent Patch(string id, Event patch)
		{
			return _repository.Patch(id, patch);
		}