using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using HeuristicLab.Services.Optimization.Web.Models; using HeuristicLab.Services.Optimization.Web.Helpers; using HeuristicLab.Services.Optimization.ControllerService.Model; using System.Web.Security; using Mvc3TestApplication.Binders; using HeuristicLab.Services.Optimization.ControllerService.Parsers; namespace HeuristicLab.Services.Optimization.Web.Controllers { [Authorize(Roles = "Web User")] public class ExperimentController : BaseController { // // GET: /Experiment/ public ActionResult Index() { RedirectToLoginIfNecessary("%2fExperiment%2fIndex"); return RedirectToAction("New", "Experiment"); /*var model = new ExperimentViewModel(); var scenarios = ControllerService.withControllerService>((service) => { return service.GetOptimizationScenarioNames(); }); var experiments = ControllerService.withControllerService>((service) => { User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string }; return service.GetExperimentNames(u); }); foreach (var experiment in experiments) model.Experiments.Add(experiment); foreach (var scenario in scenarios) model.Scenarios.Add(scenario); return View(model);*/ } public ActionResult New() { RedirectToLoginIfNecessary("%2fExperiment%2fNew"); return View(); } public ActionResult NewEdit() { RedirectToLoginIfNecessary("%2fExperiment%2fNewEdit"); return View(); } public ActionResult Edit() { var model = new ExperimentViewModel(); var experiments = ControllerService.withControllerService>((service) => { User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string }; return service.GetExperimentNames(u); }); foreach (var experiment in experiments) model.Experiments.Add(experiment); return View(model); } #region new experiment methdos [HttpGet] public ActionResult Scenario(string nodeId) { var optimizationScenario = ControllerService.withControllerService(service => { return service.GetOptimizationScenarioByName(nodeId); }); return Content(AlgorithmConverter.ConvertScenarioToJson(optimizationScenario).ToString(), "application/json", System.Text.Encoding.UTF8); } [HttpGet] public ActionResult ExperimentList() { var experiments = ControllerService.withControllerService>(service => { User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string }; return service.GetExperiments(u, namesOnly: true); }); return Content(AlgorithmConverter.ConvertExperimentsToJson(experiments).ToString(), "application/json", System.Text.Encoding.UTF8); } [HttpGet] public ActionResult ScenarioList() { var scenarios = ControllerService.withControllerService>(service => { User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string }; return service.GetOptimizationScenarios(); }); return Content(AlgorithmConverter.ConvertScenariosToJson(scenarios).ToString(), "application/json", System.Text.Encoding.UTF8); } [HttpPut] public JsonResult Experiment(string nodeId, [ExperimentJson] Experiment exp) { return Json( new { nodeId = ControllerService.withControllerService(service => { User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string }; return service.SaveExperiment(u, exp); }) }); } [HttpPost] public JsonResult Experiment([ExperimentJson] Experiment exp) { return Json( new { nodeId = ControllerService.withControllerService(service => { User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string }; return service.SaveExperiment(u, exp); }) }); } [HttpDelete] [ActionName("Experiment")] public JsonResult DeleteExperiment(string nodeId) { var isExperimentDeleted = ControllerService.withControllerService(service => { User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string }; return service.DeleteExperiment(u, nodeId); }); return Json(isExperimentDeleted, JsonRequestBehavior.DenyGet); } [HttpGet] public ActionResult Experiment(string nodeId) { var experiment = ControllerService.withControllerService(service => { User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string }; return service.GetExperimentById(u, nodeId); }); var str = AlgorithmConverter.ConvertExperimentToJson(experiment).ToString(); return Content(str, "application/json", System.Text.Encoding.UTF8); } #endregion } }