using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.Http;
using Yavsc.Model.WorkFlow;
using System.Collections.Specialized;
using Yavsc.Model.FrontOffice;
using System.Web.SessionState;
namespace Yavsc.ApiControllers
{
///
/// Basket controller.
/// Maintains a collection of articles
/// qualified with name value pairs
///
public class BasketController : ApiController
{
///
/// The wfmgr.
///
protected WorkFlowManager wfmgr = null;
///
/// Initialize the specified controllerContext.
///
/// Controller context.
protected override void Initialize (System.Web.Http.Controllers.HttpControllerContext controllerContext)
{
base.Initialize (controllerContext);
wfmgr = new WorkFlowManager ();
}
///
/// Gets the current basket, creates a new one, if it doesn't exist.
///
/// The current basket.
protected Basket CurrentBasket {
get {
HttpSessionState session = HttpContext.Current.Session;
Basket b = (Basket) session ["Basket"];
if (b == null)
session ["Basket"] = b = new Basket ();
return b;
}
}
///
/// Create the specified basket item using specified command parameters.
///
/// Command parameters.
[Authorize]
public long Create(NameValueCollection cmdParams)
{
// HttpContext.Current.Request.Files
Commande cmd = new Commande(cmdParams, HttpContext.Current.Request.Files);
CurrentBasket.Add (cmd);
return cmd.Id;
}
///
/// Read the specified basket item.
///
/// Itemid.
[Authorize]
Commande Read(long itemid){
return CurrentBasket[itemid];
}
///
/// Update the specified item parameter using the specified value.
///
/// Item identifier.
/// Parameter name.
/// Value.
[Authorize]
public void UpdateParam(long itemid, string param, string value)
{
CurrentBasket [itemid].Parameters [param] = value;
}
///
/// Delete the specified item.
///
/// Item identifier.
[Authorize]
public void Delete(long itemid)
{
CurrentBasket.Remove (itemid);
}
}
}