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 Yavsc.Helpers; namespace Yavsc.ApiControllers { /// /// Basket controller. /// Maintains a collection of articles /// qualified with name value pairs /// [Authorize] public class BasketController : ApiController { /// /// Gets the current basket, creates a new one, if it doesn't exist. /// /// The current basket. protected CommandSet CurrentBasket { get { CommandSet b = WorkFlowManager.GetCommands ( Membership.GetUser ().UserName); if (b == null) b = new CommandSet (); return b; } } /// /// Get the basket. /// public CommandSet Get() { return CurrentBasket; } /// /// Create the specified basket item using specified command parameters. /// public CommandRegistration Create() { return YavscHelpers.CreateCommandFromRequest (); } /// /// Read the specified basket item. /// /// Itemid. Command Read(long itemid){ return CurrentBasket[itemid]; } /// /// Update the specified item parameter using the specified value. /// /// Item identifier. /// Parameter name. /// Value. public void UpdateParam(long itemid, string param, string value) { CurrentBasket [itemid].Parameters [param] = value; } /// /// Delete the specified item. /// /// Item identifier. public void Delete(long itemid) { CurrentBasket.Remove (itemid); } } }