コード例 #1
0
		public TranslatedPost Patch(string id, Post patch)
		{
			var post = _db.Posts.Include(c => c.Translations).SingleOrDefault(c => c.Id == id);

			post.Patch(patch);

			return new TranslatedPost(post);
		}
コード例 #2
0
ファイル: Post.cs プロジェクト: WorkMarketingNet/WMN.Blog
		public void Patch(Post patch)
		{
			if (patch.Author?.Name != null) Author.Name = patch.Author.Name;
			if (patch.Author?.Url != null) Author.Name = patch.Author.Url;
			if (patch.Author?.Photo != null) Author.Name = patch.Author.Photo;
			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.Summary != null) translation.Summary = translationPatch.Summary;
				if (translationPatch.Content != null) translation.Content = translationPatch.Content;
				if (translationPatch.Tags != null) translation.Tags = translationPatch.Tags; // ???
			}
		}
コード例 #3
0
		public TranslatedPost(Post post)
		{
			Id = post.Id;

			if (post.Translations != null && post.Translations.Any())
			{
				var translation = post.Translations.First();
				Culture = translation.Culture;
				Title = translation.Title;
				Summary = translation.Summary;
				SummaryImage = translation.SummaryImage;
				Content = translation.Content;
				ContentImage = translation.ContentImage;
				Tags = translation.Tags;
			}
		}
コード例 #4
0
		// POST http://localhost:51102/odata/Posts
		// User-Agent: Fiddler
		// Host: localhost:14270
		// Content-type: application/json
		// Accept: application/json
		// Content-Length: 26
		// { id:"workmarketinnet-launched", title:"WorkMarketinNet launched", description:"Finally. After months of development WorkMarketingNet is alive." }
		//[Authorize(Roles = "Admin")]
		public async Task<IHttpActionResult> Post(TranslatedPost translatedPost, [ValueProvider(typeof(CultureValueProviderFactory))] string culture = "en-US")
		{
			translatedPost.Culture = culture;

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

			try
			{
				var post = new Post(translatedPost, _cultureManager.SupportedCultures);
				var newPost = _postsManager.Post(post);

				await _postsManager.SaveChanges();
				translatedPost.Id = newPost.Id;
				return Created(translatedPost);
			}
			catch (Exception ex)
			{
				throw;
			}
		}
コード例 #5
0
		// PUT  http://localhost:51102/odata/Posts('workmarketinnet-launched')
		// User-Agent: Fiddler
		// Host: localhost:14270
		// Content-type: application/json
		// Accept: application/json
		// Content-Length: 34
		// { id:"workmarketinnet-launched", title:"WorkMarketinNet launched [PUT]", description:"Finally. After months of development WorkMarketingNet is alive." }
		//[Authorize(Roles = "Admin")]
		public async Task<IHttpActionResult> Put([FromODataUri] string key, TranslatedPost updatePost, [ValueProvider(typeof(CultureValueProviderFactory))] string culture = "en-US")
		{
			updatePost.Culture = culture;

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

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

			var post = new Post(updatePost, new[] { culture });
			var modelPost = _postsManager.Put(key, post);

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

		}
コード例 #6
0
		public async Task<IHttpActionResult> Patch([FromODataUri] string key, Delta<TranslatedPost> delta, [ValueProvider(typeof(CultureValueProviderFactory))] string culture = "en-US")
		{
			var post = new Post(delta.GetEntity(), culture);
			var tochange = _postsManager.Patch(key, post);

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

			return Updated(tochange);

		}
コード例 #7
0
		public Post Post(Post post)
		{
			return _repository.Post(post);
		}
コード例 #8
0
		public TranslatedPost Put(string id, Post updatePost)
		{
			return _repository.Put(id, updatePost);
		}
コード例 #9
0
		public TranslatedPost Patch(string id, Post patch)
		{
			return _repository.Patch(id, patch);
		}
コード例 #10
0
		public Post Post(Post post)
		{
			_db.Posts.Add(post);

			return post;
		}
コード例 #11
0
		public TranslatedPost Put(string id, Post updatePost)
		{
			_db.Entry(updatePost).State = EntityState.Modified;
			_db.Entry(updatePost.Translations.First()).State = EntityState.Modified;
			return new TranslatedPost(updatePost);
		}