yavsc/web/ApiControllers/CircleController.cs
Paul Schneider 87edbaffe5 * cldr.js:
* Web.config:
* ListItem.cs:
* styles.json:
* globalize.js:
* event.js:
* Auth.aspx:
* Book.aspx:
* Login.aspx:
* jquery-2.1.4.js:
* map-load.gif:
* Book.aspx:
* Circle.cs:
* Auth.aspx:
* mapstyle.css:
* date.js:
* Login.aspx:
* mdd_help.htm:
* BlogHelper.cs:
* fit-bounds.png:
* unresolved.js:
* jquery-2.1.4.min.js:
* mapstyle-ie.css:
* FreeDate.cs:
* BookEdit.cs:
* number.js:
* BlogManager.cs:
* plural.js:
* jquery-2.1.4.min.map:
* jquery.googlemaps.js:
* supplemental.js:
* BlogProvider.cs:
* mapstyle.min.css:
* pin-pink.png:
* message.js:
* ChooseADate.aspx:
* pin-azure.png:
* currency.js:
* jquery-2.1.4-vsdoc.js:
* pin-green.png:
* MarkdownDeepLib.min.js:
* flag-azure.png:
* flag-green.png:
* needle-pink.png:
* ChooseADate.aspx:
* niddle-green.png:
* ChooseCalendar.aspx:
* current-location.png:
* jquery.googlemaps.min.js:
* ErrorMessage.aspx:
* ChooseCalendar.aspx:
* relative-time.js:
* GoogleErrorMessage.aspx:
* popup-template-marker.html:
* popup-template-circle.html:
* popup-template-polygon.html:
* popup-template-polyline.html:
* popup-template-rectangle.html:

* Web.csproj:
* YavscModel.csproj:
* YavscClient.csproj:
* fortune.csproj:
* WebControls.csproj:
* SalesCatalog.csproj:
* ITContentProvider.csproj:
* NpgsqlMRPProviders.csproj:
* NpgsqlBlogProvider.csproj:
* NpgsqlContentProvider.csproj: Moves to Mono framework

* NpgsqlCircleProvider.cs: Makes Circles private, or not

* OAuth2.cs:
* CircleController.cs:
* AccountController.cs:
* NpgsqlContentProvider.cs: Impacts htmldoc

* NpgsqlMembershipProvider.cs: Makes possible to change the UserName

* NpgsqlRoleProvider.cs: Drops this SQL code, which is actually
  maintained in Web/instdbws.sql

* PeopleApi.cs:
* GoogleController.cs:
* PaypalController.cs: Refactoring

* Global.asax.cs: Dropped an useless url mapping

* MarkdownHelper.cs: Package update

* App.master:
* NoLogin.master: Site's favicon update

* Circles.aspx: TO BE FIXED :-D

* UserPost.aspx: Comment only when logged in

* instdbws.sql: Circle public

* packages.config: package update
2015-07-15 03:36:12 +02:00

123 lines
3.3 KiB
C#

//
// CircleController.cs
//
// Author:
// Paul Schneider <paul@pschneider.fr>
//
// Copyright (c) 2015 GNU GPL
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Web.Http;
using Yavsc.Model.RolesAndMembers;
using System.Collections.Generic;
using Yavsc.Model.Circles;
using System.Web.Security;
using System.Collections.Specialized;
using Yavsc.Model;
namespace Yavsc.ApiControllers
{
/// <summary>
/// New circle.
/// </summary>
public class NewCircle {
/// <summary>
/// Gets or sets the title.
/// </summary>
/// <value>The title.</value>
public string title { get ; set; }
/// <summary>
/// Gets or sets the users.
/// </summary>
/// <value>The users.</value>
public string [] users { get ; set; }
/// <summary>
/// Gets or sets a value indicating whether this <see cref="Yavsc.ApiControllers.NewCircle"/> is private.
/// </summary>
/// <value><c>true</c> if is private; otherwise, <c>false</c>.</value>
public bool isPrivate { get; set; }
}
/// <summary>
/// Circle controller.
/// </summary>
public class CircleController : ApiController
{
/// <summary>
/// Create the specified circle.
/// </summary>
/// <param name="model">Model.</param>
[Authorize]
public long Create(NewCircle model)
{
string user = Membership.GetUser ().UserName;
return CircleManager.DefaultProvider.Create (user, model.title, model.users);
}
/// <summary>
/// Add the specified users to the circle.
/// </summary>
/// <param name="id">Circle Identifier.</param>
/// <param name="username">username.</param>
[Authorize]
public void Add(long id, string username)
{
checkIsOwner (CircleManager.DefaultProvider.Get (id));
CircleManager.DefaultProvider.Add (id, username);
}
/// <summary>
/// Delete the circle specified by id.
/// </summary>
/// <param name="id">Identifier.</param>
[Authorize] public void Delete(long id)
{
checkIsOwner (CircleManager.DefaultProvider.Get(id));
CircleManager.DefaultProvider.Delete (id);
}
private void checkIsOwner(Circle c)
{
string user = Membership.GetUser ().UserName;
if (c.Owner != user)
throw new AccessViolationException ("You're not owner of this circle");
}
/// <summary>
/// Get the circle specified id.
/// </summary>
/// <param name="id">Identifier.</param>
[Authorize]
public Circle Get(long id)
{
var c = CircleManager.DefaultProvider.Get (id);
checkIsOwner (c);
return c;
}
/// <summary>
/// List the circles
/// </summary>
[Authorize]
public IEnumerable<ListItem> List()
{
string user = Membership.GetUser ().UserName;
return CircleManager.DefaultProvider.List (user);
}
}
}