2014-09-23 01:43:11 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Web;
|
|
|
|
|
|
using System.Web.Security;
|
2014-10-06 04:58:47 +02:00
|
|
|
|
using System.Web.Http;
|
2014-09-23 01:43:11 +02:00
|
|
|
|
using Npgsql.Web.Blog;
|
2014-10-06 04:58:47 +02:00
|
|
|
|
using Yavsc.Model.Blogs;
|
2014-09-23 01:43:11 +02:00
|
|
|
|
|
2014-10-06 04:58:47 +02:00
|
|
|
|
namespace Yavsc.ApiControllers
|
2014-09-23 01:43:11 +02:00
|
|
|
|
{
|
2015-01-27 00:41:20 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Blogs API controller.
|
|
|
|
|
|
/// </summary>
|
2015-06-18 11:02:23 +02:00
|
|
|
|
public class BlogsController : ApiController
|
2014-09-23 01:43:11 +02:00
|
|
|
|
{
|
2014-10-06 03:05:57 +02:00
|
|
|
|
private const string adminRoleName = "Admin";
|
2014-10-06 04:58:47 +02:00
|
|
|
|
|
2015-01-27 00:41:20 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Initialize the specified controllerContext.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="controllerContext">Controller context.</param>
|
2014-10-06 04:58:47 +02:00
|
|
|
|
protected override void Initialize (System.Web.Http.Controllers.HttpControllerContext controllerContext)
|
2014-10-06 03:05:57 +02:00
|
|
|
|
{
|
2014-10-06 04:58:47 +02:00
|
|
|
|
base.Initialize (controllerContext);
|
2014-10-06 03:05:57 +02:00
|
|
|
|
if (!Roles.RoleExists (adminRoleName)) {
|
|
|
|
|
|
Roles.CreateRole (adminRoleName);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-01-27 00:41:20 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Tag the specified postid and tag.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="postid">Postid.</param>
|
|
|
|
|
|
/// <param name="tag">Tag.</param>
|
2014-10-06 03:05:57 +02:00
|
|
|
|
public long Tag (long postid,string tag) {
|
2014-09-24 16:19:23 +02:00
|
|
|
|
BlogEntry e = BlogManager.GetPost (postid);
|
|
|
|
|
|
if (!Roles.IsUserInRole ("Admin")) {
|
|
|
|
|
|
string rguser = Membership.GetUser ().UserName;
|
|
|
|
|
|
if (rguser != e.UserName) {
|
|
|
|
|
|
throw new AccessViolationException (
|
|
|
|
|
|
string.Format (
|
|
|
|
|
|
"Vous n'avez pas le droit de tagger des billets du Blog de {0}",
|
|
|
|
|
|
e.UserName));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2014-10-06 03:05:57 +02:00
|
|
|
|
return BlogManager.Tag (postid, tag);
|
2014-09-24 16:19:23 +02:00
|
|
|
|
}
|
2015-01-27 00:41:20 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Removes the post.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="user">User.</param>
|
|
|
|
|
|
/// <param name="title">Title.</param>
|
2015-02-12 16:08:16 +01:00
|
|
|
|
public void RemovePost(string user, string title) {
|
2014-09-23 01:43:11 +02:00
|
|
|
|
BlogEntry e = BlogManager.GetPost (user, title);
|
|
|
|
|
|
if (e == null) {
|
2014-10-06 04:58:47 +02:00
|
|
|
|
throw new KeyNotFoundException (
|
2014-09-23 01:43:11 +02:00
|
|
|
|
string.Format("Aucun post portant le titre \"{0}\" pour l'utilisateur {1}",
|
|
|
|
|
|
title, user));
|
|
|
|
|
|
}
|
|
|
|
|
|
BlogManager.RemovePost (user, title);
|
|
|
|
|
|
}
|
2015-01-27 00:41:20 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Removes the tag.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="tagid">Tagid.</param>
|
2014-10-06 03:05:57 +02:00
|
|
|
|
public void RemoveTag(long tagid) {
|
|
|
|
|
|
throw new NotImplementedException ();
|
|
|
|
|
|
}
|
2014-09-23 01:43:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|