コード例 #1
0
		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
ファイル: Event.cs プロジェクト: WorkMarketingNet/WMN.Events
		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;
			}
		}
コード例 #3
0
		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;
			}
		}
コード例 #4
0
		// 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;
			}
		}
コード例 #5
0
		public Event Post(Event @event)
		{
			_db.Events.Add(@event);

			return @event;
		}
コード例 #6
0
		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);
		}
コード例 #7
0
		// 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);

		}
コード例 #8
0
		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);
		}