@ -13,6 +13,7 @@ using Yavsc.Model.WorkFlow;
using WorkFlowProvider ;
using WorkFlowProvider ;
using System.Web.Security ;
using System.Web.Security ;
using System.Threading ;
using System.Threading ;
using Yavsc.Model.FrontOffice ;
namespace Yavsc.Controllers
namespace Yavsc.Controllers
{
{
@ -26,6 +27,7 @@ namespace Yavsc.Controllers
/// The wfmgr.
/// The wfmgr.
/// </summary>
/// </summary>
protected WorkFlowManager wfmgr = null ;
protected WorkFlowManager wfmgr = null ;
/// <summary>
/// <summary>
/// Initialize the specified requestContext.
/// Initialize the specified requestContext.
/// </summary>
/// </summary>
@ -35,6 +37,7 @@ namespace Yavsc.Controllers
base . Initialize ( requestContext ) ;
base . Initialize ( requestContext ) ;
wfmgr = new WorkFlowManager ( ) ;
wfmgr = new WorkFlowManager ( ) ;
}
}
/// <summary>
/// <summary>
/// Index this instance.
/// Index this instance.
/// </summary>
/// </summary>
@ -42,6 +45,7 @@ namespace Yavsc.Controllers
{
{
return View ( ) ;
return View ( ) ;
}
}
/// <summary>
/// <summary>
/// Estimates this instance.
/// Estimates this instance.
/// </summary>
/// </summary>
@ -50,15 +54,16 @@ namespace Yavsc.Controllers
{
{
string username = Membership . GetUser ( ) . UserName ;
string username = Membership . GetUser ( ) . UserName ;
return View ( wfmgr . GetEstimates ( username ) ) ;
return View ( wfmgr . GetEstimates ( username ) ) ;
}
}
/// <summary>
/// <summary>
/// Estimate the specified model and submit.
/// Estimate the specified model and submit.
/// </summary>
/// </summary>
/// <param name="model">Model.</param>
/// <param name="model">Model.</param>
/// <param name="submit">Submit.</param>
/// <param name="submit">Submit.</param>
[Authorize]
[Authorize]
public ActionResult Estimate ( Estimate model , string submit )
public ActionResult Estimate ( Estimate model , string submit )
{
{
ViewData [ "WebApiBase" ] = "http://" + Request . Url . Authority + "/api" ;
ViewData [ "WebApiBase" ] = "http://" + Request . Url . Authority + "/api" ;
ViewData [ "WABASEWF" ] = ViewData [ "WebApiBase" ] + "/WorkFlow" ;
ViewData [ "WABASEWF" ] = ViewData [ "WebApiBase" ] + "/WorkFlow" ;
@ -80,12 +85,12 @@ namespace Yavsc.Controllers
} else {
} else {
string username = HttpContext . User . Identity . Name ;
string username = HttpContext . User . Identity . Name ;
if ( model . Id = = 0 ) {
if ( model . Id = = 0 ) {
model . Responsible = username ;
model . Responsible = username ;
ModelState . Clear ( ) ;
ModelState . Clear ( ) ;
}
}
if ( ModelState . IsValid ) {
if ( ModelState . IsValid ) {
if ( username ! = model . Responsible
if ( username ! = model . Responsible
& & ! Roles . IsUserInRole ( "FrontOffice" ) )
& & ! Roles . IsUserInRole ( "FrontOffice" ) )
throw new UnauthorizedAccessException ( "You're not allowed to modify this estimate" ) ;
throw new UnauthorizedAccessException ( "You're not allowed to modify this estimate" ) ;
if ( model . Id = = 0 )
if ( model . Id = = 0 )
@ -98,12 +103,13 @@ namespace Yavsc.Controllers
}
}
}
}
}
}
return View ( model ) ;
return View ( model ) ;
}
}
/// <summary>
/// <summary>
/// Catalog this instance.
/// Catalog this instance.
/// </summary>
/// </summary>
[AcceptVerbs ("GET")]
[AcceptVerbs ("GET")]
public ActionResult Catalog ( )
public ActionResult Catalog ( )
{
{
return View (
return View (
@ -114,12 +120,12 @@ namespace Yavsc.Controllers
/// <summary>
/// <summary>
/// Catalog this instance.
/// Catalog this instance.
/// </summary>
/// </summary>
[AcceptVerbs ("GET")]
[AcceptVerbs ("GET")]
public ActionResult Brand ( string id )
public ActionResult Brand ( string id )
{
{
Catalog c = CatalogManager . GetCatalog ( Request . Url . AbsolutePath ) ;
Catalog c = CatalogManager . GetCatalog ( Request . Url . AbsolutePath ) ;
ViewData [ "BrandName" ] = id ;
ViewData [ "BrandName" ] = id ;
return View ( c . GetBrand ( id ) ) ;
return View ( c . GetBrand ( id ) ) ;
}
}
/// <summary>
/// <summary>
@ -128,7 +134,7 @@ namespace Yavsc.Controllers
/// <returns>The category object.</returns>
/// <returns>The category object.</returns>
/// <param name="brandid">Brand id.</param>
/// <param name="brandid">Brand id.</param>
/// <param name="pcid">Product category Id.</param>
/// <param name="pcid">Product category Id.</param>
[AcceptVerbs ("GET")]
[AcceptVerbs ("GET")]
public ActionResult ProductCategory ( string brandid , string pcid )
public ActionResult ProductCategory ( string brandid , string pcid )
{
{
ViewData [ "BrandId" ] = brandid ;
ViewData [ "BrandId" ] = brandid ;
@ -137,13 +143,14 @@ namespace Yavsc.Controllers
CatalogManager . GetCatalog ( Request . Url . AbsolutePath ) . GetBrand ( brandid ) . GetProductCategory ( pcid )
CatalogManager . GetCatalog ( Request . Url . AbsolutePath ) . GetBrand ( brandid ) . GetProductCategory ( pcid )
) ;
) ;
}
}
/// <summary>
/// <summary>
/// Product the specified id, pc and pref.
/// Product the specified id, pc and pref.
/// </summary>
/// </summary>
/// <param name="id">Identifier.</param>
/// <param name="id">Identifier.</param>
/// <param name="pc">Pc.</param>
/// <param name="pc">Pc.</param>
/// <param name="pref">Preference.</param>
/// <param name="pref">Preference.</param>
[AcceptVerbs ("GET")]
[AcceptVerbs ("GET")]
public ActionResult Product ( string id , string pc , string pref )
public ActionResult Product ( string id , string pc , string pref )
{
{
Product p = null ;
Product p = null ;
@ -168,62 +175,68 @@ namespace Yavsc.Controllers
}
}
ViewData [ "ProdCatName" ] = pcat . Name ;
ViewData [ "ProdCatName" ] = pcat . Name ;
p = pcat . GetProduct ( pref ) ;
p = pcat . GetProduct ( pref ) ;
if ( p . CommandForm = = null )
if ( p . CommandForm = = null )
p . CommandForm = b . DefaultForm ;
p . CommandForm = b . DefaultForm ;
return View ( ( p is Service ) ? "Service" : "Product" , p ) ;
return View ( ( p is Service ) ? "Service" : "Product" , p ) ;
}
}
/// <summary>
/// <summary>
/// Command this instance.
/// Command this instance.
/// </summary>
/// </summary>
public ActionResult Command ( )
public ActionResult Command ( )
{
{
return View ( ) ;
return View ( ) ;
}
}
private Basket GetBasket ( )
{
if ( Session [ "Basket" ] = = null )
Session [ "Basket" ] = new Basket ( ) ;
return Session [ "Basket" ] as Basket ;
}
/// <summary>
/// <summary>
/// Command the specified collection.
/// Command the specified collection.
/// </summary>
/// </summary>
/// <param name="collection">Collection.</param>
/// <param name="collection">Collection.</param>
[HttpPost]
[HttpPost]
[Authorize]
[Authorize]
public ActionResult Command ( FormCollection collection )
public ActionResult Command ( FormCollection collection )
{
{
try {
try {
// get files from the request
// get files from the request
string fnre = "[A-Za-z0-9~\\-.]+" ;
string fnre = "[A-Za-z0-9~\\-.]+" ;
HttpFileCollectionBase hfc = Request . Files ;
HttpFileCollectionBase hfc = Request . Files ;
foreach ( String h in hfc . AllKeys )
foreach ( String h in hfc . AllKeys ) {
{
if ( ! Regex . Match ( hfc [ h ] . FileName , fnre ) . Success ) {
if ( ! Regex . Match ( hfc [ h ] . FileName , fnre ) . Success )
{
ViewData [ "Message" ] = "File name refused" ;
ViewData [ "Message" ] = "File name refused" ;
ModelState . AddModelError (
ModelState . AddModelError (
h ,
h ,
string . Format (
string . Format (
"The file name {0} dosn't match an acceptable file name {1}" ,
"The file name {0} dosn't match an acceptable file name {1}" ,
hfc [ h ] . FileName , fnre ) )
hfc [ h ] . FileName , fnre ) ) ;
;
return View ( collection ) ;
return View ( collection ) ;
}
}
}
}
foreach ( String h in hfc . AllKeys )
foreach ( String h in hfc . AllKeys ) {
{
// TODO Limit with hfc[h].ContentLength
// TODO Limit with hfc[h].ContentLength
hfc [ h ] . SaveAs ( Path . Combine ( FileSystemController . BaseDir , hfc [ h ] . FileName ) ) ;
hfc [ h ] . SaveAs ( Path . Combine ( FileSystemController . BaseDir , hfc [ h ] . FileName ) ) ;
}
}
if ( Session [ "Basket" ] = = null )
Session [ "Basket" ] = new List < Commande > ( ) ;
List < Commande > basket = Session [ "Basket" ] as List < Commande > ;
// Add specified product command to the basket,
// Add specified product command to the basket,
basket . Add ( Commande . Create ( collection ) ) ;
GetBasket ( ) . Add ( Commande . Create ( collection ) ) ;
ViewData [ "Message" ] = LocalizedText . Item_added_to_basket ;
return View ( collection ) ;
return View ( collection ) ;
} catch ( Exception e )
} catch ( Exception e ) {
{
ViewData [ "Message" ] = "Exception:" + e . Message ;
ViewData [ "Message" ] = "Exception:" + e . Message ;
return View ( collection ) ;
return View ( collection ) ;
}
}
}
}
ActionResult YourCommands ( )
{
return View ( GetBasket ( ) ) ;
}
}
}
}
}