private ComponentLocation UpdateLocation(ComponentLocation location) { //Check if exist - Creat new or update if (location.Id != 0) { //Add existing _DB.Element("Locations").Add( new XElement("Location", new XAttribute("Id", location.Id.ToString()), new XAttribute("Name", location.Name), new XAttribute("Prefix", location.Prefix) ) ); } else { //Add new _DB.Element("Locations").Add( new XElement("Location", new XAttribute("Id", _LocationId.ToString()), new XAttribute("Name", location.Name), new XAttribute("Prefix", String.IsNullOrEmpty(location.Prefix) ? " " : location.Prefix) ) ); location.Id = _LocationId; _LocationId++; _DB.Attribute("LocationId").Value = _LocationId.ToString(); } return(location); }
public ActionResult SaveLocation(ComponentLocation location) { if (!ModelState.IsValid && location.Id != 0) { var viewModel = new LocationFormViewModel { Location = location, }; return(View("LocationForm", viewModel)); } var userName = User.Identity.GetUserName(); var xmlDB = new XMLDatabase(userName, _context.Users.First(c => c.Name == userName).ActProject); //Choose between add and update if (location.Id == 0) { xmlDB.Locations.Add(location); } else { var locationInDB = xmlDB.Locations.Single(c => c.Id == location.Id); locationInDB.Name = location.Name; locationInDB.Prefix = location.Prefix; } xmlDB.Save(); return(RedirectToAction("Index", "HWConf")); }
public void Start( ApplicationBootstrap bootstrap, ComponentLocation componentLocation, ApplicationContext applicationContext, BackgroundTasks backgroundTasks) { Configure(componentLocation, bootstrap, applicationContext, backgroundTasks); bootstrap.Start(); }
public IHttpActionResult CreateLocation(ComponentLocation location) { var userName = User.Identity.GetUserName(); var xmlDB = new XMLDatabase(userName, _context.Users.First(c => c.Name == userName).ActProject); if (!ModelState.IsValid) { return(BadRequest()); } xmlDB.Locations.Add(location); xmlDB.Save(); return(Created(new Uri(Request.RequestUri + "/" + location.Id), location)); }
private static void Configure( ComponentLocation componentLocation, ApplicationBootstrap bootstrap, ApplicationContext applicationContext, BackgroundTasks backgroundTasks) { var operationsOutputViewModel = new OperationsOutputViewModel(); var operationPropertiesViewModel = new OperationPropertiesViewModel(); var scriptOperationsViewModel = new ScriptOperationsViewModel(operationPropertiesViewModel); var operationsViewModel = new OperationsViewModel(operationPropertiesViewModel); var operationViewsViewModel = new OperationViewsViewModel(new OperationsViewInitialization[] { operationsViewModel, scriptOperationsViewModel }); var componentInstancesViewModel = new ComponentInstancesViewModel(operationsViewModel, operationViewsViewModel); var operationMachinesByControlObject = new OperationMachinesByControlObject(); var outputFactory = new OutputFactory(operationsOutputViewModel); var testComponentViewModelFactory = new TestComponentViewModelFactory( componentInstancesViewModel, outputFactory, new WpfOperationViewModelFactory(applicationContext, scriptOperationsViewModel, new PropertySetBuilderFactory()), backgroundTasks, operationMachinesByControlObject, bootstrap); var componentsViewModel = new ComponentsViewModel(testComponentViewModelFactory); var topMenuBarViewModel = new TopMenuBarViewModel( componentInstancesViewModel, operationsOutputViewModel, new PersistentModelContentBuilderFactory(operationsOutputViewModel, operationMachinesByControlObject)); var factoryRepositories = componentLocation.LoadComponentRoots(); AddAllInstanceFactories(factoryRepositories, componentsViewModel); bootstrap.SetOperationPropertiesViewDataContext(operationPropertiesViewModel); bootstrap.SetTopMenuBarContext(topMenuBarViewModel); bootstrap.SetOperationsViewDataContext(operationsViewModel); bootstrap.SetScriptOperationsViewDataContext(scriptOperationsViewModel); bootstrap.SetOperationsOutputViewDataContext(operationsOutputViewModel); bootstrap.SetComponentsViewDataContext(componentsViewModel); bootstrap.SetComponentInstancesViewDataContext(componentInstancesViewModel); bootstrap.SetOperationsViewsViewDataContext(operationViewsViewModel); return; }
public ComponentLocation UpdateLocation(int id, ComponentLocation location) { var userName = User.Identity.GetUserName(); var xmlDB = new XMLDatabase(userName, _context.Users.First(c => c.Name == userName).ActProject); if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.BadRequest); } var locationInDb = xmlDB.Locations.SingleOrDefault(c => c.Id == id); if (locationInDb == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } locationInDb.Prefix = location.Prefix; locationInDb.Name = location.Name; xmlDB.Save(); return(location); }