2014-07-16 20:35:03 +02:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Web;
|
|
|
|
|
using System.Web.Security;
|
2014-10-06 03:05:57 +02:00
|
|
|
using System.Web.Http;
|
2014-10-06 04:58:47 +02:00
|
|
|
using Yavsc.Model.WorkFlow;
|
2015-02-08 20:59:08 +01:00
|
|
|
using System.Collections.Specialized;
|
2015-02-10 13:27:10 +01:00
|
|
|
using Yavsc.Model.FrontOffice;
|
2015-12-23 13:14:50 +01:00
|
|
|
using Yavsc.Helpers;
|
2014-07-16 20:35:03 +02:00
|
|
|
|
2014-10-06 03:05:57 +02:00
|
|
|
namespace Yavsc.ApiControllers
|
2014-07-16 20:35:03 +02:00
|
|
|
{
|
2015-01-27 00:41:20 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Basket controller.
|
2015-02-10 13:27:10 +01:00
|
|
|
/// Maintains a collection of articles
|
|
|
|
|
/// qualified with name value pairs
|
2015-01-27 00:41:20 +01:00
|
|
|
/// </summary>
|
2015-12-23 13:14:50 +01:00
|
|
|
[Authorize]
|
2015-06-14 23:47:34 +02:00
|
|
|
public class BasketController : ApiController
|
2014-07-16 20:35:03 +02:00
|
|
|
{
|
2015-02-10 13:27:10 +01:00
|
|
|
|
2015-02-17 13:57:39 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the current basket, creates a new one, if it doesn't exist.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The current basket.</value>
|
2015-02-18 13:32:25 +01:00
|
|
|
protected CommandSet CurrentBasket {
|
2015-02-17 13:57:39 +01:00
|
|
|
get {
|
2015-11-22 14:00:59 +01:00
|
|
|
CommandSet b = WorkFlowManager.GetCommands (
|
|
|
|
|
Membership.GetUser ().UserName);
|
2015-02-18 13:32:25 +01:00
|
|
|
if (b == null) b = new CommandSet ();
|
2015-02-17 13:57:39 +01:00
|
|
|
return b;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-12-23 13:14:50 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Get the basket.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public CommandSet Get() {
|
|
|
|
|
return CurrentBasket;
|
|
|
|
|
}
|
2015-02-17 13:57:39 +01:00
|
|
|
|
2015-02-10 13:27:10 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Create the specified basket item using specified command parameters.
|
|
|
|
|
/// </summary>
|
2015-12-23 13:14:50 +01:00
|
|
|
public long Create()
|
2015-02-10 13:27:10 +01:00
|
|
|
{
|
2015-12-23 13:14:50 +01:00
|
|
|
return YavscHelpers.CreateCommandFromRequest ();
|
2015-02-10 13:27:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Read the specified basket item.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="itemid">Itemid.</param>
|
2015-02-18 13:32:25 +01:00
|
|
|
Command Read(long itemid){
|
2015-02-17 13:57:39 +01:00
|
|
|
return CurrentBasket[itemid];
|
2015-02-10 13:27:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Update the specified item parameter using the specified value.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="itemid">Item identifier.</param>
|
|
|
|
|
/// <param name="param">Parameter name.</param>
|
|
|
|
|
/// <param name="value">Value.</param>
|
2015-02-17 13:57:39 +01:00
|
|
|
public void UpdateParam(long itemid, string param, string value)
|
2014-10-06 03:05:57 +02:00
|
|
|
{
|
2015-02-17 13:57:39 +01:00
|
|
|
CurrentBasket [itemid].Parameters [param] = value;
|
2014-10-06 03:05:57 +02:00
|
|
|
}
|
2014-07-16 20:35:03 +02:00
|
|
|
|
2015-02-10 13:27:10 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Delete the specified item.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="itemid">Item identifier.</param>
|
|
|
|
|
public void Delete(long itemid)
|
|
|
|
|
{
|
2015-02-17 13:57:39 +01:00
|
|
|
CurrentBasket.Remove (itemid);
|
2015-02-10 13:27:10 +01:00
|
|
|
}
|
|
|
|
|
|
2014-07-16 20:35:03 +02:00
|
|
|
}
|
|
|
|
|
}
|